Search in sources :

Example 16 with ButterKnifeProcessor

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

the class BindDimenTest method simpleInt.

@Test
public void simpleInt() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.BindDimen;\n" + "public class Test {\n" + "  @BindDimen(1) int 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.getDimensionPixelSize(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)

Example 17 with ButterKnifeProcessor

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

the class BindDimenTest method typeMustBeIntOrFloat.

@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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 18 with ButterKnifeProcessor

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

the class OnTextChangedTest method textChangedWithWrongParameter.

@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();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ButterKnifeProcessor(butterknife.compiler.ButterKnifeProcessor) Test(org.junit.Test)

Example 19 with ButterKnifeProcessor

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

the class OnTextChangedTest method textChangedWithParameters.

@Test
public void textChangedWithParameters() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnTextChanged;\n" + "public class Test {\n" + "  @OnTextChanged(1) void doStuff(CharSequence p0, int p1, int p2, int p3) {}\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.text.Editable;\n" + "import android.text.TextWatcher;\n" + "import android.view.View;\n" + "import android.widget.TextView;\n" + "import butterknife.Unbinder;\n" + "import butterknife.internal.Utils;\n" + "import java.lang.CharSequence;\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 TextWatcher view1TextWatcher;\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" + "    view1TextWatcher = new TextWatcher() {\n" + "      @Override\n" + "      public void onTextChanged(CharSequence p0, int p1, int p2, int p3) {\n" + "        target.doStuff(p0, p1, p2, p3);\n" + "      }\n" + "      @Override\n" + "      public void beforeTextChanged(CharSequence p0, int p1, int p2, int p3) {\n" + "      }\n" + "      @Override\n" + "      public void afterTextChanged(Editable p0) {\n" + "      }\n" + "    };\n" + "    ((TextView) view).addTextChangedListener(view1TextWatcher);\n" + "  }\n" + "  @Override\n" + "  @CallSuper\n" + "  public void unbind() {\n" + "    if (target == null) throw new IllegalStateException(\"Bindings already cleared.\");\n" + "    target = null;\n" + "    ((TextView) view1).removeTextChangedListener(view1TextWatcher);\n" + "    view1TextWatcher = 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 20 with ButterKnifeProcessor

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

the class OnTouchTest method failsMultipleListenersWithReturnValue.

@Test
public void failsMultipleListenersWithReturnValue() throws Exception {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", "" + "package test;\n" + "import butterknife.OnTouch;\n" + "public class Test {\n" + "  @OnTouch(1) boolean doStuff1() {}\n" + "  @OnTouch(1) boolean doStuff2() {}\n" + "}");
    assertAbout(javaSource()).that(source).processedWith(new ButterKnifeProcessor()).failsToCompile().withErrorContaining("Multiple listener methods with return value specified for ID 1. (test.Test.doStuff2)").in(source).onLine(5);
}
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