BehaviorSubject extends Subject<T> { @CheckReturnValue @NonNull public static <T> BehaviorSubject<T> create() { return new BehaviorSubject<T>(); } @SuppressWarnings("unchecked")  BehaviorSubject();   BehaviorSubject(T defaultValue); @CheckReturnValue @NonNull static BehaviorSubject<T> create(); @CheckReturnValue @NonNull static BehaviorSubject<T> createDefault(T defaultValue); @Override void onSubscribe(Disposable s); @Override void onNext(T t); @Override void onError(Throwable t); @Override void onComplete(); @Override boolean hasObservers(); @Override @Nullable Throwable getThrowable(); @Nullable T getValue(); Object[] getValues(); @SuppressWarnings("unchecked") T[] getValues(T[] array); @Override boolean hasComplete(); @Override boolean hasThrowable(); boolean hasValue();  }
@Test public void addRemoveRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final BehaviorSubject<Object> p = BehaviorSubject.create(); final TestObserver<Object> to = p.test(); Runnable r1 = new Runnable() { @Override public void run() { p.test(); } }; Runnable r2 = new Runnable() { @Override public void run() { to.cancel(); } }; TestHelper.race(r1, r2); } }
@Test public void innerDisposed() { BehaviorSubject.create() .subscribe(new Observer<Object>() { @Override public void onSubscribe(Disposable d) { assertFalse(d.isDisposed()); d.dispose(); assertTrue(d.isDisposed()); } @Override public void onNext(Object value) { } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); }