Validating Float Resource Type Safety in ButterKnife
This integration test suite validates the type checking functionality of ButterKnife’s @BindFloat annotation. It specifically tests error handling when attempting to bind float resources to incompatible field types, ensuring robust type safety in the Android view binding process.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-integration-test/src/androidTestReflect/java/com/example/butterknife/functional/BindFloatFailureTest.java
package com.example.butterknife.functional;
import android.view.View;
import butterknife.BindFloat;
import butterknife.ButterKnife;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
public final class BindFloatFailureTest {
private final View tree = ViewTree.create(1);
static class Target {
@BindFloat(1) String actual;
}
@Test public void typeMustBeFloat() {
Target target = new Target();
try {
ButterKnife.bind(target, tree);
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessageThat()
.isEqualTo("@BindFloat field type must be 'float'. "
+ "(com.example.butterknife.functional.BindFloatFailureTest$Target.actual)");
}
}
}