Java Code Examples for com.google.testing.compile.JavaFileObjects#forSourceLines()

The following examples show how to use com.google.testing.compile.JavaFileObjects#forSourceLines() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompilationTest.java    From SimpleWeibo with Apache License 2.0 6 votes vote down vote up
public void testMissingSuperclassGenericParameter() throws Exception {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retroweibo.RetroWeibo;",
      "",
      "@RetroWeibo",
      "public abstract class Baz<T extends MissingType<?>> {",
      "  public abstract int foo();",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroWeiboProcessor())
      .failsToCompile()
      .withErrorContaining("MissingType")
      .in(javaFileObject).onLine(6);
}
 
Example 2
Source File: ModuleFactoryGeneratorTest.java    From dagger2-sample with Apache License 2.0 6 votes vote down vote up
@Test public void providesMethodMultipleQualifiers() {
  JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "",
      "import javax.annotation.Nullable;",
      "import javax.inject.Singleton;",
      "",
      "@Module",
      "final class TestModule {",
      "  @Provides @QualifierA @QualifierB String provideString() {",
      "    return \"foo\";",
      "  }",
      "}");
  assertAbout(javaSources()).that(ImmutableList.of(moduleFile, QUALIFIER_A, QUALIFIER_B))
      .processedWith(new ComponentProcessor())
      .failsToCompile()
      .withErrorContaining(PROVIDES_OR_PRODUCES_METHOD_MULTIPLE_QUALIFIERS);
}
 
Example 3
Source File: ModuleFactoryGeneratorTest.java    From dagger2-sample with Apache License 2.0 6 votes vote down vote up
@Test public void providesOverridesNonProvides() {
  JavaFileObject parent = JavaFileObjects.forSourceLines("test.Parent",
      "package test;",
      "",
      "import dagger.Module;",
      "",
      "@Module",
      "class Parent {",
      "  String foo() { return null; }",
      "}");
  JavaFileObject child = JavaFileObjects.forSourceLines("test.Child",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "",
      "@Module",
      "class Child extends Parent{",
      "  @Provides String foo() { return null; }",
      "}");
  assertAbout(javaSources()).that(ImmutableList.of(parent, child))
      .processedWith(new ComponentProcessor())
      .failsToCompile()
      .withErrorContaining(String.format(ErrorMessages.PROVIDES_METHOD_OVERRIDES_ANOTHER,
          "Provides", "String test.Parent.foo()"));
}
 
Example 4
Source File: CompilationTest.java    From SimpleWeibo with Apache License 2.0 6 votes vote down vote up
public void testRetroWeiboBuilderAlienMethod() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retroweibo.RetroWeibo;",
      "",
      "@RetroWeibo",
      "public abstract class Baz {",
      "  abstract String blam();",
      "",
      "  @RetroWeibo.Builder",
      "  public interface Builder {",
      "    Builder blam(String x, String y);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroWeiboProcessor(), new RetroWeiboBuilderProcessor())
      .failsToCompile()
      .withErrorContaining(
          "Builder methods must either have no arguments and return foo.bar.Baz or have one"
              + " argument and return foo.bar.Baz.Builder")
      .in(javaFileObject).onLine(11);
}
 
Example 5
Source File: CompilationTest.java    From RetroFacebook with Apache License 2.0 6 votes vote down vote up
public void testNoMultidimensionalPrimitiveArrays() throws Exception {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retrofacebook.RetroFacebook;",
      "",
      "@RetroFacebook",
      "public abstract class Baz {",
      "  public abstract int[][] ints();",
      "",
      "  public static Baz create(int[][] ints) {",
      "    return new RetroFacebook_Baz(ints);",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroFacebookProcessor())
      .failsToCompile()
      .withErrorContaining("RetroFacebook class cannot define an array-valued property "
          + "unless it is a primitive array")
      .in(javaFileObject).onLine(7);
}
 
