Top Description Inners Fields Constructors Methods
io.reactivex.observers

public Class TestObserver<T>

extends BaseTestConsumer<T, TestObserver<T>>
implements Observer<T>, Disposable, MaybeObserver<T>, SingleObserver<T>, CompletableObserver
Class Inheritance
All Implemented Interfaces
io.reactivex.CompletableObserver, io.reactivex.SingleObserver, io.reactivex.MaybeObserver, io.reactivex.disposables.Disposable, io.reactivex.Observer
Type Parameters
<T>
the value type
Imports
java.util.concurrent.atomic.AtomicReference, io.reactivex.*, io.reactivex.disposables.Disposable, io.reactivex.functions.Consumer, io.reactivex.internal.disposables.DisposableHelper, io.reactivex.internal.fuseable.*, io.reactivex.internal.util.ExceptionHelper

An Observer that records events and allows making assertions about them.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
TestObserver.EmptyObserver

An observer that ignores all events and does not report errors.

Field Summary

Modifier and TypeField and Description
private final Observer<? super T>
downstream

The actual observer to forward events to.

private QueueDisposable<T>
private final AtomicReference<Disposable>
upstream

Holds the current subscription if any.

Inherited from io.reactivex.observers.BaseTestConsumer:
checkSubscriptionOncecompletionsdoneerrorsestablishedFusionModeinitialFusionModelastThreadtagtimeoutvalues

Constructor Summary

AccessConstructor and Description
public
TestObserver()

Constructs a non-forwarding TestObserver.

public
TestObserver(Observer<? super T>
the actual Observer to forward events to
downstream
)

Constructs a forwarding TestObserver.

Method Summary

Modifier and TypeMethod and Description
pack-priv final TestObserver<T>

Returns:

this
assertFuseable
()

Assert that the upstream is a fuseable source.

pack-priv final TestObserver<T>

Returns:

this
assertFusionMode
(int
the expected mode
mode
)

Asserts that the given fusion mode has been established

Package-private: avoid leaking the now internal fusion properties into the public API.

pack-priv final TestObserver<T>

Returns:

this
assertNotFuseable
()

Assert that the upstream is not a fuseable source.

public final TestObserver<T>

Returns:

this;
assertNotSubscribed
()

Implements abstract io.reactivex.observers.BaseTestConsumer.assertNotSubscribed.

Assert that the onSubscribe method hasn't been called at all.
public final TestObserver<T>

Returns:

this
assertOf
(Consumer<? super TestObserver<T>>
the check consumer to run
check
)

Run a check consumer with this TestObserver instance.

public final TestObserver<T>

Returns:

this;
assertSubscribed
()

Implements abstract io.reactivex.observers.BaseTestConsumer.assertSubscribed.

Assert that the onSubscribe method was called exactly once.
public final void
cancel()

Cancels the TestObserver (before or after the subscription happened).

public static <
the value type received
T
>
TestObserver<T>

Returns:

the new TestObserver instance
create
()

Constructs a non-forwarding TestObserver.

public static <
the value type received
T
>
TestObserver<T>

Returns:

the new TestObserver instance
create
(Observer<? super T>
the actual Observer to forward events to
delegate
)

Constructs a forwarding TestObserver.

public final void
dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
pack-priv static String
public final boolean

Returns:

true if this TestObserver received a subscription
hasSubscription
()

Returns true if this TestObserver received a subscription.

public final boolean

Returns:

true if this TestObserver has been cancelled
isCancelled
()

Returns true if this TestObserver has been cancelled.

public final boolean
isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public void
onComplete()

Implements io.reactivex.Observer.onComplete, io.reactivex.MaybeObserver.onComplete, io.reactivex.CompletableObserver.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
t
)

Implements io.reactivex.Observer.onError, io.reactivex.MaybeObserver.onError, io.reactivex.SingleObserver.onError, io.reactivex.CompletableObserver.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
t
)

Implements io.reactivex.Observer.onNext.

Provides the Observer with a new item to observe.
public void
onSubscribe(Disposable
the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection
d
)

Implements io.reactivex.Observer.onSubscribe, io.reactivex.MaybeObserver.onSubscribe, io.reactivex.SingleObserver.onSubscribe, io.reactivex.CompletableObserver.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.
public void
onSuccess(T
the item emitted by the Maybe
value
)

