Search in sources :

Example 66 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class BindColorTest method asInt.

@Test
public void asInt() {
    IntTarget target = new IntTarget();
    int expected = context.getResources().getColor(R.color.red);
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertThat(target.actual).isEqualTo(expected);
    unbinder.unbind();
    assertThat(target.actual).isEqualTo(expected);
}
Also used : Unbinder(butterknife.Unbinder) Test(org.junit.Test)

Example 67 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class BindStringTest method simpleInt.

@Test
public void simpleInt() {
    Target target = new Target();
    String expected = context.getString(R.string.hey);
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertThat(target.actual).isEqualTo(expected);
    unbinder.unbind();
    assertThat(target.actual).isEqualTo(expected);
}
Also used : Unbinder(butterknife.Unbinder) BindString(butterknife.BindString) Test(org.junit.Test)

Example 68 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnClickTest method multipleBindings.

@Test
public void multipleBindings() {
    // TODO
    assumeFalse("Not implemented", BuildConfig.FLAVOR.equals("reflect"));
    View tree = ViewTree.create(1);
    View view1 = tree.findViewById(1);
    MultipleBindings target = new MultipleBindings();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(0, target.clicks);
    instrumentation.runOnMainSync(() -> {
        view1.performClick();
        assertEquals(2, target.clicks);
    });
    instrumentation.runOnMainSync(() -> {
        unbinder.unbind();
        view1.performClick();
        assertEquals(2, target.clicks);
    });
}
Also used : Unbinder(butterknife.Unbinder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Example 69 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnClickTest method simple.

@Test
public void simple() {
    View tree = ViewTree.create(1);
    View view1 = tree.findViewById(1);
    Simple target = new Simple();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(0, target.clicks);
    instrumentation.runOnMainSync(() -> {
        view1.performClick();
        assertEquals(1, target.clicks);
    });
    instrumentation.runOnMainSync(() -> {
        unbinder.unbind();
        view1.performClick();
        assertEquals(1, target.clicks);
    });
}
Also used : Unbinder(butterknife.Unbinder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Example 70 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnClickTest method multipleIds.

@Test
public void multipleIds() {
    View tree = ViewTree.create(1, 2);
    View view1 = tree.findViewById(1);
    View view2 = tree.findViewById(2);
    MultipleIds target = new MultipleIds();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(0, target.clicks);
    instrumentation.runOnMainSync(() -> {
        view1.performClick();
        assertEquals(1, target.clicks);
    });
    instrumentation.runOnMainSync(() -> {
        view2.performClick();
        assertEquals(2, target.clicks);
    });
    instrumentation.runOnMainSync(() -> {
        unbinder.unbind();
        view1.performClick();
        view2.performClick();
        assertEquals(2, target.clicks);
    });
}
Also used : Unbinder(butterknife.Unbinder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Aggregations

Unbinder (butterknife.Unbinder)82 Test (org.junit.Test)70 View (android.view.View)52 UiThreadTest (androidx.test.annotation.UiThreadTest)31 TextView (android.widget.TextView)21 AdapterView (android.widget.AdapterView)15 BindView (butterknife.BindView)13 Bundle (android.os.Bundle)12 LayoutInflater (android.view.LayoutInflater)12 ViewGroup (android.view.ViewGroup)12 ButterKnife (butterknife.ButterKnife)12 R (com.simplecity.amp_library.R)10 List (java.util.List)9 Nullable (android.support.annotation.Nullable)8 Aesthetic (com.afollestad.aesthetic.Aesthetic)8 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)8 Inject (javax.inject.Inject)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 RecyclerView (android.support.v7.widget.RecyclerView)6 Rx.distinctToMainThread (com.afollestad.aesthetic.Rx.distinctToMainThread)6