Validating Boolean Resource Binding Workflow in Butterknife
This test suite validates the BindBool annotation functionality in ButterKnife, focusing on boolean resource binding and unbinding operations. The tests ensure proper boolean value injection from Android resources and verify the persistence of bound values after unbinding.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jakewharton/butterknife
butterknife-integration-test/src/androidTest/java/com/example/butterknife/functional/BindBoolTest.java
package com.example.butterknife.functional;
import android.content.Context;
import android.view.View;
import androidx.test.InstrumentationRegistry;
import butterknife.BindBool;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.example.butterknife.test.R;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
public final class BindBoolTest {
private final Context context = InstrumentationRegistry.getContext();
private final View tree = ViewTree.create(1);
static class Target {
@BindBool(R.bool.just_true) boolean actual;
}
@Test public void asBoolean() {
Target target = new Target();
boolean expected = context.getResources().getBoolean(R.bool.just_true);
Unbinder unbinder = ButterKnife.bind(target, tree);
assertThat(target.actual).isEqualTo(expected);
unbinder.unbind();
assertThat(target.actual).isEqualTo(expected);
}
}