Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.subscribers

public Class TestSubscriber<T>

extends BaseTestConsumer<T, TestSubscriber<T>>
implements FlowableSubscriber<T>, Subscription
Class Inheritance
All Implemented Interfaces
org.reactivestreams.Subscription, io.reactivex.rxjava3.core.FlowableSubscriber, org.reactivestreams.Subscriber
Type Parameters
<T>
the value type
Imports
java.util.concurrent.atomic.*, org.reactivestreams.*, io.reactivex.rxjava3.annotations.NonNull, io.reactivex.rxjava3.core.FlowableSubscriber, io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper, io.reactivex.rxjava3.observers.BaseTestConsumer

A Subscriber implementation that records events and allows making assertions about them.

You can override the onSubscribe(Subscription), onNext(Object), onError(Throwable) and onComplete() methods but not the others (this is by design).

When calling the default request method, you are requesting on behalf of the wrapped actual Subscriber if any.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
TestSubscriber.EmptySubscriber

A subscriber that ignores all events and does not report errors.

Field Summary

Modifier and TypeField and Description
private volatile boolean
cancelled

Makes sure the incoming Subscriptions get cancelled immediately.

private final Subscriber<? super T>
downstream

The actual subscriber to forward events to.

private final AtomicLong
missedRequested

Holds the requested amount until a subscription arrives.

private final AtomicReference<Subscription>
upstream

Holds the current subscription if any.

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

Constructor Summary

AccessConstructor and Description
public
TestSubscriber()

Constructs a non-forwarding TestSubscriber with an initial request value of Long#MAX_VALUE.

public
TestSubscriber(long
the initial request amount
initialRequest
)

Constructs a non-forwarding TestSubscriber with the specified initial request value.

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

Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped Subscriber.

public
TestSubscriber(@NonNull Subscriber<? super T>
the actual Subscriber to forward events to
actual
,
long
the initial request amount
initialRequest
)

Constructs a forwarding TestSubscriber with the specified initial request amount and an actual Subscriber to forward events to.

Method Summary

Modifier and TypeMethod and Description
protected final TestSubscriber<T>

Returns:

this
assertSubscribed
()

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

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

Implements org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.
public static <
the value type
T
>
@NonNull TestSubscriber<T>

Returns:

the new TestSubscriber instance.
create
()

Creates a TestSubscriber with Long#MAX_VALUE initial request amount.

public static <
the value type
T
>
@NonNull TestSubscriber<T>

Returns:

the new TestSubscriber instance.
create
(long
the initial requested amount
initialRequested
)

Creates a TestSubscriber with the given initial request amount.

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

Returns:

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

Constructs a forwarding TestSubscriber.

protected final void
dispose()

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

Cancel/dispose this test consumer.
public final boolean

Returns:

true if this TestSubscriber received a Subscription via onSubscribe(Subscription)
hasSubscription
()

Returns true if this TestSubscriber received a Subscription via onSubscribe(Subscription).

public final boolean

Returns:

true if this TestSubscriber has been cancelled
isCancelled
()

Returns true if this TestSubscriber has been cancelled.

protected final boolean
isDisposed()

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

Returns true if this test consumer was cancelled/disposed.
public void
onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Successful terminal state.
public void
onError(@NonNull Throwable
the throwable signaled
t
)

Implements org.reactivestreams.Subscriber.onError.

Failed terminal state.
public void
onNext(T
the element signaled
t
)

Implements org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).
protected void
onStart()

Called after the onSubscribe is called and handled.

public void
public final void
request(long
the strictly positive number of elements to requests to the upstream Publisher
n
)

Implements org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.
public final TestSubscriber<T>

Returns:

this
requestMore
(long
the request amount
n
)

Calls request(long) and returns this.

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

Field Detail

cancelledback to summary
private volatile boolean cancelled

Makes sure the incoming Subscriptions get cancelled immediately.

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

The actual subscriber to forward events to.

missedRequestedback to summary
private final AtomicLong missedRequested

Holds the requested amount until a subscription arrives.

upstreamback to summary
private final AtomicReference<Subscription> upstream

Holds the current subscription if any.

Constructor Detail

TestSubscriberback to summary
public TestSubscriber()

Constructs a non-forwarding TestSubscriber with an initial request value of Long#MAX_VALUE.

TestSubscriberback to summary
public TestSubscriber(long initialRequest)

Constructs a non-forwarding TestSubscriber with the specified initial request value.

The TestSubscriber doesn't validate the initialRequest amount so one can test sources with invalid values as well.

Parameters
initialRequest:long

the initial request amount

TestSubscriberback to summary
public TestSubscriber(@NonNull Subscriber<? super T> downstream)

Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped Subscriber.

Parameters
downstream:@NonNull Subscriber<? super T>

the actual Subscriber to forward events to

TestSubscriberback to summary
public TestSubscriber(@NonNull Subscriber<? super T> actual, long initialRequest)

Constructs a forwarding TestSubscriber with the specified initial request amount and an actual Subscriber to forward events to.

The TestSubscriber doesn't validate the initialRequest value so one can test sources with invalid values as well.

Parameters
actual:@NonNull Subscriber<? super T>

the actual Subscriber to forward events to

initialRequest:long

the initial request amount

Method Detail

assertSubscribedback to summary
protected final TestSubscriber<T> assertSubscribed()

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

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

