Search in sources :

Example 91 with ButterKnifeProcessor

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

the class OnClickTest method failsIfHasDuplicateIds.

@Test
public void failsIfHasDuplicateIds() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick({1, 2, 3, 1})\n" + "  void doStuff() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick annotation for method contains duplicate ID 1. (test.Test.doStuff)").in(source).onLine(5);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 92 with ButterKnifeProcessor

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

the class OnClickTest method findOnlyCalledOnce.

@Test
public void findOnlyCalledOnce() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @BindView(1) View view;\n" + "  @OnClick(1) void doStuff() {}\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 butterknife.internal.DebouncingOnClickListener;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.IllegalStateException;\n" + "import java.lang.Override;\n" + "public class Test_ViewBinding implements Unbinder {\n" + "  private Test target;\n" + "  private View view1;\n" + "  @UiThread\n" + "  public Test_ViewBinding(final Test target, View source) {\n" + "    this.target = target;\n" + "    View view;\n" + "    view = Utils.findRequiredView(source, 1, \"field 'view' and method 'doStuff'\");\n" + "    target.view = view;\n" + "    view1 = view;\n" + "    view.setOnClickListener(new DebouncingOnClickListener() {\n" + "      @Override\n" + "      public void doClick(View p0) {\n" + "        target.doStuff();\n" + "      }\n" + "    });\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" + "    view1.setOnClickListener(null);\n" + "    view1 = 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 93 with ButterKnifeProcessor

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

the class OnClickTest method failsIfHasReturnType.

@Test
public void failsIfHasReturnType() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1)\n" + "  public String doStuff() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick methods must have a 'void' return type. (test.Test.doStuff)").in(source).onLine(5);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 94 with ButterKnifeProcessor

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

the class OnClickTest method failsIfPrivateMethod.

@Test
public void failsIfPrivateMethod() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1)\n" + "  private void doStuff() {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick methods must not be private or static. (test.Test.doStuff)").in(source).onLine(5);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 95 with ButterKnifeProcessor

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

the class OnClickTest method methodVisibility.

@Test
public void methodVisibility() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1) public void thing1() {}\n" + "  @OnClick(2) void thing2() {}\n" + "  @OnClick(3) protected void thing3() {}\n" + "}");
    assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings();
}
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