Implements io.reactivex.MaybeObserver.onSuccess, io.reactivex.SingleObserver.onSuccess.

Notifies the MaybeObserver with one item and that the Maybe has finished sending push-based notifications.
pack-priv final TestObserver<T>

Returns:

this
setInitialFusionMode
(int
the mode to establish, see the QueueDisposable constants
mode
)

Sets the initial fusion mode if the upstream supports fusion.

Inherited from io.reactivex.observers.BaseTestConsumer:
assertCompleteassertEmptyassertErrorassertErrorassertErrorassertErrorMessageassertFailureassertFailureassertFailureAndMessageassertNeverassertNeverassertNoErrorsassertNotCompleteassertNoTimeoutassertNotTerminatedassertNoValuesassertResultassertTerminatedassertTimeoutassertValueassertValueassertValueAtassertValueAtassertValueCountassertValuesassertValueSequenceassertValueSequenceOnlyassertValueSetassertValueSetOnlyassertValuesOnlyawaitawaitawaitCountawaitCountawaitCountawaitDoneawaitTerminalEventawaitTerminalEventclearTimeoutcompletionserrorCounterrorsfailgetEventsisTerminatedisTimeoutlastThreadvalueAndClassvalueCountvalueswithTag

Field Detail

downstreamback to summary
private final Observer<? super T> downstream

The actual observer to forward events to.

qdback to summary
private QueueDisposable<T> qd
upstreamback to summary
private final AtomicReference<Disposable> upstream

Holds the current subscription if any.

Constructor Detail

TestObserverback to summary
public TestObserver()

Constructs a non-forwarding TestObserver.

TestObserverback to summary
public TestObserver(Observer<? super T> downstream)

Constructs a forwarding TestObserver.

Parameters
downstream:Observer<? super T>

the actual Observer to forward events to

Method Detail

assertFuseableback to summary
pack-priv final TestObserver<T> assertFuseable()

Assert that the upstream is a fuseable source.

Package-private: avoid leaking the now internal fusion properties into the public API. Use ObserverFusion to work with such tests.

Returns:TestObserver<T>

this

assertFusionModeback to summary
pack-priv final TestObserver<T> assertFusionMode(int mode)

Asserts that the given fusion mode has been established

Package-private: avoid leaking the now internal fusion properties into the public API. Use ObserverFusion to work with such tests.

Parameters
mode:int

the expected mode

Returns:TestObserver<T>

this

assertNotFuseableback to summary
pack-priv final TestObserver<T> assertNotFuseable()

Assert that the upstream is not a fuseable source.

Package-private: avoid leaking the now internal fusion properties into the public API. Use ObserverFusion to work with such tests.

Returns:TestObserver<T>

this

assertNotSubscribedback to summary
public final TestObserver<T> assertNotSubscribed()

Implements abstract io.reactivex.observers.BaseTestConsumer.assertNotSubscribed.

Assert that the onSubscribe method hasn't been called at all.

Returns:TestObserver<T>

this;

Annotations
@Override
assertOfback to summary
public final TestObserver<T> assertOf(Consumer<? super TestObserver<T>> check)

Run a check consumer with this TestObserver instance.

Parameters
check:Consumer<? super TestObserver<T>>

the check consumer to run

Returns:TestObserver<T>

this

assertSubscribedback to summary
public final TestObserver<T> assertSubscribed()

Implements abstract io.reactivex.observers.BaseTestConsumer.assertSubscribed.

Assert that the onSubscribe method was called exactly once.

Returns:TestObserver<T>

this;

Annotations
@Override
cancelback to summary
public final void cancel()

Cancels the TestObserver (before or after the subscription happened).

This operation is thread-safe.

This method is provided as a convenience when converting Flowable tests that cancel.

createback to summary
public static <T> TestObserver<T> create()

Constructs a non-forwarding TestObserver.

Parameters
<T>
the value type received
Returns:TestObserver<T>

the new TestObserver instance

createback to summary
public static <T> TestObserver<T> create(Observer<? super T> delegate)

Constructs a forwarding TestObserver.