Example 6
Source File: CompilationTest.java    From SimpleWeibo with Apache License 2.0 6 votes vote down vote up
public void testRetroWeiboBuilderMissingSetter() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retroweibo.RetroWeibo;",
      "",
      "@RetroWeibo",
      "public abstract class Baz {",
      "  abstract int blim();",
      "  abstract String blam();",
      "",
      "  @RetroWeibo.Builder",
      "  public interface Builder {",
      "    Builder blam(String x);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroWeiboProcessor(), new RetroWeiboBuilderProcessor())
      .failsToCompile()
      .withErrorContaining("with this signature: foo.bar.Baz.Builder blim(int)")
      .in(javaFileObject).onLine(11);
}
 
Example 7
Source File: CompilationTest.java    From RetroFacebook with Apache License 2.0 6 votes vote down vote up
public void testRetroFacebookValidateNotInRetroFacebook() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retrofacebook.RetroFacebook;",
      "",
      "public abstract class Baz {",
      "  abstract String blam();",
      "",
      "  @RetroFacebook.Validate",
      "  void validate() {}",
      "",
      "  public interface Builder {",
      "    Builder blam(String x);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor())
      .failsToCompile()
      .withErrorContaining(
          "@RetroFacebook.Validate can only be applied to a method inside an @RetroFacebook class")
      .in(javaFileObject).onLine(9);
}
 
Example 8
Source File: CompilationTest.java    From RetroFacebook with Apache License 2.0 6 votes vote down vote up
public void testRetroFacebookBuilderMissingSetter() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retrofacebook.RetroFacebook;",
      "",
      "@RetroFacebook",
      "public abstract class Baz {",
      "  abstract int blim();",
      "  abstract String blam();",
      "",
      "  @RetroFacebook.Builder",
      "  public interface Builder {",
      "    Builder blam(String x);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor())
      .failsToCompile()
      .withErrorContaining("with this signature: foo.bar.Baz.Builder blim(int)")
      .in(javaFileObject).onLine(11);
}
 
Example 9
Source File: ModuleFactoryGeneratorTest.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
@Test public void modulesWithTypeParamsMustBeAbstract() {
  JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "",
      "@Module",
      "final class TestModule<A> {}");
  assertAbout(javaSource()).that(moduleFile)
      .processedWith(new ComponentProcessor())
      .failsToCompile()
      .withErrorContaining(MODULES_WITH_TYPE_PARAMS_MUST_BE_ABSTRACT);
}
 
Example 10
Source File: CompilationTest.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
public void testReferencingGeneratedClass() {
  // Test that ensures that a type that does not exist can be the type of an @RetroWeibo property
  // as long as it later does come into existence. The BarFoo type referenced here does not exist
  // when the RetroWeiboProcessor runs on the first round, but the FooProcessor then generates it.
  // That generation provokes a further round of annotation processing and RetroWeiboProcessor
  // should succeed then.
  JavaFileObject bazFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retroweibo.RetroWeibo;",
      "",
      "@RetroWeibo",
      "public abstract class Baz {",
      "  public abstract BarFoo barFoo();",
      "",
      "  public static Baz create(BarFoo barFoo) {",
      "    return new RetroWeibo_Baz(barFoo);",
      "  }",
      "}");
  JavaFileObject barFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Bar",
      "package foo.bar;",
      "",
      "import retroweibo.RetroWeibo;",
      "",
      "@" + Foo.class.getCanonicalName(),
      "public abstract class Bar {",
      "  public abstract BarFoo barFoo();",
      "}");
  assertAbout(javaSources())
      .that(ImmutableList.of(bazFileObject, barFileObject))
      .processedWith(new RetroWeiboProcessor(), new FooProcessor())
      .compilesWithoutError();
}
 
Example 11
Source File: ProductionComponentProcessorTest.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
@Test public void componentOnConcreteClass() {
  JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.NotAComponent",
      "package test;",
      "",
      "import dagger.producers.ProductionComponent;",
      "",
      "@ProductionComponent",
      "final class NotAComponent {}");
  assertAbout(javaSource()).that(componentFile)
      .processedWith(new ComponentProcessor())
      .failsToCompile()
      .withErrorContaining("interface");
}
 
