use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnItemSelectedTest method nonDefaultMethod.
@Test
public void nonDefaultMethod() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;" + "import butterknife.OnItemSelected;" + "import static butterknife.OnItemSelected.Callback.NOTHING_SELECTED;" + "public class Test {" + " @OnItemSelected(value = 1, callback = NOTHING_SELECTED)" + " void doStuff() {}" + "}");
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 android.widget.AdapterView;\n" + "import butterknife.Unbinder;\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, \"method 'doStuff'\");\n" + " view1 = view;\n" + " ((AdapterView<?>) view).setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {\n" + " @Override\n" + " public void onItemSelected(AdapterView<?> p0, View p1, int p2, long p3) {\n" + " }\n" + " @Override\n" + " public void onNothingSelected(AdapterView<?> p0) {\n" + " target.doStuff();\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" + " ((AdapterView<?>) view1).setOnItemSelectedListener(null);\n" + " view1 = null;\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class OnLongClickTest method failsIfMissingReturnType.
@Test
public void failsIfMissingReturnType() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnLongClick;\n" + "public class Test {\n" + " @OnLongClick(1)\n" + " public void doStuff() {\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@OnLongClick methods must have a 'boolean' return type. (test.Test.doStuff)").in(source).onLine(5);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewsTest method bindingListOfInterface.
@Test
public void bindingListOfInterface() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindViews;\n" + "import java.util.List;\n" + "public class Test {\n" + " interface TestInterface {}\n" + " @BindViews({1, 2, 3}) List<TestInterface> thing;\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.Utils;\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.thing = Utils.listOf(\n" + " Utils.findRequiredViewAsType(source, 1, \"field 'thing'\", Test.TestInterface.class), \n" + " Utils.findRequiredViewAsType(source, 2, \"field 'thing'\", Test.TestInterface.class), \n" + " Utils.findRequiredViewAsType(source, 3, \"field 'thing'\", Test.TestInterface.class));\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.thing = null;\n" + " }\n" + "}");
assertAbout(javaSource()).that(source).withCompilerOptions("-Xlint:-processing").processedWith(new ButterKnifeProcessor()).compilesWithoutWarnings().and().generatesSources(bindingSource);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewsTest method failsIfContainsDuplicateIds.
@Test
public void failsIfContainsDuplicateIds() throws Exception {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindViews;\n" + "import java.util.List;\n" + "public class Test {\n" + " @BindViews({1, 1}) List<View> thing;\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindViews annotation contains duplicate ID 1. (test.Test.thing)").in(source).onLine(6);
}
use of butterknife.compiler.ButterKnifeProcessor in project butterknife by JakeWharton.
the class BindViewsTest method failsIfGenericNotView.
@Test
public void failsIfGenericNotView() {
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<String> thing;\n" + "}");
assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("@BindViews List or array type must extend from View or be an interface. (test.Test.thing)").in(source).onLine(5);
}
Aggregations