Search in sources :

Example 76 with UiThreadTest

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

the class RxViewTest method hovers.

@Test
@UiThreadTest
public void hovers() {
    RecordingObserver<MotionEvent> o = new RecordingObserver<>();
    RxView.hovers(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_ENTER, 0, 50));
    MotionEvent event1 = o.takeNext();
    assertEquals(ACTION_HOVER_ENTER, event1.getAction());
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_MOVE, 1, 50));
    MotionEvent event2 = o.takeNext();
    assertEquals(ACTION_HOVER_MOVE, event2.getAction());
    o.dispose();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_EXIT, 1, 50));
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) MotionEvent(android.view.MotionEvent) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 77 with UiThreadTest

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

the class RxViewTest method keys.

@Test
@UiThreadTest
public void keys() {
    RecordingObserver<KeyEvent> o = new RecordingObserver<>();
    RxView.keys(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_R));
    KeyEvent event1 = o.takeNext();
    assertEquals(KeyEvent.ACTION_DOWN, event1.getAction());
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_H));
    KeyEvent event2 = o.takeNext();
    assertEquals(KeyEvent.KEYCODE_H, event2.getKeyCode());
    o.dispose();
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_S));
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 78 with UiThreadTest

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

the class RxPopupMenuTest method itemClicks.

@Test
@UiThreadTest
public void itemClicks() {
    Menu menu = view.getMenu();
    MenuItem item1 = menu.add(0, 1, 0, "Hi");
    MenuItem item2 = menu.add(0, 2, 0, "Hey");
    RecordingObserver<MenuItem> o = new RecordingObserver<>();
    com.jakewharton.rxbinding4.appcompat.RxPopupMenu.itemClicks(view).subscribe(o);
    o.assertNoMoreEvents();
    menu.performIdentifierAction(2, 0);
    assertSame(item2, o.takeNext());
    menu.performIdentifierAction(1, 0);
    assertSame(item1, o.takeNext());
    o.dispose();
    menu.performIdentifierAction(2, 0);
    o.assertNoMoreEvents();
}
Also used : MenuItem(android.view.MenuItem) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) PopupMenu(androidx.appcompat.widget.PopupMenu) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 79 with UiThreadTest

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

the class RxToolbarTest method itemClicks.

@Test
@UiThreadTest
public void itemClicks() {
    Menu menu = view.getMenu();
    MenuItem item1 = menu.add(0, 1, 0, "Hi");
    MenuItem item2 = menu.add(0, 2, 0, "Hey");
    RecordingObserver<MenuItem> o = new RecordingObserver<>();
    com.jakewharton.rxbinding4.appcompat.RxToolbar.itemClicks(view).subscribe(o);
    o.assertNoMoreEvents();
    menu.performIdentifierAction(2, 0);
    assertSame(item2, o.takeNext());
    menu.performIdentifierAction(1, 0);
    assertSame(item1, o.takeNext());
    o.dispose();
    menu.performIdentifierAction(2, 0);
    o.assertNoMoreEvents();
}
Also used : MenuItem(android.view.MenuItem) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 80 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalNoStartPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalNoStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(4);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 4) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 3) {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 1) {
                    assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus);
                }
                countDownLatch.countDown();
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, false, true);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.PREPARED, psmp.getPSMPInfo().playerStatus);
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) 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