Search in sources :

Example 1 with EmptyScheduler

use of io.reactivex.rxjava3.android.testutil.EmptyScheduler in project RxAndroid by ReactiveX.

the class RxAndroidPluginsTest method resetClearsMainThreadHandler.

@Test
public void resetClearsMainThreadHandler() {
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {

        @Override
        public Scheduler apply(Scheduler scheduler) {
            throw new AssertionError();
        }
    });
    RxAndroidPlugins.reset();
    Scheduler scheduler = new EmptyScheduler();
    Scheduler actual = RxAndroidPlugins.onMainThreadScheduler(scheduler);
    assertSame(scheduler, actual);
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Test(org.junit.Test)

Example 2 with EmptyScheduler

use of io.reactivex.rxjava3.android.testutil.EmptyScheduler in project RxAndroid by ReactiveX.

the class RxAndroidPluginsTest method initMainThreadHandlerCalled.

@Test
public void initMainThreadHandlerCalled() {
    final AtomicReference<Callable<Scheduler>> schedulerRef = new AtomicReference<>();
    final Scheduler newScheduler = new EmptyScheduler();
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {

        @Override
        public Scheduler apply(Callable<Scheduler> scheduler) {
            schedulerRef.set(scheduler);
            return newScheduler;
        }
    });
    Callable<Scheduler> scheduler = new Callable<Scheduler>() {

        @Override
        public Scheduler call() throws Exception {
            throw new AssertionError();
        }
    };
    Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(scheduler);
    assertSame(newScheduler, actual);
    assertSame(scheduler, schedulerRef.get());
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 3 with EmptyScheduler

use of io.reactivex.rxjava3.android.testutil.EmptyScheduler in project RxAndroid by ReactiveX.

the class RxAndroidPluginsTest method resetClearsInitMainThreadHandler.

@Test
public void resetClearsInitMainThreadHandler() throws Exception {
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {

        @Override
        public Scheduler apply(Callable<Scheduler> scheduler) {
            throw new AssertionError();
        }
    });
    final Scheduler scheduler = new EmptyScheduler();
    Callable<Scheduler> schedulerCallable = new Callable<Scheduler>() {

        @Override
        public Scheduler call() throws Exception {
            return scheduler;
        }
    };
    RxAndroidPlugins.reset();
    Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(schedulerCallable);
    assertSame(schedulerCallable.call(), actual);
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 4 with EmptyScheduler

use of io.reactivex.rxjava3.android.testutil.EmptyScheduler in project RxAndroid by ReactiveX.

the class AndroidSchedulersTest method mainThreadCallsThroughToHook.

@Test
public void mainThreadCallsThroughToHook() {
    final AtomicInteger called = new AtomicInteger();
    final Scheduler newScheduler = new EmptyScheduler();
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {

        @Override
        public Scheduler apply(Scheduler scheduler) {
            called.getAndIncrement();
            return newScheduler;
        }
    });
    assertSame(newScheduler, AndroidSchedulers.mainThread());
    assertEquals(1, called.get());
    assertSame(newScheduler, AndroidSchedulers.mainThread());
    assertEquals(2, called.get());
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Test(org.junit.Test)

Example 5 with EmptyScheduler

use of io.reactivex.rxjava3.android.testutil.EmptyScheduler in project RxAndroid by ReactiveX.

the class RxAndroidPluginsTest method mainThreadHandlerCalled.

@Test
public void mainThreadHandlerCalled() {
    final AtomicReference<Scheduler> schedulerRef = new AtomicReference<>();
    final Scheduler newScheduler = new EmptyScheduler();
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {

        @Override
        public Scheduler apply(Scheduler scheduler) {
            schedulerRef.set(scheduler);
            return newScheduler;
        }
    });
    Scheduler scheduler = new EmptyScheduler();
    Scheduler actual = RxAndroidPlugins.onMainThreadScheduler(scheduler);
    assertSame(newScheduler, actual);
    assertSame(scheduler, schedulerRef.get());
}
Also used : EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)5 Scheduler (io.reactivex.rxjava3.core.Scheduler)5 Test (org.junit.Test)5 Callable (java.util.concurrent.Callable)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1