T
- the value typepublic class TestSubscriber<T> extends BaseTestConsumer<T,TestSubscriber<T>> implements FlowableSubscriber<T>, Subscription
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.
checkSubscriptionOnce, completions, done, errors, lastThread, tag, timeout, values
Constructor and Description |
---|
TestSubscriber()
Constructs a non-forwarding
TestSubscriber with an initial request value of Long.MAX_VALUE . |
TestSubscriber(long initialRequest)
Constructs a non-forwarding
TestSubscriber with the specified initial request value. |
TestSubscriber(@NonNull Subscriber<? super T> downstream)
Constructs a forwarding
TestSubscriber but leaves the requesting to the wrapped Subscriber . |
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. |
Modifier and Type | Method and Description |
---|---|
protected TestSubscriber<T> |
assertSubscribed()
Assert that the
onSubscribe(Subscription) method was called exactly once. |
void |
cancel() |
static <T> @NonNull TestSubscriber<T> |
create()
Creates a
TestSubscriber with Long.MAX_VALUE initial request amount. |
static <T> @NonNull TestSubscriber<T> |
create(long initialRequested)
Creates a
TestSubscriber with the given initial request amount. |
static <T> TestSubscriber<T> |
create(@NonNull Subscriber<? super T> delegate)
Constructs a forwarding
TestSubscriber . |
protected void |
dispose()
Cancel/dispose this test consumer.
|
boolean |
hasSubscription()
|
boolean |
isCancelled()
Returns true if this
TestSubscriber has been cancelled. |
protected boolean |
isDisposed()
Returns true if this test consumer was cancelled/disposed.
|
void |
onComplete() |
void |
onError(@NonNull Throwable t) |
void |
onNext(T t) |
protected void |
onStart()
Called after the onSubscribe is called and handled.
|
void |
onSubscribe(@NonNull Subscription s)
Implementors of this method should make sure everything that needs
to be visible in
Subscriber.onNext(Object) is established before
calling Subscription.request(long) . |
void |
request(long n) |
TestSubscriber<T> |
requestMore(long n)
Calls
request(long) and returns this. |
assertComplete, assertEmpty, assertError, assertError, assertError, assertFailure, assertNoErrors, assertNotComplete, assertNoValues, assertResult, assertValue, assertValue, assertValueAt, assertValueAt, assertValueCount, assertValues, assertValueSequence, assertValuesOnly, await, await, awaitCount, awaitDone, fail, valueAndClass, values, withTag
public TestSubscriber()
TestSubscriber
with an initial request value of Long.MAX_VALUE
.public TestSubscriber(long initialRequest)
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.
initialRequest
- the initial request amountpublic TestSubscriber(@NonNull Subscriber<? super T> downstream)
TestSubscriber
but leaves the requesting to the wrapped Subscriber
.downstream
- the actual Subscriber
to forward events topublic TestSubscriber(@NonNull Subscriber<? super T> actual, long initialRequest)
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.
actual
- the actual Subscriber
to forward events toinitialRequest
- the initial request amount@NonNull public static <T> @NonNull TestSubscriber<T> create()
TestSubscriber
with Long.MAX_VALUE
initial request amount.T
- the value typeTestSubscriber
instance.create(long)
@NonNull public static <T> @NonNull TestSubscriber<T> create(long initialRequested)
TestSubscriber
with the given initial request amount.T
- the value typeinitialRequested
- the initial requested amountTestSubscriber
instance.public static <T> TestSubscriber<T> create(@NonNull Subscriber<? super T> delegate)
TestSubscriber
.T
- the value type receiveddelegate
- the actual Subscriber
to forward events topublic void onSubscribe(@NonNull Subscription s)
FlowableSubscriber
Subscriber.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
.
onSubscribe
in interface FlowableSubscriber<T>
onSubscribe
in interface Subscriber<T>
protected void onStart()
public void onNext(@NonNull T t)
onNext
in interface Subscriber<T>
public void onError(@NonNull Throwable t)
onError
in interface Subscriber<T>
public void onComplete()
onComplete
in interface Subscriber<T>
public final void request(long n)
request
in interface Subscription
public final void cancel()
cancel
in interface Subscription
public final boolean isCancelled()
TestSubscriber
has been cancelled.TestSubscriber
has been cancelledprotected final void dispose()
BaseTestConsumer
dispose
in class BaseTestConsumer<T,TestSubscriber<T>>
protected final boolean isDisposed()
BaseTestConsumer
isDisposed
in class BaseTestConsumer<T,TestSubscriber<T>>
public final boolean hasSubscription()
TestSubscriber
received a Subscription
via onSubscribe(Subscription)
protected final TestSubscriber<T> assertSubscribed()
onSubscribe(Subscription)
method was called exactly once.assertSubscribed
in class BaseTestConsumer<T,TestSubscriber<T>>
public final TestSubscriber<T> requestMore(long n)
request(long)
and returns this.
History: 2.0.1 - experimental
n
- the request amount