Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.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.rxjava3.core.CompletableObserver, io.reactivex.rxjava3.core.SingleObserver, io.reactivex.rxjava3.core.MaybeObserver, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.core.Observer
Type Parameters
<T>
the value type
Imports
java.util.concurrent.atomic.AtomicReference, io.reactivex.rxjava3.annotations.NonNull, io.reactivex.rxjava3.core.*, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.internal.disposables.DisposableHelper

An 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.

See Also
io.reactivex.rxjava3.subscribers.TestSubscriber

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 final AtomicReference<Disposable>
upstream

Holds the current subscription if any.

Inherited from io.reactivex.rxjava3.observers.BaseTestConsumer:
checkSubscriptionOncecompletionsdoneerrorslastThreadtagtimeoutvalues

Constructor Summary

AccessConstructor and Description
public
TestObserver()

Constructs a non-forwarding TestObserver.

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

Constructs a forwarding TestObserver.

Method Summary

Modifier and TypeMethod and Description
protected final @NonNull TestObserver<T>

Returns:

this
assertSubscribed
()

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

Assert that the onSubscribe(Disposable) method was called exactly once.
public static <
the value type received
T
>
@NonNull TestObserver<T>

Returns:

the new TestObserver instance
create
()

Constructs a non-forwarding TestObserver.

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

Returns:

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

Constructs a forwarding TestObserver.

public final void
dispose()

Implements abstract io.reactivex.rxjava3.observers.BaseTestConsumer.dispose.

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public final boolean

Returns:

true if this TestObserver received a subscription
hasSubscription
()

Returns true if this TestObserver received a subscription.

public final boolean
isDisposed()

Implements abstract io.reactivex.rxjava3.observers.BaseTestConsumer.isDisposed.

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public void
public void
public void
onNext(T
the item emitted by the Observable
t
)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Provides the Observer with a new item to observe.
public void
public void
onSuccess(T
the item emitted by the Maybe
value
)

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

Notifies the MaybeObserver with one item and that the Maybe has finished sending push-based notifications.
Inherited from io.reactivex.rxjava3.observers.BaseTestConsumer:
assertCompleteassertEmptyassertErrorassertErrorassertErrorassertFailureassertNoErrorsassertNotCompleteassertNoValuesassertResultassertValueassertValueassertValueAtassertValueAtassertValueCountassertValuesassertValueSequenceassertValuesOnlyawaitawaitawaitCountawaitDonefailvalueAndClassvalueswithTag

Field Detail

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

The actual observer to forward events to.

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(@NonNull Observer<? super T> downstream)

Constructs a forwarding TestObserver.

Parameters
downstream:@NonNull Observer<? super T>

the actual Observer to forward events to

Method Detail

assertSubscribedback to summary
protected final @NonNull TestObserver<T> assertSubscribed()

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

Assert that the onSubscribe(Disposable) method was called exactly once.

Returns:@NonNull TestObserver<T>

this

Annotations
@Override
@NonNull
createback to summary
public static <T> @NonNull TestObserver<T> create()

Constructs a non-forwarding TestObserver.

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

the new TestObserver instance

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

Constructs a forwarding TestObserver.

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

the actual Observer to forward events to

Returns:@NonNull TestObserver<T>

the new TestObserver instance

Annotations
@NonNull
disposeback to summary
public final void dispose()

Implements abstract io.reactivex.rxjava3.observers.BaseTestConsumer.dispose.

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

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

Dispose the resource, the operation should be idempotent.

Annotations
@Override
hasSubscriptionback to summary
public final boolean hasSubscription()

Returns true if this TestObserver received a subscription.

Returns:boolean

true if this TestObserver received a subscription

isDisposedback to summary
public final boolean isDisposed()

Implements abstract io.reactivex.rxjava3.observers.BaseTestConsumer.isDisposed.

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.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.rxjava3.core.Observer.onComplete, io.reactivex.rxjava3.core.MaybeObserver.onComplete, io.reactivex.rxjava3.core.CompletableObserver.onComplete.

Doc from io.reactivex.rxjava3.core.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(@NonNull Throwable t)
Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Doc from io.reactivex.rxjava3.core.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(@NonNull Disposable d)
Annotations
@Override
onSuccessback to summary
public void onSuccess(T value)

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

Doc from io.reactivex.rxjava3.core.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
io.reactivex.rxjava3.observers back to summary

pack-priv final Enum TestObserver.EmptyObserver

extends Enum<TestObserver.EmptyObserver>
implements Observer<Object>
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.core.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.rxjava3.core.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
public void
onNext(Object
the item emitted by the Observable
t
)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Provides the Observer with a new item to observe.
public void
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.rxjava3.core.Observer.onComplete.

Doc from io.reactivex.rxjava3.core.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)
Annotations
@Override
onNextback to summary
public void onNext(Object t)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Doc from io.reactivex.rxjava3.core.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)
Annotations
@Override
valueOfback to summary
public static TestObserver.EmptyObserver valueOf(String name)
valuesback to summary
public static TestObserver.EmptyObserver[] values()