Example 12
Source File: CompilationTest.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
public void testRetroFacebookValidateWithoutBuilder() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retrofacebook.RetroFacebook;",
      "",
      "@RetroFacebook",
      "public abstract class Baz {",
      "  abstract String blam();",
      "",
      "  @RetroFacebook.Validate",
      "  void validate() {}",
      "",
      "  public interface Builder {",
      "    Builder blam(String x);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor())
      .failsToCompile()
      .withErrorContaining(
          "@RetroFacebook.Validate is only meaningful if there is an @RetroFacebook.Builder")
      .in(javaFileObject).onLine(10);
}
 
Example 13
Source File: CompilationTest.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
public void testRetroFacebookBuilderValidateMethodNotVoid() {
  JavaFileObject javaFileObject = JavaFileObjects.forSourceLines(
      "foo.bar.Baz",
      "package foo.bar;",
      "",
      "import retrofacebook.RetroFacebook;",
      "",
      "@RetroFacebook",
      "public abstract class Baz {",
      "  abstract String blam();",
      "",
      "  @RetroFacebook.Validate",
      "  Baz validate() {",
      "    return this;",
      "  }",
      "",
      "  @RetroFacebook.Builder",
      "  public interface Builder {",
      "    Builder blam(String x);",
      "    Baz build();",
      "  }",
      "}");
  assertAbout(javaSource())
      .that(javaFileObject)
      .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor())
      .failsToCompile()
      .withErrorContaining("@RetroFacebook.Validate method must be void")
      .in(javaFileObject).onLine(10);
}
 
Example 14
Source File: GraphValidationTest.java    From dagger2-sample with Apache License 2.0 4 votes vote down vote up
@Test public void duplicateExplicitBindings_MultipleProvisionTypes() {
  JavaFileObject component = JavaFileObjects.forSourceLines("test.Outer",
      "package test;",
      "",
      "import dagger.Component;",
      "import dagger.MapKey;",
      "import dagger.Module;",
      "import dagger.Provides;",
      "import dagger.MapKey;",
      "import java.util.HashMap;",
      "import java.util.HashSet;",
      "import java.util.Map;",
      "import java.util.Set;",
      "",
      "import static java.lang.annotation.RetentionPolicy.RUNTIME;",
      "import static dagger.Provides.Type.MAP;",
      "import static dagger.Provides.Type.SET;",
      "",
      "final class Outer {",
      "  @MapKey(unwrapValue = true)",
      "  @interface StringKey {",
      "    String value();",
      "  }",
      "",
      "  @Module",
      "  static class TestModule1 {",
      "    @Provides(type = MAP)",
      "    @StringKey(\"foo\")",
      "    String stringMapEntry() { return \"\"; }",
      "",
      "    @Provides(type = SET) String stringSetElement() { return \"\"; }",
      "  }",
      "",
      "  @Module",
      "  static class TestModule2 {",
      "    @Provides Set<String> stringSet() { return new HashSet<String>(); }",
      "",
      "    @Provides Map<String, String> stringMap() {",
      "      return new HashMap<String, String>();",
      "    }",
      "  }",
      "",
      "  @Component(modules = { TestModule1.class, TestModule2.class })",
      "  interface TestComponent {",
      "    Set<String> getStringSet();",
      "    Map<String, String> getStringMap();",
      "  }",
      "}");

  String expectedSetError =
      "java.util.Set<java.lang.String> has incompatible bindings:\n"
          + "      Set bindings:\n"
          + "          @Provides(type=SET) String test.Outer.TestModule1.stringSetElement()\n"
          + "      Unique bindings:\n"
          + "          @Provides Set<String> test.Outer.TestModule2.stringSet()";

  String expectedMapError =
      "java.util.Map<java.lang.String,java.lang.String> has incompatible bindings:\n"
          + "      Map bindings:\n"
          + "          @Provides(type=MAP) @test.Outer.StringKey(\"foo\") String"
          + " test.Outer.TestModule1.stringMapEntry()\n"
          + "      Unique bindings:\n"
          + "          @Provides Map<String,String> test.Outer.TestModule2.stringMap()";

  assertAbout(javaSource()).that(component)
      .processedWith(new ComponentProcessor())
      .failsToCompile()
      .withErrorContaining(expectedSetError).in(component).onLine(43)
      .and().withErrorContaining(expectedMapError).in(component).onLine(44);
}
 
