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