T - the value typepublic class TestObserver<T> extends BaseTestConsumer<T,TestObserver<T>> implements Observer<T>, Disposable, MaybeObserver<T>, SingleObserver<T>, CompletableObserver
Observer, MaybeObserver, SingleObserver and
CompletableObserver composite that can record events from
Observables, Maybes, Singles and Completables
and allows making assertions about them.
You can override the onSubscribe(Disposable), onNext(Object), onError(Throwable),
onComplete() and onSuccess(Object) methods but not the others (this is by design).
The TestObserver implements Disposable for convenience where dispose calls cancel.
TestSubscriber checkSubscriptionOnce, completions, done, errors, lastThread, tag, timeout, values | Constructor and Description |
|---|
TestObserver ()
Constructs a non-forwarding TestObserver.
|
TestObserver (@NonNull Observer<? super T> downstream)
Constructs a forwarding
TestObserver. |
| Modifier and Type | Method and Description |
|---|---|
protected @NonNull TestObserver<T> |
assertSubscribed ()
Assert that the
onSubscribe(Disposable) method was called exactly once. |
static <T> @NonNull TestObserver<T> |
create ()
Constructs a non-forwarding
TestObserver. |
static <T> @NonNull TestObserver<T> |
create (@NonNull Observer<? super T> delegate)
Constructs a forwarding
TestObserver. |
void |
dispose ()
Cancel/dispose this test consumer.
|
boolean |
hasSubscription ()
Returns true if this
TestObserver received a subscription. |
boolean |
isDisposed ()
Returns true if this test consumer was cancelled/disposed.
|
void |
onComplete ()
Notifies the
Observer that the Observable has finished sending push-based notifications. |
void |
onError (@NonNull Throwable t)
Notifies the
Observer that the Observable has experienced an error condition. |
void |
onNext (T t)
Provides the
Observer with a new item to observe. |
void |
onSubscribe (@NonNull Disposable d)
Provides the
Observer with the means of cancelling (disposing) the
connection (channel) with the Observable in both
synchronous (from within Observer.onNext(Object)) and asynchronous manner. |
void |
onSuccess (T value)
Notifies the
MaybeObserver with one item and that the Maybe has finished sending
push-based notifications. |
assertComplete, assertEmpty, assertError, assertError, assertError, assertFailure, assertNoErrors, assertNotComplete, assertNoValues, assertResult, assertValue, assertValue, assertValueAt, assertValueAt, assertValueCount, assertValues, assertValueSequence, assertValuesOnly, await, await, awaitCount, awaitDone, fail, valueAndClass, values, withTag clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait disposed, empty, fromAction, fromAutoCloseable, fromFuture, fromFuture, fromRunnable, fromSubscription, toAutoCloseable public TestObserver()
@NonNull public static <T> @NonNull TestObserver<T> create()
TestObserver.T - the value type receivedTestObserver instance@NonNull public static <T> @NonNull TestObserver<T> create(@NonNull Observer<? super T> delegate)
TestObserver.T - the value type receiveddelegate - the actual Observer to forward events toTestObserver instancepublic void onSubscribe(@NonNull Disposable d)
Observer Observer with the means of cancelling (disposing) the
connection (channel) with the Observable in both
synchronous (from within Observer.onNext(Object)) and asynchronous manner.onSubscribe in interface CompletableObserver onSubscribe in interface MaybeObserver<T>onSubscribe in interface Observer<T>onSubscribe in interface SingleObserver<T>d - the Disposable instance whose Disposable.dispose() can
be called anytime to cancel the connectionpublic void onNext(@NonNull T t)
Observer Observer with a new item to observe.
The Observable may call this method 0 or more times.
The Observable will not call this method again after it calls either Observer.onComplete() or
Observer.onError(java.lang.Throwable).
public void onError(@NonNull Throwable t)
Observer Observer that the Observable has experienced an error condition.
If the Observable calls this method, it will not thereafter call Observer.onNext(T) or
Observer.onComplete().
onError in interface CompletableObserver onError in interface MaybeObserver<T>onError in interface Observer<T>onError in interface SingleObserver<T>t - the exception encountered by the Observablepublic void onComplete()
Observer Observer that the Observable has finished sending push-based notifications.
The Observable will not call this method if it calls Observer.onError(java.lang.Throwable).
onComplete in interface CompletableObserver onComplete in interface MaybeObserver<T>onComplete in interface Observer<T>public final void dispose()
BaseTestConsumer dispose in interface Disposable dispose in class BaseTestConsumer<T,TestObserver<T>>public final boolean isDisposed()
BaseTestConsumer isDisposed in interface Disposable isDisposed in class BaseTestConsumer<T,TestObserver<T>>public final boolean hasSubscription()
TestObserver received a subscription.TestObserver received a subscription@NonNull protected final @NonNull TestObserver<T> assertSubscribed()
onSubscribe(Disposable) method was called exactly once.assertSubscribed in class BaseTestConsumer<T,TestObserver<T>>public void onSuccess(@NonNull T value)
MaybeObserver MaybeObserver with one item and that the Maybe has finished sending
push-based notifications.
The Maybe will not call this method if it calls MaybeObserver.onError(java.lang.Throwable).
onSuccess in interface MaybeObserver<T>onSuccess in interface SingleObserver<T>value - the item emitted by the Maybe