Validating @BindInt Type Validation in ButterKnife
This test suite validates the @BindInt annotation functionality in ButterKnife, ensuring proper type checking for integer resource bindings. It focuses on verifying compile-time validation of field types when using the @BindInt annotation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-runtime/src/test/java/butterknife/BindIntTest.java
package butterknife;
import butterknife.compiler.ButterKnifeProcessor;
import com.google.testing.compile.JavaFileObjects;
import javax.tools.JavaFileObject;
import org.junit.Test;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
public final class BindIntTest {
@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);
}
}