@Test public void overrideInitSingleSchedulerCrashes() { // fail when Callable is null try { RxJavaCommonPlugins.initSingleScheduler(null); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable can't be null", npe.getMessage()); } // fail when Callable result is null try { RxJavaCommonPlugins.initSingleScheduler(nullResultCallable); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } }
@Test public void overrideInitSingleScheduler() { final Scheduler s = Schedulers.single(); // make sure the Schedulers is initialized Callable<Scheduler> c = new Callable<Scheduler>() { @Override public Scheduler call() throws Exception { return s; } }; try { RxJavaCommonPlugins.setInitSingleSchedulerHandler(initReplaceWithImmediate); assertSame(ImmediateThinScheduler.INSTANCE, RxJavaCommonPlugins.initSingleScheduler(c)); } finally { RxJavaCommonPlugins.reset(); } // make sure the reset worked assertSame(s, RxJavaCommonPlugins.initSingleScheduler(c)); }
@Test public void testDefaultSingleSchedulerIsInitializedLazily() { // unsafe default Scheduler Callable should not be evaluated try { RxJavaCommonPlugins.setInitSingleSchedulerHandler(initReplaceWithImmediate); RxJavaCommonPlugins.initSingleScheduler(unsafeDefault); } finally { RxJavaCommonPlugins.reset(); } // make sure the reset worked assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.single()); }
assertSame(s, RxJavaCommonPlugins.initSingleScheduler(c));