T - the value typepublic class TestSubscriber<T> extends java.lang.Object implements org.reactivestreams.Subscriber<T>, org.reactivestreams.Subscription, Disposable
You can override the onSubscribe, onNext, onError, onComplete, request and cancel methods but not the others (this is by desing).
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.
| Constructor and Description |
|---|
TestSubscriber()
Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE.
|
TestSubscriber(java.lang.Long initialRequest)
Constructs a non-forwarding TestSubscriber with the specified initial request value.
|
TestSubscriber(org.reactivestreams.Subscriber<? super T> actual)
Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber.
|
TestSubscriber(org.reactivestreams.Subscriber<? super T> actual,
java.lang.Long initialRequest)
Constructs a forwarding TestSubscriber with the specified initial request value.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assertComplete()
Assert that this TestSubscriber received exactly one onComplete event.
|
void |
assertError(java.lang.Class<? extends java.lang.Throwable> errorClass)
Asserts that this TestSubscriber received exactly one onError event which is an
instance of the specified errorClass class.
|
void |
assertError(java.lang.Throwable error)
Assert that this TestSubscriber received exactly the specified onError event value.
|
void |
assertErrorMessage(java.lang.String message) |
void |
assertNoErrors()
Assert that this TestSubscriber has not received any onError event.
|
void |
assertNotComplete()
Assert that this TestSubscriber has not received any onComplete event.
|
void |
assertNotSubscribed()
Assert that the onSubscribe method hasn't been called at all.
|
void |
assertNotTerminated()
Assert that the TestSubscriber has not terminated (i.e., the terminal latch is still non-zero).
|
void |
assertNoValues()
Assert that this TestSubscriber has not received any onNext events.
|
void |
assertSubscribed()
Assert that the onSubscribe method was called exactly once.
|
void |
assertTerminated()
Assert that the TestSubscriber terminated (i.e., the terminal latch reached zero).
|
void |
assertValue(T value)
Assert that this TestSubscriber received exactly one onNext value which is equal to
the given value with respect to Objects.equals.
|
void |
assertValueCount(int count)
Assert that this TestSubscriber received the specified number onNext events.
|
void |
assertValues(T... values)
Assert that the TestSubscriber received only the specified values in the specified order.
|
void |
assertValueSequence(java.lang.Iterable<? extends T> sequence)
Assert that the TestSubscriber received only the specified sequence of values in the same order.
|
void |
assertValueSet(java.util.Collection<? extends T> values)
Assert that the TestSubscriber received only the specified values in any order.
|
void |
await()
Awaits until this TestSubscriber receives an onError or onComplete events.
|
boolean |
await(long time,
java.util.concurrent.TimeUnit unit)
Awaits the specified amount of time or until this TestSubscriber
receives an onError or onComplete events, whichever happens first.
|
boolean |
awaitTerminalEvent()
Waits until the any terminal event has been received by this TestSubscriber
or returns false if the wait has been interrupted.
|
boolean |
awaitTerminalEvent(long duration,
java.util.concurrent.TimeUnit unit)
Awaits the specified amount of time or until this TestSubscriber
receives an onError or onComplete events, whichever happens first.
|
void |
cancel() |
long |
completions()
Returns the number of times onComplete was called.
|
void |
dispose()
Dispose the resource, the operation should be idempotent.
|
int |
errorCount()
Returns the number of onError exceptions received.
|
java.util.List<java.lang.Throwable> |
errors()
Returns a shared list of received onError exceptions.
|
java.util.List<java.util.List<java.lang.Object>> |
getEvents()
Returns a list of 3 other lists: the first inner list contains the plain
values received; the second list contains the potential errors
and the final list contains the potential completions as Notifications.
|
boolean |
hasSubscription()
Returns true if this TestSubscriber received a subscription.
|
boolean |
isCancelled()
Returns true if this TestSubscriber has been cancelled.
|
boolean |
isTerminated()
Returns true if TestSubscriber received any onError or onComplete events.
|
java.lang.Thread |
lastThread()
Returns the last thread which called the onXXX methods of this TestSubscriber.
|
void |
onComplete() |
void |
onError(java.lang.Throwable t) |
void |
onNext(T t) |
void |
onSubscribe(org.reactivestreams.Subscription s) |
void |
request(long n) |
int |
valueCount()
Returns the number of onNext values received.
|
java.util.List<T> |
values()
Returns a shared list of received onNext values.
|
public TestSubscriber()
public TestSubscriber(java.lang.Long initialRequest)
The TestSubscriber doesn't validate the initialRequest value so one can test sources with invalid values as well.
initialRequest - the initial request value if not nullpublic TestSubscriber(org.reactivestreams.Subscriber<? super T> actual)
actual - the actual Subscriber to forward events topublic TestSubscriber(org.reactivestreams.Subscriber<? super T> actual, java.lang.Long initialRequest)
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 value if not nullpublic void onSubscribe(org.reactivestreams.Subscription s)
onSubscribe in interface org.reactivestreams.Subscriber<T>public void onError(java.lang.Throwable t)
onError in interface org.reactivestreams.Subscriber<T>public void onComplete()
onComplete in interface org.reactivestreams.Subscriber<T>public void request(long n)
request in interface org.reactivestreams.Subscriptionpublic void cancel()
cancel in interface org.reactivestreams.Subscriptionpublic final boolean isCancelled()
public final void dispose()
Disposabledispose in interface Disposablepublic final java.lang.Thread lastThread()
public final java.util.List<T> values()
public final java.util.List<java.lang.Throwable> errors()
public final long completions()
public final boolean isTerminated()
public final int valueCount()
public final int errorCount()
public final boolean hasSubscription()
public final void await()
throws java.lang.InterruptedException
java.lang.InterruptedException - if the current thread is interrupted while waitingawaitTerminalEvent()public final boolean await(long time,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
time - the waiting timeunit - the time unit of the waiting timejava.lang.InterruptedException - if the current thread is interrupted while waitingawaitTerminalEvent(long, TimeUnit)public void assertComplete()
public void assertNotComplete()
public void assertNoErrors()
public void assertError(java.lang.Throwable error)
The comparison is performed via Objects.equals(); since most exceptions don't
implement equals(), this assertion may fail. Use the assertError(Class)
overload to test against the class of an error instead of an instance of an error.
error - the error to checkassertError(Class)public void assertError(java.lang.Class<? extends java.lang.Throwable> errorClass)
errorClass - the error class to expectpublic final void assertValue(T value)
value - the value to expectpublic final void assertValueCount(int count)
count - the expected number of onNext eventspublic final void assertNoValues()
public final void assertValues(T... values)
values - the values expectedassertValueSet(Collection)public final void assertValueSet(java.util.Collection<? extends T> values)
This helps asserting when the order of the values is not guaranteed, i.e., when merging asynchronous streams.
values - the collection of values expected in any orderpublic final void assertValueSequence(java.lang.Iterable<? extends T> sequence)
sequence - the sequence of expected values in orderpublic final void assertTerminated()
public final void assertNotTerminated()
public final void assertSubscribed()
public final void assertNotSubscribed()
public boolean awaitTerminalEvent()
public boolean awaitTerminalEvent(long duration,
java.util.concurrent.TimeUnit unit)
duration - the waiting timeunit - the time unit of the waiting timepublic void assertErrorMessage(java.lang.String message)
public java.util.List<java.util.List<java.lang.Object>> getEvents()