@Test public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() { try { RxAndroidPlugins.initMainThreadScheduler(null); fail(); } catch (NullPointerException e) { assertEquals("scheduler == null", e.getMessage()); } }
@Test public void overrideInitSingleSchedulerCrashes() { // fail when Callable is null try { RxJavaPlugins.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 { RxJavaPlugins.initSingleScheduler(nullResultCallable); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } }
@Test public void overrideInitComputationSchedulerCrashes() { // fail when Callable is null try { RxJavaPlugins.initComputationScheduler(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 { RxJavaPlugins.initComputationScheduler(nullResultCallable); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } }
@Test public void overrideInitIoSchedulerCrashes() { // fail when Callable is null try { RxJavaPlugins.initIoScheduler(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 { RxJavaPlugins.initIoScheduler(nullResultCallable); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } }
@Test public void overrideInitNewThreadSchedulerCrashes() { // fail when Callable is null try { RxJavaPlugins.initNewThreadScheduler(null); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { // expected assertEquals("Scheduler Callable can't be null", npe.getMessage()); } // fail when Callable result is null try { RxJavaPlugins.initNewThreadScheduler(nullResultCallable); fail("Should have thrown NullPointerException"); } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } }
@Test public void schedulePeriodicallyDirectNullRunnable() { try { getScheduler().schedulePeriodicallyDirect(null, 5, 10, TimeUnit.MILLISECONDS); fail(); } catch (NullPointerException npe) { assertEquals("run is null", npe.getMessage()); } } }
@Test public void scheduleDirectNullRunnable() { try { getScheduler().scheduleDirect(null); fail(); } catch (NullPointerException npe) { assertEquals("run is null", npe.getMessage()); } }
@Test public void scheduleDirectWithDelayNullRunnable() { try { getScheduler().scheduleDirect(null, 10, TimeUnit.MILLISECONDS); fail(); } catch (NullPointerException npe) { assertEquals("run is null", npe.getMessage()); } }
@Test public void nullActionShouldBeCheckedInConstructor() { try { Flowable.empty().doAfterTerminate(null); fail("Should have thrown NullPointerException"); } catch (NullPointerException expected) { assertEquals("onAfterTerminate is null", expected.getMessage()); } }
@Test public void sourceThrowsNPE() { try { Maybe.unsafeCreate(new MaybeSource<Object>() { @Override public void subscribe(MaybeObserver<? super Object> observer) { throw new NullPointerException("Forced failure"); } }).test(); fail("Should have thrown!"); } catch (NullPointerException ex) { assertEquals("Forced failure", ex.getMessage()); } }
@Test public void fromNullThrowsTwoArg() { try { AndroidSchedulers.from(null, false); fail(); } catch (NullPointerException e) { assertEquals("looper == null", e.getMessage()); } }
@SuppressWarnings("rawtypes") @Test public void pluginNull() { RxJavaPlugins.setOnObservableSubscribe(new BiFunction<Observable, Observer, Observer>() { @Override public Observer apply(Observable a, Observer b) throws Exception { return null; } }); try { try { Observable.just(1).test(); fail("Should have thrown"); } catch (NullPointerException ex) { assertEquals("The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage()); } } finally { RxJavaPlugins.reset(); } }
@Test public void onErrorNull() { FlowableProcessor<T> p = create(); try { p.onError(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } p.test().assertEmpty().cancel(); } }
@Test public void nullThrowable() { CompletableSubject cs = CompletableSubject.create(); try { cs.onError(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } cs.test().assertEmpty().cancel();; }
@Test public void onNextNull() { Subject<T> p = create(); try { p.onNext(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } p.test().assertEmpty().cancel(); }
@Test public void nullValue() { SingleSubject<Integer> ss = SingleSubject.create(); try { ss.onSuccess(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } ss.test().assertEmpty().cancel(); }
@Test public void nullThrowable() { SingleSubject<Integer> ss = SingleSubject.create(); try { ss.onError(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } ss.test().assertEmpty().cancel(); }
@Test public void onNextNull() { FlowableProcessor<T> p = create(); try { p.onNext(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } p.test().assertEmpty().cancel(); }
@Test public void onErrorNull() { Subject<T> p = create(); try { p.onError(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } p.test().assertEmpty().cancel(); } }
@SuppressWarnings("rawtypes") @Test public void pluginNull() { RxJavaPlugins.setOnFlowableSubscribe(new BiFunction<Flowable, Subscriber, Subscriber>() { @Override public Subscriber apply(Flowable a, Subscriber b) throws Exception { return null; } }); try { try { Flowable.just(1).test(); fail("Should have thrown"); } catch (NullPointerException ex) { assertEquals("The RxJavaPlugins.onSubscribe hook returned a null FlowableSubscriber. Please check the handler provided to RxJavaPlugins.setOnFlowableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage()); } } finally { RxJavaPlugins.reset(); } }