Search in sources :

Example 26 with Scheduler

use of org.robolectric.util.Scheduler in project robolectric by robolectric.

the class ShadowLegacyMessageTest method recycle_shouldRemoveMessageFromScheduler.

private void recycle_shouldRemoveMessageFromScheduler() {
    ShadowLooper.pauseMainLooper();
    Handler h = new Handler();
    Message msg = Message.obtain(h, 234);
    msg.sendToTarget();
    Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
    assertWithMessage("before recycle").that(scheduler.size()).isEqualTo(1);
    shadowOf(msg).recycleUnchecked();
    assertWithMessage("after recycle").that(scheduler.size()).isEqualTo(0);
}
Also used : Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(android.os.Message) Scheduler(org.robolectric.util.Scheduler) Handler(android.os.Handler)

Example 27 with Scheduler

use of org.robolectric.util.Scheduler in project robolectric by robolectric.

the class ShadowLegacyLooperTest method shouldSetNewScheduler_whenLooperIsReset.

@Test
public void shouldSetNewScheduler_whenLooperIsReset() {
    HandlerThread ht = getHandlerThread();
    Looper looper = ht.getLooper();
    ShadowLooper sLooper = shadowOf(looper);
    Scheduler old = sLooper.getScheduler();
    sLooper.reset();
    assertThat(old).isNotSameInstanceAs(sLooper.getScheduler());
}
Also used : ShadowLooper.shadowMainLooper(org.robolectric.shadows.ShadowLooper.shadowMainLooper) Looper(android.os.Looper) HandlerThread(android.os.HandlerThread) Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Example 28 with Scheduler

use of org.robolectric.util.Scheduler in project robolectric by robolectric.

the class ShadowLegacyLooperTest method reset_setsSchedulerToMaster_forNonMainLooper_withAdvancedScheduling.

@Test
public void reset_setsSchedulerToMaster_forNonMainLooper_withAdvancedScheduling() {
    HandlerThread ht = getHandlerThread();
    ShadowLooper sLooper = shadowOf(ht.getLooper());
    Scheduler s = new Scheduler();
    RuntimeEnvironment.setMasterScheduler(s);
    setAdvancedScheduling();
    sLooper.reset();
    assertThat(sLooper.getScheduler()).isSameInstanceAs(s);
}
Also used : HandlerThread(android.os.HandlerThread) Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Example 29 with Scheduler

use of org.robolectric.util.Scheduler in project robolectric by robolectric.

the class ShadowLegacyLooperTest method reset_setsGlobalScheduler_forMainLooper_withAdvancedScheduling.

@Test
public void reset_setsGlobalScheduler_forMainLooper_withAdvancedScheduling() {
    setAdvancedScheduling();
    ShadowLooper sMainLooper = ShadowLooper.getShadowMainLooper();
    Scheduler s = new Scheduler();
    RuntimeEnvironment.setMasterScheduler(s);
    sMainLooper.reset();
    assertThat(sMainLooper.getScheduler()).isSameInstanceAs(s);
}
Also used : Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Example 30 with Scheduler

use of org.robolectric.util.Scheduler in project androidannotations by androidannotations.

the class SupposeThreadTest method testSupposeUiAndUi.

@Test
public void testSupposeUiAndUi() throws Exception {
    Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
    final AtomicBoolean run = new AtomicBoolean(false);
    scheduler.pause();
    bean.uiSupposedAndUi(new Runnable() {

        @Override
        public void run() {
            run.set(true);
        }
    });
    if (run.get()) {
        throw new IllegalStateException("Runnable wasn't post through handler, but was invoked");
    }
    scheduler.unPause();
    scheduler.advanceToLastPostedRunnable();
    if (!run.get()) {
        throw new IllegalStateException("Runnable wasn't invoked");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Aggregations

Scheduler (org.robolectric.util.Scheduler)30 Test (org.junit.Test)22 HandlerThread (android.os.HandlerThread)8 Handler (android.os.Handler)6 Looper (android.os.Looper)6 LooperMode (org.robolectric.annotation.LooperMode)5 Application (android.app.Application)4 Context (android.content.Context)3 ApplicationInfo (android.content.pm.ApplicationInfo)2 Message (android.os.Message)2 ArrayList (java.util.ArrayList)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)2 ShadowLooper.shadowMainLooper (org.robolectric.shadows.ShadowLooper.shadowMainLooper)2 ActivityThread (android.app.ActivityThread)1 Instrumentation (android.app.Instrumentation)1 LoadedApk (android.app.LoadedApk)1 JobScheduler (android.app.job.JobScheduler)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1