Validating BindBitmap Type Validation in ButterKnife
This test suite validates the error handling of ButterKnife’s @BindBitmap annotation when used with incorrect field types. It specifically tests the failure scenario where a String field is annotated instead of the required Bitmap type.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-integration-test/src/androidTestReflect/java/com/example/butterknife/functional/BindBitmapFailureTest.java
package com.example.butterknife.functional;
import android.view.View;
import butterknife.BindBitmap;
import butterknife.ButterKnife;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
public final class BindBitmapFailureTest {
private final View tree = ViewTree.create(1);
static class Target {
@BindBitmap(1) String actual;
}
@Test public void typeMustBeBitmap() {
Target target = new Target();
try {
ButterKnife.bind(target, tree);
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessageThat()
.isEqualTo("@BindBitmap field type must be 'Bitmap'. "
+ "(com.example.butterknife.functional.BindBitmapFailureTest$Target.actual)");
}
}
}