java.lang.Object | ||
↳ | io.reactivex.observers.BaseTestConsumer<T, U extends io.reactivex.observers.BaseTestConsumer<T, U>> | |
↳ | io.reactivex.subscribers.TestSubscriber<T> |
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.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
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(Subscriber<? super T> actual)
Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber.
| |||||||||||
TestSubscriber(Subscriber<? super T> actual, long initialRequest)
Constructs a forwarding TestSubscriber with the specified initial request value.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
final TestSubscriber<T> |
assertNotSubscribed()
Assert that the onSubscribe method hasn't been called at all.
| ||||||||||
final TestSubscriber<T> |
assertOf(Consumer<? super TestSubscriber<T>> check)
Run a check consumer with this TestSubscriber instance.
| ||||||||||
final TestSubscriber<T> |
assertSubscribed()
Assert that the onSubscribe method was called exactly once.
| ||||||||||
final void | cancel() | ||||||||||
static <T> TestSubscriber<T> |
create(long initialRequested)
Creates a TestSubscriber with the given initial request.
| ||||||||||
static <T> TestSubscriber<T> |
create()
Creates a TestSubscriber with Long.MAX_VALUE initial request.
| ||||||||||
static <T> TestSubscriber<T> |
create(Subscriber<? super T> delegate)
Constructs a forwarding TestSubscriber.
| ||||||||||
final void |
dispose()
Dispose the resource, the operation should be idempotent.
| ||||||||||
final boolean |
hasSubscription()
Returns true if this TestSubscriber received a subscription.
| ||||||||||
final boolean |
isCancelled()
Returns true if this TestSubscriber has been cancelled.
| ||||||||||
final boolean |
isDisposed()
Returns true if this resource has been disposed.
| ||||||||||
void | onComplete() | ||||||||||
void | onError(Throwable t) | ||||||||||
void | onNext(T t) | ||||||||||
void |
onSubscribe(Subscription s)
Implementors of this method should make sure everything that needs
to be visible in
onNext(Object) is established before
calling request(long) . | ||||||||||
final void | request(long n) | ||||||||||
final TestSubscriber<T> |
requestMore(long n)
Calls
request(long) and returns this. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
onStart()
Called after the onSubscribe is called and handled.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE.
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.
initialRequest | the initial request value |
---|
Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber.
actual | the actual Subscriber to forward events to |
---|
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.
actual | the actual Subscriber to forward events to |
---|---|
initialRequest | the initial request value |
Assert that the onSubscribe method hasn't been called at all.
Run a check consumer with this TestSubscriber instance.
check | the check consumer to run |
---|
Assert that the onSubscribe method was called exactly once.
Creates a TestSubscriber with the given initial request.
initialRequested | the initial requested amount |
---|
Creates a TestSubscriber with Long.MAX_VALUE initial request.
Constructs a forwarding TestSubscriber.
delegate | the actual Subscriber to forward events to |
---|
Dispose the resource, the operation should be idempotent.
Returns true if this TestSubscriber received a subscription.
Returns true if this TestSubscriber has been cancelled.
Returns true if this resource has been disposed.
Implementors of this method should make sure everything that needs
to be visible in onNext(Object)
is established before
calling request(long)
. In practice this means
no initialization should happen after the request()
call and
additional behavior is thread safe in respect to onNext
.
Calls request(long)
and returns this.
History: 2.0.1 - experimental
n | the request amount |
---|
Called after the onSubscribe is called and handled.