@Override public Completable apply(Completable n) { return n.onErrorComplete(); } });
@Test(expected = NullPointerException.class) public void onErrorCompleteNull() { error.completable.onErrorComplete(null); }
/** * Returns a Completable instance that if this Completable emits an error, it will emit an onComplete * and swallow the throwable. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable onErrorComplete() { return onErrorComplete(Functions.alwaysTrue()); }
/** * Returns a Completable instance that if this Completable emits an error, it will emit an onComplete * and swallow the throwable. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code onErrorComplete} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable onErrorComplete() { return onErrorComplete(Functions.alwaysTrue()); }
@Test(timeout = 5000) public void onErrorComplete() { Completable c = error.completable.onErrorComplete(); c.blockingAwait(); }
@Test(timeout = 5000, expected = TestException.class) public void onErrorCompleteFalse() { Completable c = error.completable.onErrorComplete(new Predicate<Throwable>() { @Override public boolean test(Throwable e) { return e instanceof IllegalStateException; } }); c.blockingAwait(); }
@Test public void onErrorCompleteFunctionThrows() { TestObserver<String> ts = new TestObserver<String>(); error.completable.onErrorComplete(new Predicate<Throwable>() { @Override public boolean test(Throwable t) { throw new TestException("Forced inner failure"); } }).subscribe(ts); ts.assertNoValues(); ts.assertNotComplete(); ts.assertError(CompositeException.class); CompositeException composite = (CompositeException)ts.errors().get(0); List<Throwable> errors = composite.getExceptions(); Assert.assertEquals(2, errors.size()); Assert.assertTrue(errors.get(0).toString(), errors.get(0) instanceof TestException); Assert.assertEquals(errors.get(0).toString(), null, errors.get(0).getMessage()); Assert.assertTrue(errors.get(1).toString(), errors.get(1) instanceof TestException); Assert.assertEquals(errors.get(1).toString(), "Forced inner failure", errors.get(1).getMessage()); }
@Test public void testOnErrorCalledOnScheduler() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Thread> thread = new AtomicReference<Thread>(); Completable.error(new Exception()) .delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread()) .doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { thread.set(Thread.currentThread()); latch.countDown(); } }) .onErrorComplete() .subscribe(); latch.await(); assertNotEquals(Thread.currentThread(), thread.get()); }
@Test public void normalReturn() { Completable.complete() .onErrorComplete() .test() .assertResult(); }