Search in sources :

Example 66 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindViewTest method failsIfNotView.

@Test
public void failsIfNotView() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + "  @BindView(1) String thing;\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindView fields must extend from View or be an interface. (test.Test.thing)").in(source).onLine(4);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 67 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindViewTest method failsIfInInterface.

@Test
public void failsIfInInterface() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public interface Test {\n" + "    @BindView(1) View thing = null;\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindView fields may only be contained in classes. (test.Test.thing)").in(source).onLine(4);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 68 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindViewTest method nullable.

@Test
public void nullable() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + "  @interface Nullable {}\n" + "  @Nullable @BindView(1) View view;\n" + "}");
    JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class Test_ViewBinding implements Unbinder {\n" + "  private Test target;\n" + "  @UiThread\n" + "  public Test_ViewBinding(Test target, View source) {\n" + "    this.target = target;\n" + "    target.view = source.findViewById(1);\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "    Test target = this.target;\n" + "    if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + "    this.target = null;\n" + "    target.view = null;\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 69 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindViewTest method bindingViewFinalClass.

@Test
public void bindingViewFinalClass() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public final class Test {\n" + "    @BindView(1) View thing;\n" + "}");
    JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "package test;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public final class Test_ViewBinding implements Unbinder {\n" + "  private Test target;\n" + "  @UiThread\n" + "  public Test_ViewBinding(Test target, View source) {\n" + "    this.target = target;\n" + "    target.thing = Utils.findRequiredView(source, 1, \"field 'thing'\");\n" + "  }\n" + "  @Override\n" + "  public void unbind() {\n" + "    Test target = this.target;\n" + "    if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + "    this.target = null;\n" + "    target.thing = null;\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 70 with ButterKnifeProcessor

use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.

the class BindArrayTest method typedArray.

@Test
public void typedArray() throws Exception {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindArray;\n" + "import android.content.res.TypedArray;\n" + "public class Test {\n" + "  @BindArray(1) TypedArray one;\n" + "}");
    JavaFileObject bindingSource = JavaFileObjects.forSourceString("test/Test_ViewBinding", "" + "// Generated code from Butter Knife. Do not modify!\n" + "package test;\n" + "import android.content.Context;\n" + "import android.content.res.Resources;\n" + "import android.support.annotation.CallSuper;\n" + "import android.support.annotation.UiThread;\n" + "import android.view.View;\n" + "import butterknife.Unbinder;\n" + "import java.lang.Deprecated;\n" + "import java.lang.Override;\n" + "import java.lang.SuppressWarnings;\n" + "public class Test_ViewBinding implements Unbinder {\n" + "  /**\n" + "   * @deprecated Use {@link #Test_ViewBinding(Test, Context)} for direct creation.\n" + "   *     Only present for runtime invocation through {@code ButterKnife.bind()}.\n" + "   */\n" + "  @Deprecated\n" + "  @UiThread\n" + "  public Test_ViewBinding(Test target, View source) {\n" + "    this(target, source.getContext());\n" + "  }\n" + "  @UiThread\n" + "  @SuppressWarnings(\"ResourceType\")\n" + "  public Test_ViewBinding(Test target, Context context) {\n" + "    Resources res = context.getResources();\n" + "    target.one = res.obtainTypedArray(1);\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Aggregations

ButterKnifeProcessor (butterknife.compiler.ButterKnifeProcessor)121 JavaFileObject (javax.tools.JavaFileObject)121 Test (org.junit.Test)121