Example 15
Source File: FeatureProcessorTests.java    From featured with Apache License 2.0 4 votes vote down vote up
@Test
public void checkOnEventWithParametersGenerics() throws Exception {

    JavaFileObject source = JavaFileObjects
            .forSourceLines("de.halfbit.featured.test.TestFeature",
                    "",
                    "package de.halfbit.featured.test;",
                    "",
                    "import android.content.Context;",
                    "import de.halfbit.featured.FeatureEvent;",
                    "import de.halfbit.featured.Feature;",
                    "import java.util.List;",
                    "",
                    "public class TestFeature extends Feature<TestFeatureHost, Context> {",
                    "    @FeatureEvent protected void onStart(List<String> names) { }",
                    "}"
            );

    JavaFileObject expectedSource = JavaFileObjects
            .forSourceLines("de.halfbit.featured.test.TestFeatureHost",
                    "",
                    "package de.halfbit.featured.test;",
                    "",
                    "import android.content.Context;",
                    "import de.halfbit.featured.Feature;",
                    "import de.halfbit.featured.FeatureHost;",
                    "import java.util.List;",
                    "import org.jetbrains.annotations.NotNull;",
                    "",
                    "public class TestFeatureHost extends FeatureHost<TestFeatureHost, Context> {",
                    "    public TestFeatureHost(@NotNull Context context) {",
                    "        super(context);",
                    "    }",
                    "    @NotNull public TestFeatureHost with(@NotNull TestFeature feature) {",
                    "        addFeature(feature, feature.getClass().toString());",
                    "        return this;",
                    "    }",
                    "    @NotNull public TestFeatureHost with(@NotNull TestFeature feature, @NotNull String featureName) {",
                    "        addFeature(feature, featureName);",
                    "        return this;",
                    "    }",
                    "    public void dispatchOnStart(List<String> names) {",
                    "        dispatch(new OnStartEvent(names));",
                    "    }",
                    "    static final class OnStartEvent extends FeatureHost.Event {",
                    "        private final List<String> mNames;",
                    "        OnStartEvent(List<String> names) {",
                    "            mNames = names;",
                    "        }",
                    "        @Override protected void dispatch(@NotNull Feature feature) {",
                    "            if (feature instanceof TestFeature) {",
                    "                ((TestFeature) feature).onStart(mNames);",
                    "            }",
                    "        }",
                    "    }",
                    "}"
            );

    assertAbout(javaSource()).that(source)
            .processedWith(new FeatureProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedSource);
}
 
Example 16
Source File: BaseTest.java    From PermissionsDispatcher with Apache License 2.0 4 votes vote down vote up
final JavaFileObject expect() {
    return JavaFileObjects.forSourceLines(getName() + "PermissionsDispatcher", getExpectSource());
}
 
