Validating Bitmap Annotation Type Safety in Butterknife
This test suite validates the @BindBitmap annotation functionality in the Butterknife library, specifically focusing on type validation for bitmap bindings. The tests ensure proper compile-time validation of bitmap field types and error handling.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-runtime/src/test/java/butterknife/BindBitmapTest.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 BindBitmapTest {
@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);
}
}