Search in sources :

Example 6 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project butterknife by JakeWharton.

the class OnItemClickTest method simple.

@UiThreadTest
@Test
public void simple() {
    View tree = ViewTree.create(TestSpinner.class, 1);
    TestSpinner spinner = tree.findViewById(1);
    Simple target = new Simple();
    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 7 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project butterknife by JakeWharton.

the class OnItemSelectedTest method argumentCast.

@UiThreadTest
@Test
public void argumentCast() {
    class MySpinner extends TestSpinner implements ArgumentCast.MyInterface {

        MySpinner(Context context) {
            super(context);
        }
    }
    Context context = InstrumentationRegistry.getContext();
    TestSpinner spinner1 = new MySpinner(context);
    spinner1.setId(1);
    TestSpinner spinner2 = new MySpinner(context);
    spinner2.setId(2);
    TestSpinner spinner3 = new MySpinner(context);
    spinner3.setId(3);
    ViewGroup tree = new FrameLayout(context);
    tree.addView(spinner1);
    tree.addView(spinner2);
    tree.addView(spinner3);
    ArgumentCast target = new ArgumentCast();
    ButterKnife.bind(target, tree);
    spinner1.performSelection(0);
    assertSame(spinner1, target.last);
    spinner2.performSelection(0);
    assertSame(spinner2, target.last);
    spinner3.performSelection(0);
    assertSame(spinner3, target.last);
    spinner1.clearSelection();
    assertSame(spinner1, target.last);
    spinner2.clearSelection();
    assertSame(spinner2, target.last);
    spinner3.clearSelection();
    assertSame(spinner3, target.last);
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 8 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project butterknife by JakeWharton.

the class OnItemSelectedTest method optionalIdAbsent.

@UiThreadTest
@Test
public void optionalIdAbsent() {
    View tree = ViewTree.create(TestSpinner.class, 2);
    TestSpinner spinner = tree.findViewById(2);
    OptionalId target = new OptionalId();
    target.selectedPosition = 1;
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(1, target.selectedPosition);
    spinner.performSelection(0);
    assertEquals(1, target.selectedPosition);
    spinner.clearSelection();
    assertEquals(1, target.selectedPosition);
    unbinder.unbind();
    spinner.performSelection(1);
    assertEquals(1, target.selectedPosition);
    spinner.clearSelection();
    assertEquals(1, target.selectedPosition);
}
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 9 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project butterknife by JakeWharton.

the class OnTouchTest method arguments.

@UiThreadTest
@Test
public void arguments() {
    View tree = ViewTree.create(1, 2);
    View view1 = tree.findViewById(1);
    View view2 = tree.findViewById(2);
    Arguments target = new Arguments();
    Unbinder unbinder = ButterKnife.bind(target, tree);
    assertEquals(0, target.touches);
    assertTrue(performTouch(view1));
    assertEquals(1, target.touches);
    assertTrue(performTouch(view2));
    assertEquals(2, target.touches);
    unbinder.unbind();
    performTouch(view1);
    assertEquals(2, target.touches);
}
Also used : Unbinder(butterknife.Unbinder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 10 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project butterknife by JakeWharton.

the class OnTouchTest method simple.

@UiThreadTest
@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.touches);
    assertTrue(performTouch(view1));
    assertEquals(1, target.touches);
    target.returnValue = false;
    assertFalse(performTouch(view1));
    assertEquals(2, target.touches);
    unbinder.unbind();
    performTouch(view1);
    assertEquals(2, target.touches);
}
Also used : Unbinder(butterknife.Unbinder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)136 Test (org.junit.Test)129 View (android.view.View)41 Unbinder (butterknife.Unbinder)31 Context (android.content.Context)23 AdapterView (android.widget.AdapterView)18 TextView (android.widget.TextView)15 RecordingObserver (com.jakewharton.rxbinding4.RecordingObserver)15 MediumTest (androidx.test.filters.MediumTest)14 Intent (android.content.Intent)10 SubscriptionInfo (android.telephony.SubscriptionInfo)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)9 PlaybackServiceMediaPlayer (de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer)9 Slice (androidx.slice.Slice)8 Playable (de.danoeh.antennapod.model.playback.Playable)8 AssertionFailedError (junit.framework.AssertionFailedError)8 Before (org.junit.Before)7 ViewGroup (android.view.ViewGroup)6 FrameLayout (android.widget.FrameLayout)6