/** * Run a check consumer with this TestSubscriber instance. * @param check the check consumer to run * @return this */ public final TestSubscriber<T> assertOf(Consumer<? super TestSubscriber<T>> check) { try { check.accept(this); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } return this; }
/** * Atomically adds a Throwable to this container (combining with a previous Throwable is necessary). * @param t the throwable to add * @return true if successful, false if the container has been terminated */ public boolean addThrowable(Throwable t) { return ExceptionHelper.addThrowable(this, t); }
/** * Atomically terminate the container and return the contents of the last * non-terminal Throwable of it. * @return the last Throwable */ public Throwable terminate() { return ExceptionHelper.terminate(this); }
ExceptionHelper.addThrowable(error, ex); ex = ExceptionHelper.terminate(error);
@Test(expected = InternalError.class) public void throwIfThrowable() throws Exception { ExceptionHelper.<Exception>throwIfThrowable(new InternalError()); } }
@Test public void delayErrors() { PublishProcessor<Publisher<Integer>> source = PublishProcessor.create(); TestSubscriber<Integer> ts = source.switchMapDelayError(Functions.<Publisher<Integer>>identity()) .test(); ts.assertNoValues() .assertNoErrors() .assertNotComplete(); source.onNext(Flowable.just(1)); source.onNext(Flowable.<Integer>error(new TestException("Forced failure 1"))); source.onNext(Flowable.just(2, 3, 4)); source.onNext(Flowable.<Integer>error(new TestException("Forced failure 2"))); source.onNext(Flowable.just(5)); source.onError(new TestException("Forced failure 3")); ts.assertValues(1, 2, 3, 4, 5) .assertNotComplete() .assertError(CompositeException.class); List<Throwable> errors = ExceptionHelper.flatten(ts.errors().get(0)); TestCommonHelper.assertError(errors, 0, TestException.class, "Forced failure 1"); TestCommonHelper.assertError(errors, 1, TestException.class, "Forced failure 2"); TestCommonHelper.assertError(errors, 2, TestException.class, "Forced failure 3"); }
throw new CompositeException(ex, exc); throw ExceptionHelper.<Exception>throwIfThrowable(ex); throw new CompositeException(ex, exc); throw ExceptionHelper.<Exception>throwIfThrowable(ex);
@Test public void delayErrors() { PublishSubject<ObservableSource<Integer>> source = PublishSubject.create(); TestObserver<Integer> ts = source.switchMapDelayError(Functions.<ObservableSource<Integer>>identity()) .test(); ts.assertNoValues() .assertNoErrors() .assertNotComplete(); source.onNext(Observable.just(1)); source.onNext(Observable.<Integer>error(new TestException("Forced failure 1"))); source.onNext(Observable.just(2, 3, 4)); source.onNext(Observable.<Integer>error(new TestException("Forced failure 2"))); source.onNext(Observable.just(5)); source.onError(new TestException("Forced failure 3")); ts.assertValues(1, 2, 3, 4, 5) .assertNotComplete() .assertError(CompositeException.class); List<Throwable> errors = ExceptionHelper.flatten(ts.errors().get(0)); TestCommonHelper.assertError(errors, 0, TestException.class, "Forced failure 1"); TestCommonHelper.assertError(errors, 1, TestException.class, "Forced failure 2"); TestCommonHelper.assertError(errors, 2, TestException.class, "Forced failure 3"); }
/** * Run a check consumer with this TestObserver instance. * @param check the check consumer to run * @return this */ public final TestObserver<T> assertOf(Consumer<? super TestObserver<T>> check) { try { check.accept(this); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } return this; }
/** * Atomically adds a Throwable to this container (combining with a previous Throwable is necessary). * @param t the throwable to add * @return true if successful, false if the container has been terminated */ public boolean addThrowable(Throwable t) { return ExceptionHelper.addThrowable(this, t); }
/** * Atomically terminate the container and return the contents of the last * non-terminal Throwable of it. * @return the last Throwable */ public Throwable terminate() { return ExceptionHelper.terminate(this); }
throw new CompositeException(ex, exc); throw ExceptionHelper.<Exception>throwIfThrowable(ex); throw new CompositeException(ex, exc); throw ExceptionHelper.<Exception>throwIfThrowable(ex);
/** * Run a check consumer with this TestObserver instance. * @param check the check consumer to run * @return this */ public final TestObserver<T> assertOf(Consumer<? super TestObserver<T>> check) { try { check.accept(this); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } return this; }
/** * Atomically adds a Throwable to this container (combining with a previous Throwable is necessary). * @param t the throwable to add * @return true if successful, false if the container has been terminated */ public boolean addThrowable(Throwable t) { return ExceptionHelper.addThrowable(this, t); }
/** * Atomically terminate the container and return the contents of the last * non-terminal Throwable of it. * @return the last Throwable */ public Throwable terminate() { return ExceptionHelper.terminate(this); }
@Override public T next() { if (error != null) { // If any error has already been thrown, throw it again. throw ExceptionHelper.wrapOrThrow(error); } if (hasNext()) { isNextConsumed = true; return next; } else { throw new NoSuchElementException("No more elements"); } }
@Override public void innerError(Throwable ex) { if (ExceptionHelper.addThrowable(error, ex)) { active.decrementAndGet(); drain(); } else { RxJavaCommonPlugins.onError(ex); } }
void errorAll(Subscriber<?> a) { Throwable ex = ExceptionHelper.terminate(error); lefts.clear(); rights.clear(); a.onError(ex); }
@Override public T next() { if (error != null) { // If any error has already been thrown, throw it again. throw ExceptionHelper.wrapOrThrow(error); } if (hasNext()) { isNextConsumed = true; return next; } else { throw new NoSuchElementException("No more elements"); } }
@Override public void innerError(Throwable ex) { if (ExceptionHelper.addThrowable(error, ex)) { active.decrementAndGet(); drain(); } else { RxJavaCommonPlugins.onError(ex); } }