Example 17
Source File: MembersInjectionTest.java    From dagger2-sample with Apache License 2.0 4 votes vote down vote up
@Test public void simpleComponentWithNesting() {
  JavaFileObject nestedTypesFile = JavaFileObjects.forSourceLines("test.OuterType",
      "package test;",
      "",
      "import dagger.Component;",
      "import javax.inject.Inject;",
      "",
      "final class OuterType {",
      "  static class A {",
      "    @Inject A() {}",
      "  }",
      "  static class B {",
      "    @Inject A a;",
      "  }",
      "  @Component interface SimpleComponent {",
      "    A a();",
      "    void inject(B b);",
      "  }",
      "}");
  JavaFileObject bMembersInjector = JavaFileObjects.forSourceLines(
      "test.OuterType$B_MembersInjector",
      "package test;",
      "",
      "import dagger.MembersInjector;",
      "import javax.annotation.Generated;",
      "import javax.inject.Provider;",
      "import test.OuterType.A;",
      "import test.OuterType.B;",
      "",
      "@Generated(\"dagger.internal.codegen.ComponentProcessor\")",
      "public final class OuterType$B_MembersInjector implements MembersInjector<B> {",
      "  private final Provider<A> aProvider;",
      "",
      "  public OuterType$B_MembersInjector(Provider<A> aProvider) {",
      "    assert aProvider != null;",
      "    this.aProvider = aProvider;",
      "  }",
       "",
      "  @Override",
      "  public void injectMembers(B instance) {",
      "    if (instance == null) {",
      "      throw new NullPointerException(\"Cannot inject members into a null reference\");",
      "    }",
      "    instance.a = aProvider.get();",
      "  }",
      "",
      "  public static MembersInjector<B> create(Provider<A> aProvider) {",
      "    return new OuterType$B_MembersInjector(aProvider);",
      "  }",
      "}");
  assertAbout(javaSources()).that(ImmutableList.of(nestedTypesFile))
      .processedWith(new ComponentProcessor())
      .compilesWithoutError()
      .and().generatesSources(bMembersInjector);
}
 
Example 18
Source File: ModuleFactoryGeneratorTest.java    From dagger2-sample with Apache License 2.0 4 votes vote down vote up
@Test public void providesSetValues() {
  JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule",
      "package test;",
      "",
      "import static dagger.Provides.Type.SET_VALUES;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "import java.util.Set;",
      "",
      "@Module",
      "final class TestModule {",
      "  @Provides(type = SET_VALUES) Set<String> provideStrings() {",
      "    return null;",
      "  }",
      "}");
  JavaFileObject factoryFile = JavaFileObjects.forSourceLines("TestModule_ProvideStringsFactory",
      "package test;",
      "",
      "import dagger.internal.Factory;",
      "import java.util.Set;",
      "import javax.annotation.Generated;",
      "",
      "@Generated(\"dagger.internal.codegen.ComponentProcessor\")",
      "public final class TestModule_ProvideStringsFactory implements Factory<Set<String>> {",
      "  private final TestModule module;",
      "",
      "  public TestModule_ProvideStringsFactory(TestModule module) {",
      "    assert module != null;",
      "    this.module = module;",
      "  }",
      "",
      "  @Override public Set<String> get() {",
      "    Set<String> provided = module.provideStrings();",
      "    if (provided == null) {",
      "      throw new NullPointerException(" + NPE_LITERAL + ");",
      "    }",
      "    return provided;",
      "  }",
      "",
      "  public static Factory<Set<String>> create(TestModule module) {",
      "    return new TestModule_ProvideStringsFactory(module);",
      "  }",
      "}");
  assertAbout(javaSource()).that(moduleFile)
      .processedWith(new ComponentProcessor())
      .compilesWithoutError()
      .and().generatesSources(factoryFile);
}
 
