use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class RuntimeEnvironmentTest method isMainThread_forNewThread_withoutSwitch.
@Test
@LooperMode(LEGACY)
public void isMainThread_forNewThread_withoutSwitch() throws InterruptedException {
final AtomicBoolean res = new AtomicBoolean();
final CountDownLatch finished = new CountDownLatch(1);
Thread t = new Thread() {
@Override
public void run() {
res.set(RuntimeEnvironment.isMainThread());
finished.countDown();
}
};
RuntimeEnvironment.setMainThread(Thread.currentThread());
t.start();
if (!finished.await(1000, MILLISECONDS)) {
throw new InterruptedException("Thread " + t + " didn't finish timely");
}
assertWithMessage("testThread").that(RuntimeEnvironment.isMainThread()).isTrue();
assertWithMessage("thread t").that(res.get()).isFalse();
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class RuntimeEnvironmentTest method isMainThread_forNewThread_withSwitch.
@Test
@LooperMode(LEGACY)
public void isMainThread_forNewThread_withSwitch() throws InterruptedException {
final AtomicBoolean res = new AtomicBoolean();
final CountDownLatch finished = new CountDownLatch(1);
Thread t = new Thread(() -> {
res.set(RuntimeEnvironment.isMainThread());
finished.countDown();
});
RuntimeEnvironment.setMainThread(t);
t.start();
if (!finished.await(1000, MILLISECONDS)) {
throw new InterruptedException("Thread " + t + " didn't finish timely");
}
assertWithMessage("testThread").that(RuntimeEnvironment.isMainThread()).isFalse();
assertWithMessage("thread t").that(res.get()).isTrue();
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class ShadowApplicationTest method getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_byDefault.
@Test
@LooperMode(LEGACY)
public void getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_byDefault() {
Scheduler s = new Scheduler();
RuntimeEnvironment.setMasterScheduler(s);
assertThat(Shadows.shadowOf(context).getBackgroundThreadScheduler()).isNotSameInstanceAs(RuntimeEnvironment.getMasterScheduler());
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class ShadowActivityTest method shouldQueueUiTasksWhenUiThreadIsPaused.
@Test
@LooperMode(LEGACY)
public void shouldQueueUiTasksWhenUiThreadIsPaused() throws Exception {
shadowOf(getMainLooper()).pause();
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
TestRunnable runnable = new TestRunnable();
activity.runOnUiThread(runnable);
assertFalse(runnable.wasRun);
shadowOf(getMainLooper()).idle();
assertTrue(runnable.wasRun);
}
use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.
the class LooperModeConfigurerClassTest method shouldUseRealisticShadows.
@Test
@LooperMode(Mode.PAUSED)
public void shouldUseRealisticShadows() {
assertThat(ConfigurationRegistry.get(LooperMode.Mode.class)).isSameInstanceAs(Mode.PAUSED);
ShadowLooper looper = Shadow.extract(Looper.getMainLooper());
assertThat(looper).isInstanceOf(ShadowPausedLooper.class);
}
Aggregations