@Override public CompletableSource apply(Object v) throws Exception { return Completable.never(); } }, new Consumer<Object>() {
@Override public CompletableSource apply(Object v) throws Exception { return Completable.never(); } }, new Consumer<Object>() {
@Override public CompletableSource apply(Object v) throws Exception { return Completable.never(); } }, new Consumer<Object>() {
@Test(timeout = 5000) public void getTimeout() { try { Completable.never().blockingGet(100, TimeUnit.MILLISECONDS); } catch (RuntimeException ex) { if (!(ex.getCause() instanceof TimeoutException)) { Assert.fail("Wrong exception cause: " + ex.getCause()); } } }
@Test public void ambLots() { List<Completable> ms = new ArrayList<Completable>(); for (int i = 0; i < 32; i++) { ms.add(Completable.never()); } ms.add(Completable.complete()); Completable.amb(ms) .test() .assertResult(); }
@Test(timeout = 5000) public void never() { final AtomicBoolean onSubscribeCalled = new AtomicBoolean(); final AtomicInteger calls = new AtomicInteger(); Completable.never().subscribe(new CompletableObserver() { @Override public void onSubscribe(Disposable d) { onSubscribeCalled.set(true); } @Override public void onError(Throwable e) { calls.getAndIncrement(); } @Override public void onComplete() { calls.getAndIncrement(); } }); Assert.assertTrue("onSubscribe not called", onSubscribeCalled.get()); Assert.assertEquals("There were calls to onXXX methods", 0, calls.get()); }
@Test(timeout = 5000) public void timeoutEmitError() { Throwable e = Completable.never().timeout(100, TimeUnit.MILLISECONDS).blockingGet(); Assert.assertTrue(e instanceof TimeoutException); }
@Test(timeout = 5000) public void timeoutSwitchNormal() { Completable c = Completable.never().timeout(100, TimeUnit.MILLISECONDS, normal.completable); c.blockingAwait(); normal.assertSubscriptions(1); }
@Test public void never() { Completable.never() .hide() .test() .assertNotComplete() .assertNoErrors(); }
@Test public void timeoutException() throws Exception { Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Test public void nullSourceSuccessRace() { for (int i = 0; i < 1000; i++) { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { final Subject<Integer> ps = ReplaySubject.create(); ps.onNext(1); final Completable source = Completable.ambArray(ps.ignoreElements(), Completable.never(), Completable.never(), null); Runnable r1 = new Runnable() { @Override public void run() { source.test(); } }; Runnable r2 = new Runnable() { @Override public void run() { ps.onComplete(); } }; TestCommonHelper.race(r1, r2, Schedulers.single()); if (!errors.isEmpty()) { TestCommonHelper.assertError(errors, 0, NullPointerException.class); } } finally { RxJavaCommonPlugins.reset(); } } }
@Test public void otherErrors() { Completable.never() .timeout(1, TimeUnit.MILLISECONDS, Completable.error(new TestException())) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); }
@Test public void andThenSingleNever() { TestObserver<String> ts = new TestObserver<String>(); Completable.never().andThen(Single.just("foo")).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); }
@Test public void andThenNever() { TestObserver<String> ts = new TestObserver<String>(); Completable.never().andThen(Observable.just("foo")).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); }
@Test public void timeoutContinueOther() throws Exception { final int[] call = { 0 }; Completable other = Completable.fromAction(new Action() { @Override public void run() throws Exception { call[0]++; } }); Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); assertEquals(1, call[0]); }