MaybeSubject extends Maybe<T> implements MaybeObserver<T> { @CheckReturnValue @NonNull public static <T> MaybeSubject<T> create() { return new MaybeSubject<T>(); } @SuppressWarnings("unchecked")  MaybeSubject(); @CheckReturnValue @NonNull static MaybeSubject<T> create(); @Override void onSubscribe(Disposable d); @SuppressWarnings("unchecked") @Override void onSuccess(T value); @SuppressWarnings("unchecked") @Override void onError(Throwable e); @SuppressWarnings("unchecked") @Override void onComplete(); @Nullable T getValue(); boolean hasValue(); @Nullable Throwable getThrowable(); boolean hasThrowable(); boolean hasComplete(); boolean hasObservers();  }
@Test public void cancelOnArrival() { MaybeSubject.create() .test(true) .assertEmpty(); }
@Test public void cancelOnArrival2() { MaybeSubject<Integer> ms = MaybeSubject.create(); ms.test(); ms .test(true) .assertEmpty(); }
@Test public void dispose() { TestHelper.checkDisposed(MaybeSubject.create()); }
@Test public void disposeTwice() { MaybeSubject.create() .subscribe(new MaybeObserver<Object>() { @Override public void onSubscribe(Disposable d) { assertFalse(d.isDisposed()); d.dispose(); d.dispose(); assertTrue(d.isDisposed()); } @Override public void onSuccess(Object value) { } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); }
@Test public void addRemoveRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final MaybeSubject<Integer> ms = MaybeSubject.create(); final TestObserver<Integer> to = ms.test(); Runnable r1 = new Runnable() { @Override public void run() { ms.test(); } }; Runnable r2 = new Runnable() { @Override public void run() { to.cancel(); } }; TestHelper.race(r1, r2); } }