UnicastSubject extends Subject<T> { @Override public boolean hasObservers() { return actual.get() != null; } UnicastSubject(int capacityHint, boolean delayError);   UnicastSubject(int capacityHint, Runnable onTerminate);   UnicastSubject(int capacityHint, Runnable onTerminate, boolean delayError); @CheckReturnValue @NonNull static UnicastSubject<T> create(); @CheckReturnValue @NonNull static UnicastSubject<T> create(int capacityHint); @CheckReturnValue @NonNull static UnicastSubject<T> create(int capacityHint, Runnable onTerminate); @CheckReturnValue @Experimental @NonNull static UnicastSubject<T> create(int capacityHint, Runnable onTerminate, boolean delayError); @CheckReturnValue @Experimental @NonNull static UnicastSubject<T> create(boolean delayError); @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(); @Override boolean hasThrowable(); @Override boolean hasComplete();  }
@Test public void hasObservers() { UnicastSubject<Integer> us = UnicastSubject.create(); assertFalse(us.hasObservers()); TestObserver<Integer> to = us.test(); assertTrue(us.hasObservers()); to.cancel(); assertFalse(us.hasObservers()); }