Top Description Inners Fields Constructors Methods
io.reactivex.subscribers

public Class TestSubscriber<T>

extends BaseTestConsumer<T, TestSubscriber<T>>
implements FlowableSubscriber<T>, Subscription, Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.disposables.Disposable, org.reactivestreams.Subscription, io.reactivex.FlowableSubscriber, org.reactivestreams.Subscriber
Type Parameters
<T>
the value type
Imports
java.util.concurrent.atomic.*, org.reactivestreams.*, io.reactivex.FlowableSubscriber, io.reactivex.disposables.Disposable, io.reactivex.functions.Consumer, io.reactivex.internal.fuseable.QueueSubscription, io.reactivex.internal.subscriptions.SubscriptionHelper, io.reactivex.internal.util.ExceptionHelper, io.reactivex.observers.BaseTestConsumer

A subscriber that records events and allows making assertions about them.

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

The TestSubscriber implements Disposable for convenience where dispose calls cancel.

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

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 QueueSubscription<T>
private final AtomicReference<Subscription>
upstream

Holds the current subscription if any.

Inherited from io.reactivex.observers.BaseTestConsumer:
checkSubscriptionOncecompletionsdoneerrorsestablishedFusionModeinitialFusionModelastThreadtagtimeoutvalues

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 value
initialRequest
)

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

public
TestSubscriber(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(Subscriber<? super T>
the actual Subscriber to forward events to
actual
,
long
the initial request value
initialRequest
)

Constructs a forwarding TestSubscriber with the specified initial request value.

Method Summary

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

Returns:

this
assertFuseable
()

Assert that the upstream is a fuseable source.

pack-priv final TestSubscriber<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 TestSubscriber<T>

Returns:

this
assertNotFuseable
()

Assert that the upstream is not a fuseable source.

public final TestSubscriber<T>

Returns:

this
assertNotSubscribed
()

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

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

Returns:

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

Run a check consumer with this TestSubscriber instance.

public final TestSubscriber<T>

Returns:

this
assertSubscribed
()

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

Assert that the onSubscribe 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
>
TestSubscriber<T>

Returns:

the new TestSubscriber instance.
create
()

Creates a TestSubscriber with Long.MAX_VALUE initial request.

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

Returns:

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

Creates a TestSubscriber with the given initial request.

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

Returns:

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

Constructs a forwarding TestSubscriber.

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 TestSubscriber received a subscription
hasSubscription
()

Returns true if this TestSubscriber received a subscription.

public final boolean

Returns:

true if this TestSubscriber has been cancelled
isCancelled
()

Returns true if this TestSubscriber 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 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(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
onSubscribe(Subscription
the Subscription that allows requesting data via Subscription#request(long)
s
)

Implements io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long).
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.

pack-priv final TestSubscriber<T>

Returns:

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

Sets the initial fusion mode if the upstream supports fusion.

Inherited from io.reactivex.observers.BaseTestConsumer:
assertCompleteassertEmptyassertErrorassertErrorassertErrorassertErrorMessageassertFailureassertFailureassertFailureAndMessageassertNeverassertNeverassertNoErrorsassertNotCompleteassertNoTimeoutassertNotTerminatedassertNoValuesassertResultassertTerminatedassertTimeoutassertValueassertValueassertValueAtassertValueAtassertValueCountassertValuesassertValueSequenceassertValueSequenceOnlyassertValueSetassertValueSetOnlyassertValuesOnlyawaitawaitawaitCountawaitCountawaitCountawaitDoneawaitTerminalEventawaitTerminalEventclearTimeoutcompletionserrorCounterrorsfailgetEventsisTerminatedisTimeoutlastThreadvalueAndClassvalueCountvalueswithTag

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.

qsback to summary
private QueueSubscription<T> qs
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 value so one can test sources with invalid values as well.

Parameters
initialRequest:long

the initial request value

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

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

Parameters
downstream:Subscriber<? super T>

the actual Subscriber to forward events to

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

Constructs a forwarding TestSubscriber with the specified initial request value.

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

Parameters
actual:Subscriber<? super T>

the actual Subscriber to forward events to

initialRequest:long

the initial request value

Method Detail

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

Assert that the upstream is a fuseable source.

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

Returns:TestSubscriber<T>

this

assertFusionModeback to summary
pack-priv final TestSubscriber<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 SubscriberFusion to work with such tests.

Parameters
mode:int

the expected mode

Returns:TestSubscriber<T>

this

assertNotFuseableback to summary
pack-priv final TestSubscriber<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 SubscriberFusion to work with such tests.

Returns:TestSubscriber<T>

this

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

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

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

Returns:TestSubscriber<T>

this

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

Run a check consumer with this TestSubscriber instance.

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

the check consumer to run

Returns:TestSubscriber<T>

this

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

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

Assert that the onSubscribe 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> TestSubscriber<T> create()

Creates a TestSubscriber with Long.MAX_VALUE initial request.

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

the new TestSubscriber instance.

createback to summary
public static <T> TestSubscriber<T> create(long initialRequested)

Creates a TestSubscriber with the given initial request.

Parameters
<T>
the value type
initialRequested:long

the initial requested amount

Returns:TestSubscriber<T>

the new TestSubscriber instance.

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

Constructs a forwarding TestSubscriber.

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

the actual Subscriber to forward events to

Returns:TestSubscriber<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 TestSubscriber received a subscription.

Returns:boolean

true if this TestSubscriber received a 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
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 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(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(Subscription s)

Implements io.reactivex.FlowableSubscriber.onSubscribe.

Doc from io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long). In practice this means no initialization should happen after the request() call and additional behavior is thread safe in respect to onNext. 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

Doc from org.reactivestreams.Subscriber.onSubscribe.

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

Annotations
@SuppressWarnings:unchecked
@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
setInitialFusionModeback to summary
pack-priv final TestSubscriber<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 SubscriberFusion to work with such tests.

Parameters
mode:int

the mode to establish, see the QueueSubscription constants

Returns:TestSubscriber<T>

this

io.reactivex.subscribers back to summary

pack-priv final Enum TestSubscriber.EmptySubscriber

extends Enum<TestSubscriber.EmptySubscriber>
implements FlowableSubscriber<Object>
Class Inheritance
All Implemented Interfaces
io.reactivex.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
onSubscribe(Subscription
the Subscription that allows requesting data via Subscription#request(long)
s
)

Implements io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long).
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 io.reactivex.FlowableSubscriber.onSubscribe.

Doc from io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long). In practice this means no initialization should happen after the request() call and additional behavior is thread safe in respect to onNext. 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

Doc from org.reactivestreams.Subscriber.onSubscribe.

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()