@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);
}