@Test public void textChangedWithWrongParameter() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnTextChanged;\n" + "public class Test {\n" + " @OnTextChanged(1) void doStuff(String p0, int p1, int p2, int p3) {}\n" + "}" ); assertAbout(javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .failsToCompile(); }
@Test public void typeMustBeTypeface() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindFont;\n" + "public class Test {\n" + " @BindFont(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindFont field type must be 'Typeface'. (test.Test.one)") .in(source).onLine(4); }
@Test public void failsWithInvalidId() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnItemClick;\n" + "public class Test {\n" + " @OnItemClick({1, -1}) void doStuff() {}\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@OnItemClick annotation contains invalid ID -1. (test.Test.doStuff)") .in(source).onLine(4); }
@Test public void failsIfArrayNotView() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindViews;\n" + "public class Test {\n" + " @BindViews(1) 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(4); }
@Test public void typeMustBeBoolean() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindBool;\n" + "public class Test {\n" + " @BindBool(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindBool field type must be 'boolean'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void typeMustBeAnimation() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindAnim;\n" + "public class Test {\n" + " @BindAnim(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindAnim field type must be 'Animation'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void typeMustBeDrawable() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindDrawable;\n" + "public class Test {\n" + " @BindDrawable(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindDrawable field type must be 'Drawable'. (test.Test.one)") .in(source).onLine(4); } }
@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); }
@Test public void typeMustBeBitmap() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindBitmap;\n" + "public class Test {\n" + " @BindBitmap(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindBitmap field type must be 'Bitmap'. (test.Test.one)") .in(source).onLine(4); } }
@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); }
@Test public void typeMustBeIntOrColorStateList() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindColor;\n" + "public class Test {\n" + " @BindColor(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindColor field type must be 'int' or 'ColorStateList'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void typeMustBeString() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindString;\n" + "public class Test {\n" + " @BindString(1) boolean one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindString field type must be 'String'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void failsInJavaPackage() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package java.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 Java framework package. (java.test.Test)") .in(source).onLine(4); }
@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); }
@Test public void typeMustBeIntOrFloat() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindDimen;\n" + "public class Test {\n" + " @BindDimen(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindDimen field type must be 'int' or 'float'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void typeMustBeFloat() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindFloat;\n" + "public class Test {\n" + " @BindFloat(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindFloat field type must be 'float'. (test.Test.one)") .in(source).onLine(4); } }
@Test public void failsIfPrivate() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) private View thing;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindView fields must not be private or static. (test.Test.thing)") .in(source).onLine(5); }
@Test public void failsIfStatic() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import android.view.View;\n" + "import butterknife.BindView;\n" + "public class Test {\n" + " @BindView(1) static View thing;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindView fields must not be private or static. (test.Test.thing)") .in(source).onLine(5); }
@Test public void typeMustBeInt() { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindInt;\n" + "public class Test {\n" + " @BindInt(1) String one;\n" + "}" ); assertAbout(javaSource()).that(source) .processedWith(new ButterKnifeProcessor()) .failsToCompile() .withErrorContaining("@BindInt field type must be 'int'. (test.Test.one)") .in(source).onLine(4); } }
@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); }