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();
}
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);
}
Aggregations