Search in sources :

Example 86 with UiThreadTest

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

the class PlaybackServiceMediaPlayerTest method setUp.

@Before
@UiThreadTest
public void setUp() throws Exception {
    assertionError = null;
    EspressoTestUtils.clearPreferences();
    EspressoTestUtils.clearDatabase();
    final Context context = getInstrumentation().getTargetContext();
    httpServer = new HTTPBin();
    httpServer.start();
    playableFileUrl = httpServer.getBaseUrl() + "/files/0";
    File cacheDir = context.getExternalFilesDir("testFiles");
    if (cacheDir == null)
        cacheDir = context.getExternalFilesDir("testFiles");
    File dest = new File(cacheDir, PLAYABLE_DEST_URL);
    assertNotNull(cacheDir);
    assertTrue(cacheDir.canWrite());
    assertTrue(cacheDir.canRead());
    if (!dest.exists()) {
        InputStream i = getInstrumentation().getTargetContext().getAssets().open("3sec.mp3");
        OutputStream o = new FileOutputStream(new File(cacheDir, PLAYABLE_DEST_URL));
        IOUtils.copy(i, o);
        o.flush();
        o.close();
        i.close();
    }
    PLAYABLE_LOCAL_URL = dest.getAbsolutePath();
    assertEquals(0, httpServer.serveFile(dest));
}
Also used : Context(android.content.Context) HTTPBin(de.test.antennapod.util.service.download.HTTPBin) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Before(org.junit.Before) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 87 with UiThreadTest

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

the class PlaybackServiceTaskManagerTest method testIsSleepTimerActiveNegative.

@Test
@UiThreadTest
public void testIsSleepTimerActiveNegative() {
    final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.setSleepTimer(10000);
    pstm.disableSleepTimer();
    assertFalse(pstm.isSleepTimerActive());
    pstm.shutdown();
}
Also used : Context(android.content.Context) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 88 with UiThreadTest

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

the class PlaybackServiceTaskManagerTest method testDisableSleepTimer.

@Test
@UiThreadTest
public void testDisableSleepTimer() throws InterruptedException {
    final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
    final long TIME = 5000;
    final long TIMEOUT = 2 * TIME;
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Object timerReceiver = new Object() {

        @Subscribe
        public void sleepTimerUpdate(SleepTimerUpdatedEvent event) {
            if (event.isOver()) {
                countDownLatch.countDown();
            } else if (event.getTimeLeft() == 1) {
                fail("Arrived at 1 but should have been cancelled");
            }
        }
    };
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    EventBus.getDefault().register(timerReceiver);
    pstm.setSleepTimer(TIME);
    pstm.disableSleepTimer();
    assertFalse(countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));
    pstm.shutdown();
    EventBus.getDefault().unregister(timerReceiver);
}
Also used : Context(android.content.Context) SleepTimerUpdatedEvent(de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 89 with UiThreadTest

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

the class PlaybackServiceTaskManagerTest method testIsSleepTimerActivePositive.

@Test
@UiThreadTest
public void testIsSleepTimerActivePositive() {
    final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.setSleepTimer(1000);
    assertTrue(pstm.isSleepTimerActive());
    pstm.shutdown();
}
Also used : Context(android.content.Context) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 90 with UiThreadTest

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

the class OnItemClickTest method visibilities.

@UiThreadTest
@Test
public void visibilities() {
    View tree = ViewTree.create(TestSpinner.class, 1, 2, 3);
    TestSpinner spinner1 = tree.findViewById(1);
    TestSpinner spinner2 = tree.findViewById(2);
    TestSpinner spinner3 = tree.findViewById(3);
    Visibilities target = new Visibilities();
    ButterKnife.bind(target, tree);
    assertEquals(-1, target.clickedPosition);
    spinner1.performItemClick(0);
    assertEquals(0, target.clickedPosition);
    spinner2.performItemClick(1);
    assertEquals(1, target.clickedPosition);
    spinner3.performItemClick(2);
    assertEquals(2, target.clickedPosition);
}
Also used : View(android.view.View) AdapterView(android.widget.AdapterView) 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