use of org.robolectric.util.TestRunnable 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.util.TestRunnable in project robolectric by robolectric.
the class ShadowViewTest method shouldRemovePostedCallbacksFromMessageQueue.
@Test
public void shouldRemovePostedCallbacksFromMessageQueue() throws Exception {
TestRunnable runnable = new TestRunnable();
assertThat(view.postDelayed(runnable, 1)).isTrue();
assertThat(view.removeCallbacks(runnable)).isTrue();
shadowMainLooper().idleFor(Duration.ofMillis(1));
assertThat(runnable.wasRun).isFalse();
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowViewTest method shouldPostActionsToTheMessageQueueWithDelay.
@Test
public void shouldPostActionsToTheMessageQueueWithDelay() throws Exception {
shadowMainLooper().pause();
TestRunnable runnable = new TestRunnable();
view.postDelayed(runnable, 1);
assertFalse(runnable.wasRun);
shadowMainLooper().idleFor(Duration.ofMillis(1));
assertTrue(runnable.wasRun);
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowHandlerTest method testPostDelayedTwiceThenRunMainLooperToNextTask_shouldRunMultipleTasks.
@Test
public void testPostDelayedTwiceThenRunMainLooperToNextTask_shouldRunMultipleTasks() {
TestRunnable task1 = new TestRunnable();
TestRunnable task2 = new TestRunnable();
new Handler().postDelayed(task1, 1);
new Handler().postDelayed(task2, 1);
ShadowLooper.runMainLooperToNextTask();
assertThat(task1.wasRun).isTrue();
assertThat(task2.wasRun).isTrue();
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowActivityTest method shouldExecutePostedUiTasksInRealisticLooper.
/**
* The legacy behavior spec-ed in {@link #shouldQueueUiTasksWhenUiThreadIsPaused()} is actually
* incorrect. The {@link Activity#runOnUiThread} will execute posted tasks inline.
*/
@Test
@LooperMode(Mode.PAUSED)
public void shouldExecutePostedUiTasksInRealisticLooper() throws Exception {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
TestRunnable runnable = new TestRunnable();
activity.runOnUiThread(runnable);
assertTrue(runnable.wasRun);
}
Aggregations