Validating Animation Binding Type Constraints in ButterKnife
This test suite validates the BindAnim annotation functionality in ButterKnife, focusing on type validation for Animation bindings. The tests ensure proper enforcement of type constraints when binding animation resources in Android applications.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-runtime/src/test/java/butterknife/BindAnimTest.java
package butterknife;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Test;
import javax.tools.JavaFileObject;
import butterknife.compiler.ButterKnifeProcessor;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
public class BindAnimTest {
@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);
}
}