Search in sources :

Example 51 with ButterKnifeProcessor

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

the class BindViewsTest method failsIfNoGenericType.

@Test
public void failsIfNoGenericType() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindViews;\n" + "import java.util.List;\n" + "public class Test {\n" + "  @BindViews(1) List thing;\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindViews List must have a generic component. (test.Test.thing)").in(source).onLine(5);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 52 with ButterKnifeProcessor

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

the class OnClickTest method failsInAndroidPackage.

@Test
public void failsInAndroidPackage() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package android.test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1) void doStuff() {}\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick-annotated class incorrectly in Android framework package. (android.test.Test)").in(source).onLine(4);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 53 with ButterKnifeProcessor

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

the class OnClickTest method failsIfParameterNotView.

@Test
public void failsIfParameterNotView() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1)\n" + "  public void doStuff(String thing) {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("" + "Unable to match @OnClick method arguments. (test.Test.doStuff)\n" + "  \n" + "    Parameter #1: java.lang.String\n" + "      did not match any listener parameters\n" + "  \n" + "  Methods may have up to 1 parameter(s):\n" + "  \n" + "    android.view.View\n" + "  \n" + "  These may be listed in any order but will be searched for from top to bottom.").in(source).onLine(5);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 54 with ButterKnifeProcessor

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

the class OnClickTest method onClickMultipleBindings.

@Test
public void onClickMultipleBindings() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1) void doStuff1() {}\n" + "  @OnClick(1) void doStuff2() {}\n" + "  @OnClick({1, 2}) void doStuff3(View v) {}\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" + "  private View view2;\n" + "  @UiThread\n" + "  public Test_ViewBinding(final Test target, View source) {\n" + "    this.target = target;\n" + "    View view;\n" + "    view = Utils.findRequiredView(source, 1, \"method 'doStuff1', method 'doStuff2', and method 'doStuff3'\");\n" + "    view1 = view;\n" + "    view.setOnClickListener(new DebouncingOnClickListener() {\n" + "      @Override\n" + "      public void doClick(View p0) {\n" + "        target.doStuff1();\n" + "        target.doStuff2();\n" + "        target.doStuff3(p0);\n" + "      }\n" + "    });\n" + "    view = Utils.findRequiredView(source, 2, \"method 'doStuff3'\");\n" + "    view2 = view;\n" + "    view.setOnClickListener(new DebouncingOnClickListener() {\n" + "      @Override\n" + "      public void doClick(View p0) {\n" + "        target.doStuff3(p0);\n" + "      }\n" + "    });\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "    if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + "    target = null;\n" + "    view1.setOnClickListener(null);\n" + "    view1 = null;\n" + "    view2.setOnClickListener(null);\n" + "    view2 = 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 55 with ButterKnifeProcessor

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

the class OnClickTest method failsIfMoreThanOneParameter.

@Test
public void failsIfMoreThanOneParameter() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.OnClick;\n" + "public class Test {\n" + "  @OnClick(1)\n" + "  public void doStuff(View thing, View otherThing) {\n" + "  }\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnClick methods can have at most 1 parameter(s). (test.Test.doStuff)").in(source).onLine(6);
}
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