use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowViewTest method shouldPostActionsToTheMessageQueue.
@Test
public void shouldPostActionsToTheMessageQueue() throws Exception {
shadowMainLooper().pause();
TestRunnable runnable = new TestRunnable();
assertThat(view.post(runnable)).isTrue();
assertFalse(runnable.wasRun);
shadowMainLooper().idle();
assertTrue(runnable.wasRun);
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowActivityTest method shouldRunUiTasksImmediatelyByDefault.
@Test
public void shouldRunUiTasksImmediatelyByDefault() throws Exception {
TestRunnable runnable = new TestRunnable();
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
activity.runOnUiThread(runnable);
assertTrue(runnable.wasRun);
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowHandlerTest method testPostDelayedTwiceThenRunMainLooperOneTask_shouldRunOnlyOneTask.
@Test
public void testPostDelayedTwiceThenRunMainLooperOneTask_shouldRunOnlyOneTask() {
TestRunnable task1 = new TestRunnable();
TestRunnable task2 = new TestRunnable();
new Handler().postDelayed(task1, 1);
new Handler().postDelayed(task2, 1);
ShadowLooper.runMainLooperOneTask();
assertThat(task1.wasRun).isTrue();
assertThat(task2.wasRun).isFalse();
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowHandlerTest method testPostAtFrontOfQueueThenRunMainLooperOneTaskAtATime_shouldRunFrontOfQueueTaskFirst.
@Test
public void testPostAtFrontOfQueueThenRunMainLooperOneTaskAtATime_shouldRunFrontOfQueueTaskFirst() {
TestRunnable task1 = new TestRunnable();
TestRunnable task2 = new TestRunnable();
ShadowLooper.pauseMainLooper();
new Handler().post(task1);
boolean result = new Handler().postAtFrontOfQueue(task2);
assertTrue(result);
ShadowLooper.runMainLooperOneTask();
assertThat(task2.wasRun).isTrue();
assertThat(task1.wasRun).isFalse();
ShadowLooper.runMainLooperOneTask();
assertThat(task1.wasRun).isTrue();
}
use of org.robolectric.util.TestRunnable in project robolectric by robolectric.
the class ShadowHandlerTest method testPostDelayedMultipleThenRunMainLooperOneTask_shouldRunMultipleTask.
@Test
public void testPostDelayedMultipleThenRunMainLooperOneTask_shouldRunMultipleTask() {
TestRunnable task1 = new TestRunnable();
TestRunnable task2 = new TestRunnable();
TestRunnable task3 = new TestRunnable();
new Handler().postDelayed(task1, 1);
new Handler().postDelayed(task2, 10);
new Handler().postDelayed(task3, 100);
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
assertThat(task1.wasRun).isTrue();
assertThat(task2.wasRun).isTrue();
assertThat(task3.wasRun).isTrue();
}
Aggregations