Validating BindInt Type Validation in Butterknife Framework
This integration test suite validates the BindInt annotation behavior in Butterknife, specifically focusing on type validation failures. The test ensures proper error handling when attempting to bind integer resources to incompatible field types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-integration-test/src/androidTestReflect/java/com/example/butterknife/functional/BindIntFailureTest.java
package com.example.butterknife.functional;
import android.view.View;
import butterknife.BindInt;
import butterknife.ButterKnife;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
public final class BindIntFailureTest {
private final View tree = ViewTree.create(1);
static class Target {
@BindInt(1) String actual;
}
@Test public void typeMustBeInt() {
Target target = new Target();
try {
ButterKnife.bind(target, tree);
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessageThat()
.isEqualTo("@BindInt field type must be 'int'. "
+ "(com.example.butterknife.functional.BindIntFailureTest$Target.actual)");
}
}
}