Search in sources :

Example 1 with SleepTimerUpdatedEvent

use of de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testSetSleepTimer.

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

        @Subscribe
        public void sleepTimerUpdate(SleepTimerUpdatedEvent event) {
            if (countDownLatch.getCount() == 0) {
                fail();
            }
            countDownLatch.countDown();
        }
    };
    EventBus.getDefault().register(timerReceiver);
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.setSleepTimer(TIME);
    countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
    EventBus.getDefault().unregister(timerReceiver);
    pstm.shutdown();
}
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 2 with SleepTimerUpdatedEvent

use of de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent 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)

Aggregations

Context (android.content.Context)2 UiThreadTest (androidx.test.annotation.UiThreadTest)2 LargeTest (androidx.test.filters.LargeTest)2 PlaybackServiceTaskManager (de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)2 SleepTimerUpdatedEvent (de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2