Parameters
<T>
the value type received
delegate:Observer<? super T>

the actual Observer to forward events to

Returns:TestObserver<T>

the new TestObserver instance

disposeback to summary
public final void dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Doc from io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
fusionModeToStringback to summary
pack-priv static String fusionModeToString(int mode)
hasSubscriptionback to summary
public final boolean hasSubscription()

Returns true if this TestObserver received a subscription.

Returns:boolean

true if this TestObserver received a subscription

isCancelledback to summary
public final boolean isCancelled()

Returns true if this TestObserver has been cancelled.

Returns:boolean

true if this TestObserver has been cancelled

isDisposedback to summary
public final boolean isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Doc from io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements io.reactivex.Observer.onComplete, io.reactivex.MaybeObserver.onComplete, io.reactivex.CompletableObserver.onComplete.

Doc from io.reactivex.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(Throwable t)

Implements io.reactivex.Observer.onError, io.reactivex.MaybeObserver.onError, io.reactivex.SingleObserver.onError, io.reactivex.CompletableObserver.onError.

Doc from io.reactivex.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onComplete.

Parameters
t:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements io.reactivex.Observer.onNext.

Doc from io.reactivex.Observer.onNext.

Provides the 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 onComplete or onError.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Disposable d)

Implements io.reactivex.Observer.onSubscribe, io.reactivex.MaybeObserver.onSubscribe, io.reactivex.SingleObserver.onSubscribe, io.reactivex.CompletableObserver.onSubscribe.

Doc from io.reactivex.Observer.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.

Parameters
d:Disposable

the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection

Annotations
@SuppressWarnings:unchecked
@Override
onSuccessback to summary
public void onSuccess(T value)

Implements io.reactivex.MaybeObserver.onSuccess, io.reactivex.SingleObserver.onSuccess.

Doc from io.reactivex.MaybeObserver.onSuccess.

Notifies the MaybeObserver with one item and that the Maybe has finished sending push-based notifications.

The Maybe will not call this method if it calls onError.

Parameters
value:T

the item emitted by the Maybe

Annotations
@Override
setInitialFusionModeback to summary
pack-priv final TestObserver<T> setInitialFusionMode(int mode)

Sets the initial fusion mode if the upstream supports fusion.

Package-private: avoid leaking the now internal fusion properties into the public API. Use ObserverFusion to work with such tests.

Parameters
mode:int

the mode to establish, see the QueueDisposable constants

Returns:TestObserver<T>

this

io.reactivex.observers back to summary

pack-priv final Enum TestObserver.EmptyObserver

extends Enum<TestObserver.EmptyObserver>
implements Observer<Object>
Class Inheritance
All Implemented Interfaces
io.reactivex.Observer

An observer that ignores all events and does not report errors.

Field Summary

Modifier and TypeField and Description
public static final TestObserver.EmptyObserver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onComplete()

Implements io.reactivex.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
t
)

Implements io.reactivex.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(Object
the item emitted by the Observable
t
)

Implements io.reactivex.Observer.onNext.

Provides the Observer with a new item to observe.
public void
onSubscribe(Disposable
the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection
d
)

Implements io.reactivex.Observer.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.
public static TestObserver.EmptyObserver
public static TestObserver.EmptyObserver[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INSTANCEback to summary
public static final TestObserver.EmptyObserver INSTANCE

Constructor Detail

EmptyObserverback to summary
private EmptyObserver()

Method Detail

onCompleteback to summary
public void onComplete()

Implements io.reactivex.Observer.onComplete.

Doc from io.reactivex.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(Throwable t)

Implements io.reactivex.Observer.onError.

Doc from io.reactivex.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onComplete.

Parameters
t:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(Object t)

Implements io.reactivex.Observer.onNext.

Doc from io.reactivex.Observer.onNext.

Provides the 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 onComplete or onError.

Parameters
t:Object

the item emitted by the Observable

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Disposable d)

Implements io.reactivex.Observer.onSubscribe.

Doc from io.reactivex.Observer.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.

Parameters
d:Disposable

the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection

Annotations
@Override
valueOfback to summary
public static TestObserver.EmptyObserver valueOf(String name)
valuesback to summary
public static TestObserver.EmptyObserver[] values()