Example 19
Source File: ComponentProcessorTest.java    From dagger2-sample with Apache License 2.0 4 votes vote down vote up
@Test public void doubleBindingFromResolvedModules() {
  JavaFileObject parent = JavaFileObjects.forSourceLines("test.ParentModule",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "import java.util.List;",
      "",
      "@Module",
      "abstract class ParentModule<A> {",
      "  @Provides List<A> provideListB(A a) { return null; }",
      "}");
  JavaFileObject child = JavaFileObjects.forSourceLines("test.ChildModule",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "",
      "@Module",
      "class ChildNumberModule extends ParentModule<Integer> {",
      "  @Provides Integer provideInteger() { return null; }",
      "}");
  JavaFileObject another = JavaFileObjects.forSourceLines("test.AnotherModule",
      "package test;",
      "",
      "import dagger.Module;",
      "import dagger.Provides;",
      "import java.util.List;",
      "",
      "@Module",
      "class AnotherModule {",
      "  @Provides List<Integer> provideListOfInteger() { return null; }",
      "}");
  JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.BadComponent",
      "package test;",
      "",
      "import dagger.Component;",
      "import java.util.List;",
      "",
      "@Component(modules = {ChildNumberModule.class, AnotherModule.class})",
      "interface BadComponent {",
      "  List<Integer> listOfInteger();",
      "}");
  assertAbout(javaSources()).that(ImmutableList.of(parent, child, another, componentFile))
      .processedWith(new ComponentProcessor())
      .failsToCompile().withErrorContaining(
          "java.util.List<java.lang.Integer> is bound multiple times")
      .and().withErrorContaining(
          "@Provides List<Integer> test.ChildNumberModule.provideListB(Integer)")
      .and().withErrorContaining(
          "@Provides List<Integer> test.AnotherModule.provideListOfInteger()");
}
 
Example 20
Source File: FeatureProcessorTests.java    From featured with Apache License 2.0 4 votes vote down vote up
@Test
public void checkOnEventWithArrayParameters() throws Exception {

    JavaFileObject source = JavaFileObjects
            .forSourceLines("de.halfbit.featured.test.TestFeature",
                    "",
                    "package de.halfbit.featured.test;",
                    "",
                    "import android.content.Context;",
                    "import de.halfbit.featured.FeatureEvent;",
                    "import de.halfbit.featured.Feature;",
                    "import org.jetbrains.annotations.NotNull;",
                    "",
                    "public class TestFeature extends Feature<TestFeatureHost, Context> {",
                    "    @FeatureEvent protected void onCreate(@NotNull int[] value1, Object[] value2) { }",
                    "}"
            );

    JavaFileObject expectedSource = JavaFileObjects
            .forSourceLines("de.halfbit.featured.test.TestFeatureHost",
                    "",
                    "package de.halfbit.featured.test;",
                    "",
                    "import android.content.Context;",
                    "import de.halfbit.featured.Feature;",
                    "import de.halfbit.featured.FeatureHost;",
                    "import org.jetbrains.annotations.NotNull;",
                    "",
                    "public class TestFeatureHost extends FeatureHost<TestFeatureHost, Context> {",
                    "    public TestFeatureHost(@NotNull Context context) {",
                    "        super(context);",
                    "    }",
                    "    @NotNull public TestFeatureHost with(@NotNull TestFeature feature) {",
                    "        addFeature(feature, feature.getClass().toString());",
                    "        return this;",
                    "    }",
                    "    @NotNull public TestFeatureHost with(@NotNull TestFeature feature, @NotNull String featureName) {",
                    "        addFeature(feature, featureName);",
                    "        return this;",
                    "    }",
                    "    public void dispatchOnCreate(@NotNull int[] value1, Object[] value2) {",
                    "        dispatch(new OnCreateEvent(value1, value2));",
                    "    }",
                    "    static final class OnCreateEvent extends FeatureHost.Event {",
                    "        private final @NotNull int[] mValue1;",
                    "        private final Object[] mValue2;",
                    "        OnCreateEvent(@NotNull int[] value1, Object[] value2) {",
                    "            mValue1 = value1;",
                    "            mValue2 = value2;",
                    "        }",
                    "        @Override protected void dispatch(@NotNull Feature feature) {",
                    "            if (feature instanceof TestFeature) {",
                    "                ((TestFeature) feature).onCreate(mValue1, mValue2);",
                    "            }",
                    "        }",
                    "    }",
                    "}"
            );

    assertAbout(javaSource()).that(source)
            .processedWith(new FeatureProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedSource);

}