@Test(expected = NullPointerException.class) public void unsafeCreateThrowsNPE() { Completable.unsafeCreate(new CompletableSource() { @Override public void subscribe(CompletableObserver s) { throw new NullPointerException(); } }).test(); }
@Test(timeout = 5000) public void ambIterableOneThrows() { Completable.amb(Collections.singleton(error.completable)) .test() .assertError(TestException.class); }
@Test public void fromCallableThrows() { Completable.fromCallable(new Callable<Object>() { @Override public Object call() throws Exception { throw new UnsupportedOperationException(); } }) .test() .assertFailure(UnsupportedOperationException.class); } }
@Test public void ambIterableOrder() { Completable error = Completable.error(new RuntimeException()); Completable.amb(Arrays.asList(Completable.complete(), error)).test().assertComplete(); }
@Test(timeout = 5000) public void ambMultipleOneIsNull() { Completable.ambArray(null, normal.completable) .test() .assertError(NullPointerException.class); }
@Test(timeout = 5000) public void ambIterableIteratorNull() { Completable.amb(new Iterable<Completable>() { @Override public Iterator<Completable> iterator() { return null; } }).test().assertError(NullPointerException.class); }
@Test public void ambFirstDone() { Completable.amb(Arrays.asList(Completable.complete(), Completable.complete())) .test() .assertResult(); }
@Test public void ambArrayOrder() { Completable error = Completable.error(new RuntimeException()); Completable.ambArray(Completable.complete(), error).test().assertComplete(); }
@Test public void complete() { Completable.complete() .hide() .test() .assertResult(); }
@Test public void mapperThrows() { Maybe.just(1) .flatMapCompletable(new Function<Integer, Completable>() { @Override public Completable apply(Integer v) throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); }
@Test public void never() { Completable.never() .hide() .test() .assertNotComplete() .assertNoErrors(); }
@Test public void delayCustomScheduler() { Completable.complete() .delay(100, TimeUnit.MILLISECONDS, Schedulers.trampoline()) .test() .assertResult(); }
@Test public void successAcceptThrows() { Completable.complete().doOnEvent(new Consumer<Throwable>() { @Override public void accept(Throwable e) throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); }
@Test public void normalEmpty() { Completable.complete() .doFinally(this) .test() .assertResult(); assertEquals(1, calls); }
@Test public void normalAsyncFlowableMaxConcurrency() { flatMapCompletable(Flowable.range(1, 1000), new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return ignoreElements(Flowable.range(1, 100).subscribeOn(Schedulers.computation())); } }, false, 3) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); }
@Test public void subscribeAlreadyCancelled() { PublishSubject<Integer> pp = PublishSubject.create(); pp.ignoreElements().test(true); assertFalse(pp.hasObservers()); }
@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 unboundedIn() { Completable.concat(Observable.just(Completable.complete()).hide(), Integer.MAX_VALUE) .test() .assertResult(); }
@Test public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() { final PublishSubject<String> subject = PublishSubject.create(); final TestScheduler scheduler = new TestScheduler(); final TestObserver<Void> observer = subject.ignoreElements() .timeout(100, TimeUnit.MILLISECONDS, scheduler) .test(); assertTrue(subject.hasObservers()); observer.dispose(); assertFalse(subject.hasObservers()); }
@Test public void cancelDelayed() { TestScheduler scheduler = new TestScheduler(); PublishSubject<Integer> ps = PublishSubject.create(); ps.ignoreElements() .unsubscribeOn(scheduler) .test() .cancel(); assertTrue(ps.hasObservers()); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); assertFalse(ps.hasObservers()); }