@Test public void invalidDeferredRequest() { AtomicReference<Subscription> s = new AtomicReference<Subscription>(); AtomicLong r = new AtomicLong(); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { SubscriptionHelper.deferredRequest(s, r, -99); TestCommonHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void timerDelayZero() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { for (int i = 0; i < 1000; i++) { Observable.timer(0, TimeUnit.MILLISECONDS).blockingFirst(); } assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void timerDelayZero() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { for (int i = 0; i < 1000; i++) { Flowable.timer(0, TimeUnit.MILLISECONDS).blockingFirst(); } assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void errorConsumerEmpty() throws Exception { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { Functions.ERROR_CONSUMER.accept(new TestException()); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); assertEquals(errors.toString(), 1, errors.size()); } finally { RxJavaCommonPlugins.reset(); } } }
@Test public void producedMoreCancel() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { AtomicLong requested = new AtomicLong(1); assertEquals(0, BackpressureHelper.producedCancel(requested, 2)); TestCommonHelper.assertError(list, 0, IllegalStateException.class, "More produced than requested: -1"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void producedMore() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { AtomicLong requested = new AtomicLong(1); assertEquals(0, BackpressureHelper.produced(requested, 2)); TestCommonHelper.assertError(list, 0, IllegalStateException.class, "More produced than requested: -1"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void validateNullThrows() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { SubscriptionHelper.validate(null, null); TestCommonHelper.assertError(errors, 0, NullPointerException.class, "next is null"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void invalidDeferredRequest() { SubscriptionArbiter sa = new SubscriptionArbiter(); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { sa.request(-99); TestCommonHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void validationNull() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { assertFalse(DisposableHelper.validate(null, null)); TestCommonHelper.assertError(list, 0, NullPointerException.class, "next is null"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void onSubscribeCrashes() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { CrashDummy cd = new CrashDummy(true, 1, false, false, false); SafeObserver<Object> so = cd.toSafe(); so.onSubscribe(cd); TestCommonHelper.assertUndeliverable(list, 0, TestException.class, "onSubscribe()"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void onSubscribeCrashes() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { CrashDummy cd = new CrashDummy(true, 1, false, false, false, false); SafeSubscriber<Object> so = cd.toSafe(); so.onSubscribe(cd); TestCommonHelper.assertUndeliverable(list, 0, TestException.class, "onSubscribe()"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void nextObserverError() { NextSubscriber<Integer> no = new NextSubscriber<Integer>(); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { no.onError(new TestException()); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void nextObserverError() { NextObserver<Integer> no = new NextObserver<Integer>(); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { no.onError(new TestException()); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void badRequest() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L); ScalarSubscription<Integer> sc = new ScalarSubscription<Integer>(ts, 1); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { sc.request(-99); TestCommonHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void negativeRequest() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); TestSubscriber<Integer> ts = TestSubscriber.create(0); TestingDeferredScalarSubscriber ds = new TestingDeferredScalarSubscriber(ts); ds.setupDownstream(); ds.downstreamRequest(-99); RxJavaCommonPlugins.reset(); TestCommonHelper.assertError(list, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); }
@Test public void invalidDeferredRequest() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { new FullArbiter<Integer>(new TestSubscriber<Integer>(), null, 128).request(-99); TestCommonHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void noErrorLoss() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { ConnectableFlowable<Object> co = Flowable.error(new TestException()).publish(); co.connect(); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void onErrorAfterComplete() { BehaviorProcessor<Object> p = BehaviorProcessor.create(); p.onComplete(); List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { p.onError(new TestException()); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void noErrorLoss() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { ConnectableObservable<Object> co = Observable.error(new TestException()).publish(); co.connect(); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void noneagerMapperThrowsDisposerThrows() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { Single.using(Functions.justCallable(Disposables.empty()), mapperThrows, disposerThrows, false) .test() .assertFailureAndMessage(TestException.class, "Mapper"); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class, "Disposer"); } finally { RxJavaCommonPlugins.reset(); } }