Returns:TestSubscriber<T>

this

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

Implements org.reactivestreams.Subscription.cancel.

Doc from org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.

Data may still be sent to meet previously signalled demand after calling cancel.

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

Creates a TestSubscriber with Long#MAX_VALUE initial request amount.

Parameters
<T>
the value type
Returns:@NonNull TestSubscriber<T>

the new TestSubscriber instance.

Annotations
@NonNull
See Also
create(long)
createback to summary
public static <T> @NonNull TestSubscriber<T> create(long initialRequested)

Creates a TestSubscriber with the given initial request amount.

Parameters
<T>
the value type
initialRequested:long

the initial requested amount

Returns:@NonNull TestSubscriber<T>

the new TestSubscriber instance.

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

Constructs a forwarding TestSubscriber.

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

the actual Subscriber to forward events to

Returns:TestSubscriber<T>

the new TestObserver instance

disposeback to summary
protected final void dispose()

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

Doc from io.reactivex.rxjava3.observers.BaseTestConsumer.dispose.

Cancel/dispose this test consumer.

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

Returns true if this TestSubscriber received a Subscription via onSubscribe(Subscription).

Returns:boolean

true if this TestSubscriber received a Subscription via onSubscribe(Subscription)

isCancelledback to summary
public final boolean isCancelled()

Returns true if this TestSubscriber has been cancelled.

Returns:boolean

true if this TestSubscriber has been cancelled

isDisposedback to summary
protected final boolean isDisposed()

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

Doc from io.reactivex.rxjava3.observers.BaseTestConsumer.isDisposed.

Returns true if this test consumer was cancelled/disposed.

Returns:boolean

true if this test consumer was cancelled/disposed.

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Doc from org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

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

Implements org.reactivestreams.Subscriber.onError.

Doc from org.reactivestreams.Subscriber.onError.

Failed terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Parameters
t:@NonNull Throwable

the throwable signaled

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

Implements org.reactivestreams.Subscriber.onNext.

Doc from org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

Parameters
t:T

the element signaled

Annotations
@Override
onStartback to summary
protected void onStart()

Called after the onSubscribe is called and handled.

onSubscribeback to summary
public void onSubscribe(@NonNull Subscription s)

Implements org.reactivestreams.Subscriber.onSubscribe.

Doc from org.reactivestreams.Subscriber.onSubscribe.

Invoked after calling Publisher#subscribe(Subscriber).

No data will start flowing until Subscription#request(long) is invoked.

It is the responsibility of this Subscriber instance to call Subscription#request(long) whenever more data is wanted.

The Publisher will send notifications only in response to Subscription#request(long).

Parameters
s:@NonNull Subscription

the Subscription that allows requesting data via Subscription#request(long)

Annotations
@Override
requestback to summary
public final void request(long n)

Implements org.reactivestreams.Subscription.request.

Doc from org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.

It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more, it may be treated by the Publisher as "effectively unbounded".

Whatever has been requested can be sent by the Publisher so only signal demand for what can be safely handled.

A Publisher can send less than is requested if the stream ends but then must emit either Subscriber#onError(Throwable) or Subscriber#onComplete().

Parameters
n:long

the strictly positive number of elements to requests to the upstream Publisher

Annotations
@Override
requestMoreback to summary
public final TestSubscriber<T> requestMore(long n)

Calls request(long) and returns this.

History: 2.0.1 - experimental

Parameters
n:long

the request amount

Returns:TestSubscriber<T>

this

Since
2.1
io.reactivex.rxjava3.subscribers back to summary

pack-priv final Enum TestSubscriber.EmptySubscriber

extends Enum<TestSubscriber.EmptySubscriber>
implements FlowableSubscriber<Object>
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.core.FlowableSubscriber, org.reactivestreams.Subscriber

A subscriber that ignores all events and does not report errors.

Field Summary

Modifier and TypeField and Description
public static final TestSubscriber.EmptySubscriber

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Successful terminal state.
public void
onError(Throwable
the throwable signaled
t
)

Implements org.reactivestreams.Subscriber.onError.

Failed terminal state.
public void
onNext(Object
the element signaled
t
)

Implements org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).
public void
public static TestSubscriber.EmptySubscriber
public static TestSubscriber.EmptySubscriber[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INSTANCEback to summary
public static final TestSubscriber.EmptySubscriber INSTANCE

Constructor Detail

EmptySubscriberback to summary
private EmptySubscriber()

Method Detail

onCompleteback to summary
public void onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Doc from org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

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

Implements org.reactivestreams.Subscriber.onError.

Doc from org.reactivestreams.Subscriber.onError.

Failed terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Parameters
t:Throwable

the throwable signaled

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

Implements org.reactivestreams.Subscriber.onNext.

Doc from org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

Parameters
t:Object

the element signaled

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Subscription s)

Implements org.reactivestreams.Subscriber.onSubscribe.

Doc from org.reactivestreams.Subscriber.onSubscribe.

Invoked after calling Publisher#subscribe(Subscriber).

No data will start flowing until Subscription#request(long) is invoked.

It is the responsibility of this Subscriber instance to call Subscription#request(long) whenever more data is wanted.

The Publisher will send notifications only in response to Subscription#request(long).

Parameters
s:Subscription

the Subscription that allows requesting data via Subscription#request(long)

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