Search in sources :

Example 1 with TestRunnable

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);
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Test(org.junit.Test)

Example 2 with TestRunnable

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);
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Test(org.junit.Test)

Example 3 with TestRunnable

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();
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Handler(android.os.Handler) Test(org.junit.Test)

Example 4 with TestRunnable

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();
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Handler(android.os.Handler) Test(org.junit.Test)

Example 5 with TestRunnable

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();
}
Also used : TestRunnable(org.robolectric.util.TestRunnable) Handler(android.os.Handler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 TestRunnable (org.robolectric.util.TestRunnable)10 Handler (android.os.Handler)4 LooperMode (org.robolectric.annotation.LooperMode)2