Search in sources :

Example 1 with ShadowMessageQueue

use of org.robolectric.shadows.ShadowMessageQueue in project android_packages_apps_Settings by DirtyUnicorns.

the class ShadowPackageMonitor method setupBackgroundThreadScheduler.

private static void setupBackgroundThreadScheduler() {
    ShadowMessageQueue shadowMessageQueue = ((ShadowMessageQueue) ShadowExtractor.extract(BackgroundThread.getHandler().getLooper().getQueue()));
    shadowMessageQueue.setScheduler(ShadowApplication.getInstance().getBackgroundThreadScheduler());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue)

Example 2 with ShadowMessageQueue

use of org.robolectric.shadows.ShadowMessageQueue in project RxAndroid by ReactiveX.

the class AndroidSchedulersTest method asyncIgnoredPre16.

@Test
public void asyncIgnoredPre16() {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 14);
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.from(Looper.getMainLooper(), true);
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertFalse(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Build(android.os.Build) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Example 3 with ShadowMessageQueue

use of org.robolectric.shadows.ShadowMessageQueue in project RxAndroid by ReactiveX.

the class AndroidSchedulersTest method fromAsyncMessagesByDefault.

@Test
public void fromAsyncMessagesByDefault() {
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.from(Looper.getMainLooper());
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertTrue(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Example 4 with ShadowMessageQueue

use of org.robolectric.shadows.ShadowMessageQueue in project RxAndroid by ReactiveX.

the class AndroidSchedulersTest method mainThreadAsyncMessagesByDefault.

@Test
public void mainThreadAsyncMessagesByDefault() {
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.mainThread();
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertTrue(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Example 5 with ShadowMessageQueue

use of org.robolectric.shadows.ShadowMessageQueue in project android_packages_apps_Settings by LineageOS.

the class ShadowPackageMonitor method setupBackgroundThreadScheduler.

private static void setupBackgroundThreadScheduler() {
    ShadowMessageQueue shadowMessageQueue = ((ShadowMessageQueue) ShadowExtractor.extract(BackgroundThread.getHandler().getLooper().getQueue()));
    shadowMessageQueue.setScheduler(ShadowApplication.getInstance().getBackgroundThreadScheduler());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue)

Aggregations

ShadowMessageQueue (org.robolectric.shadows.ShadowMessageQueue)12 Message (android.os.Message)6 Test (org.junit.Test)6 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)3 Scheduler (io.reactivex.rxjava3.core.Scheduler)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)2 Build (android.os.Build)1