T
- the value typepublic class TestObserver<T> extends BaseTestConsumer<T,TestObserver<T>> implements Observer<T>, Disposable, MaybeObserver<T>, SingleObserver<T>, CompletableObserver
You can override the onSubscribe, onNext, onError, onComplete, onSuccess and cancel methods but not the others (this is by design).
The TestObserver implements Disposable for convenience where dispose calls cancel.
checkSubscriptionOnce, completions, done, errors, lastThread, tag, timeout, values
Constructor and Description |
---|
TestObserver()
Constructs a non-forwarding TestObserver.
|
TestObserver(Observer<? super T> downstream)
Constructs a forwarding TestObserver.
|
Modifier and Type | Method and Description |
---|---|
protected TestObserver<T> |
assertSubscribed()
Assert that the onSubscribe method was called exactly once.
|
static <T> TestObserver<T> |
create()
Constructs a non-forwarding TestObserver.
|
static <T> TestObserver<T> |
create(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(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(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
public static <T> TestObserver<T> create()
T
- the value type receivedpublic static <T> TestObserver<T> create(Observer<? super T> delegate)
T
- the value type receiveddelegate
- the actual Observer to forward events topublic void onSubscribe(Disposable d)
Observer
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(T t)
Observer
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(Throwable t)
Observer
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
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()
protected final TestObserver<T> assertSubscribed()
assertSubscribed
in class BaseTestConsumer<T,TestObserver<T>>
public void onSuccess(T value)
MaybeObserver
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