LambdaObserver extends AtomicReference<Disposable> implements Observer<T>, Disposable, LambdaConsumerIntrospection { @Override public void onNext(T t) { if (!isDisposed()) { try { onNext.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); get().dispose(); onError(e); } } } LambdaObserver(Consumer<? super T> onNext, Consumer<? super Throwable> onError,
            Action onComplete,
            Consumer<? super Disposable> onSubscribe); @Override void onSubscribe(Disposable s); @Override void onNext(T t); @Override void onError(Throwable t); @Override void onComplete(); @Override void dispose(); @Override boolean isDisposed(); @Override boolean hasCustomOnError();  }
@Test public void onNextThrowsCancelsUpstream() { PublishSubject<Integer> ps = PublishSubject.create(); final List<Throwable> errors = new ArrayList<Throwable>(); ps.subscribe(new Consumer<Integer>() { @Override public void accept(Integer v) throws Exception { throw new TestException(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable e) throws Exception { errors.add(e); } }); assertTrue("No observers?!", ps.hasObservers()); assertTrue("Has errors already?!", errors.isEmpty()); ps.onNext(1); assertFalse("Has observers?!", ps.hasObservers()); assertFalse("No errors?!", errors.isEmpty()); assertTrue(errors.toString(), errors.get(0) instanceof TestException); }