PublishSubject extends Subject<T> { @CheckReturnValue @NonNull public static <T> PublishSubject<T> create() { return new PublishSubject<T>(); } @SuppressWarnings("unchecked")  PublishSubject(); @CheckReturnValue @NonNull static PublishSubject<T> create(); @Override void subscribeActual(Observer<? super T> t); @Override void onSubscribe(Disposable s); @Override void onNext(T t); @SuppressWarnings("unchecked") @Override void onError(Throwable t); @SuppressWarnings("unchecked") @Override void onComplete(); @Override boolean hasObservers(); @Override @Nullable Throwable getThrowable(); @Override boolean hasThrowable(); @Override boolean hasComplete();  }
@Test public void addRemoveRance() throws Exception { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final PublishSubject<Integer> ps = PublishSubject.create(); final TestObserver<Integer> to = ps.test(); Runnable r1 = new Runnable() { @Override public void run() { ps.subscribe(); } }; Runnable r2 = new Runnable() { @Override public void run() { to.cancel(); } }; TestHelper.race(r1, r2); } }