Search in sources :

Example 26 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnClickTest method optionalIdPresent.

@Test
public void optionalIdPresent() {
    View tree = ViewTree.create(1);
    View view1 = tree.findViewById(1);
    OptionalId target = new OptionalId();
    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 27 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnClickTest method optionalIdAbsent.

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

Example 28 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnItemClickTest method optionalIdPresent.

@UiThreadTest
@Test
public void optionalIdPresent() {
    View tree = ViewTree.create(TestSpinner.class, 1);
    TestSpinner spinner = tree.findViewById(1);
    OptionalId target = new OptionalId();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(-1, target.clickedPosition);
    spinner.performItemClick(0);
    assertEquals(0, target.clickedPosition);
    unbinder.unbind();
    spinner.performItemClick(1);
    assertEquals(0, target.clickedPosition);
}
Also used : Unbinder(butterknife.Unbinder) View(android.view.View) AdapterView(android.widget.AdapterView) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 29 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnItemClickTest method multipleBindings.

@UiThreadTest
@Test
public void multipleBindings() {
    // TODO
    assumeFalse("Not implemented", BuildConfig.FLAVOR.equals("reflect"));
    View tree = ViewTree.create(TestSpinner.class, 1);
    TestSpinner spinner = tree.findViewById(1);
    MultipleBindings target = new MultipleBindings();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(-1, target.clickedPosition1);
    assertEquals(-1, target.clickedPosition2);
    spinner.performItemClick(0);
    assertEquals(0, target.clickedPosition1);
    assertEquals(0, target.clickedPosition2);
    unbinder.unbind();
    spinner.performItemClick(1);
    assertEquals(0, target.clickedPosition1);
    assertEquals(0, target.clickedPosition2);
}
Also used : Unbinder(butterknife.Unbinder) View(android.view.View) AdapterView(android.widget.AdapterView) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 30 with Unbinder

use of butterknife.Unbinder in project butterknife by JakeWharton.

the class OnItemClickTest method multipleIds.

@UiThreadTest
@Test
public void multipleIds() {
    View tree = ViewTree.create(TestSpinner.class, 1, 2);
    TestSpinner spinner1 = tree.findViewById(1);
    TestSpinner spinner2 = tree.findViewById(2);
    MultipleIds target = new MultipleIds();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(-1, target.clickedPosition);
    spinner1.performItemClick(0);
    assertEquals(0, target.clickedPosition);
    spinner2.performItemClick(1);
    assertEquals(1, target.clickedPosition);
    unbinder.unbind();
    spinner1.performItemClick(2);
    assertEquals(1, target.clickedPosition);
    spinner2.performItemClick(2);
    assertEquals(1, target.clickedPosition);
}
Also used : Unbinder(butterknife.Unbinder) View(android.view.View) AdapterView(android.widget.AdapterView) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

Unbinder (butterknife.Unbinder)86 Test (org.junit.Test)70 View (android.view.View)55 UiThreadTest (androidx.test.annotation.UiThreadTest)31 TextView (android.widget.TextView)23 Bundle (android.os.Bundle)15 LayoutInflater (android.view.LayoutInflater)15 AdapterView (android.widget.AdapterView)15 BindView (butterknife.BindView)15 ButterKnife (butterknife.ButterKnife)15 ViewGroup (android.view.ViewGroup)14 R (com.simplecity.amp_library.R)10 List (java.util.List)10 Inject (javax.inject.Inject)9 Nullable (android.support.annotation.Nullable)8 MenuItem (android.view.MenuItem)8 Aesthetic (com.afollestad.aesthetic.Aesthetic)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Rx.distinctToMainThread (com.afollestad.aesthetic.Rx.distinctToMainThread)6 Song (com.simplecity.amp_library.model.Song)6