SafeObserver implements Observer<T>, Disposable { @Override public void dispose() { s.dispose(); } SafeObserver(@NonNull Observer<? super T> actual); @Override void onSubscribe(@NonNull Disposable s); @Override void dispose(); @Override boolean isDisposed(); @Override void onNext(@NonNull T t); @Override void onError(@NonNull Throwable t); @Override void onComplete();  }
@Test public void dispose() { TestObserver<Integer> to = new TestObserver<Integer>(); SafeObserver<Integer> so = new SafeObserver<Integer>(to); Disposable d = Disposables.empty(); so.onSubscribe(d); to.dispose(); assertTrue(d.isDisposed()); assertTrue(so.isDisposed()); }