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.
BaseTestConsumer.TestWaitStrategy
checkSubscriptionOnce, completions, done, errors, establishedFusionMode, initialFusionMode, 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 |
---|---|
TestObserver<T> |
assertNotSubscribed()
Assert that the onSubscribe method hasn't been called at all.
|
TestObserver<T> |
assertOf(Consumer<? super TestObserver<T>> check)
Run a check consumer with this TestObserver instance.
|
TestObserver<T> |
assertSubscribed()
Assert that the onSubscribe method was called exactly once.
|
void |
cancel()
Cancels the TestObserver (before or after the subscription happened).
|
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()
Dispose the resource, the operation should be idempotent.
|
boolean |
hasSubscription()
Returns true if this TestObserver received a subscription.
|
boolean |
isCancelled()
Returns true if this TestObserver has been cancelled.
|
boolean |
isDisposed()
Returns true if this resource has been 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, assertErrorMessage, assertFailure, assertFailure, assertFailureAndMessage, assertNever, assertNever, assertNoErrors, assertNotComplete, assertNoTimeout, assertNotTerminated, assertNoValues, assertResult, assertTerminated, assertTimeout, assertValue, assertValue, assertValueAt, assertValueAt, assertValueCount, assertValues, assertValueSequence, assertValueSequenceOnly, assertValueSet, assertValueSetOnly, assertValuesOnly, await, await, awaitCount, awaitCount, awaitCount, awaitDone, awaitTerminalEvent, awaitTerminalEvent, clearTimeout, completions, errorCount, errors, fail, getEvents, isTerminated, isTimeout, lastThread, valueAndClass, valueCount, 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 boolean isCancelled()
public final void cancel()
This operation is thread-safe.
This method is provided as a convenience when converting Flowable tests that cancel.
public final void dispose()
Disposable
dispose
in interface Disposable
public final boolean isDisposed()
Disposable
isDisposed
in interface Disposable
public final boolean hasSubscription()
public final TestObserver<T> assertSubscribed()
assertSubscribed
in class BaseTestConsumer<T,TestObserver<T>>
public final TestObserver<T> assertNotSubscribed()
assertNotSubscribed
in class BaseTestConsumer<T,TestObserver<T>>
public final TestObserver<T> assertOf(Consumer<? super TestObserver<T>> check)
check
- the check consumer to runpublic 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