java.lang.Object | |
↳ | io.reactivex.observers.BaseTestConsumer<T, U extends io.reactivex.observers.BaseTestConsumer<T, U>> |
![]()
TestObserver<T>,
TestSubscriber<T>
|
Base class with shared infrastructure to support TestSubscriber and TestObserver.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
enum | BaseTestConsumer.TestWaitStrategy | Enumeration of default wait strategies when waiting for a specific number of
items in awaitCount(int, Runnable) . |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
protected boolean | checkSubscriptionOnce | ||||||||||
protected long | completions | The number of completions. | |||||||||
protected final CountDownLatch | done | The latch that indicates an onError or onComplete has been called. | |||||||||
protected final List<Throwable> | errors | The list of errors received. | |||||||||
protected int | establishedFusionMode | ||||||||||
protected int | initialFusionMode | ||||||||||
protected Thread | lastThread | The last thread seen by the observer. | |||||||||
protected CharSequence | tag | The optional tag associated with this test consumer. | |||||||||
protected boolean | timeout | Indicates that one of the awaitX method has timed out. | |||||||||
protected final List<T> | values | The list of values received. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BaseTestConsumer() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
final U |
assertComplete()
Assert that this TestObserver/TestSubscriber received exactly one onComplete event.
| ||||||||||
final U |
assertEmpty()
Assert that the TestObserver/TestSubscriber has received a Disposable but no other events.
| ||||||||||
final U |
assertError(Throwable error)
Assert that this TestObserver/TestSubscriber received exactly the specified onError event value.
| ||||||||||
final U |
assertError(Class<? extends Throwable> errorClass)
Asserts that this TestObserver/TestSubscriber received exactly one onError event which is an
instance of the specified errorClass class.
| ||||||||||
final U |
assertError(Predicate<Throwable> errorPredicate)
Asserts that this TestObserver/TestSubscriber received exactly one onError event for which
the provided predicate returns true.
| ||||||||||
final U |
assertErrorMessage(String message)
Assert that there is a single error and it has the given message.
| ||||||||||
final U |
assertFailure(Predicate<Throwable> errorPredicate, T... values)
Assert that the upstream signalled the specified values in order and then failed
with a Throwable for which the provided predicate returns true.
| ||||||||||
final U |
assertFailure(Class<? extends Throwable> error, T... values)
Assert that the upstream signalled the specified values in order
and then failed with a specific class or subclass of Throwable.
| ||||||||||
final U |
assertFailureAndMessage(Class<? extends Throwable> error, String message, T... values)
Assert that the upstream signalled the specified values in order,
then failed with a specific class or subclass of Throwable
and with the given exact error message.
| ||||||||||
final U |
assertNever(Predicate<? super T> valuePredicate)
Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which
the provided predicate returns true.
| ||||||||||
final U |
assertNever(T value)
Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to
the given value with respect to Objects.equals.
| ||||||||||
final U |
assertNoErrors()
Assert that this TestObserver/TestSubscriber has not received any onError event.
| ||||||||||
final U |
assertNoTimeout()
Asserts that some awaitX method has not timed out.
| ||||||||||
final U |
assertNoValues()
Assert that this TestObserver/TestSubscriber has not received any onNext events.
| ||||||||||
final U |
assertNotComplete()
Assert that this TestObserver/TestSubscriber has not received any onComplete event.
| ||||||||||
abstract U |
assertNotSubscribed()
Assert that the onSubscribe method hasn't been called at all.
| ||||||||||
final U |
assertNotTerminated()
Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero).
| ||||||||||
final U |
assertResult(T... values)
Assert that the upstream signalled the specified values in order and
completed normally.
| ||||||||||
abstract U |
assertSubscribed()
Assert that the onSubscribe method was called exactly once.
| ||||||||||
final U |
assertTerminated()
Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero).
| ||||||||||
final U |
assertTimeout()
Asserts that some awaitX method has timed out.
| ||||||||||
final U |
assertValue(Predicate<T> valuePredicate)
Asserts that this TestObserver/TestSubscriber received exactly one onNext value for which
the provided predicate returns true.
| ||||||||||
final U |
assertValue(T value)
Assert that this TestObserver/TestSubscriber received exactly one onNext value which is equal to
the given value with respect to Objects.equals.
| ||||||||||
final U |
assertValueAt(int index, Predicate<T> valuePredicate)
Asserts that this TestObserver/TestSubscriber received an onNext value at the given index
for the provided predicate returns true.
| ||||||||||
final U |
assertValueCount(int count)
Assert that this TestObserver/TestSubscriber received the specified number onNext events.
| ||||||||||
final U |
assertValueSequence(Iterable<? extends T> sequence)
Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order.
| ||||||||||
final U |
assertValueSet(Collection<? extends T> expected)
Assert that the TestObserver/TestSubscriber received only the specified values in any order.
| ||||||||||
final U |
assertValues(T... values)
Assert that the TestObserver/TestSubscriber received only the specified values in the specified order.
| ||||||||||
final U |
await()
Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events.
| ||||||||||
final boolean |
await(long time, TimeUnit unit)
Awaits the specified amount of time or until this TestObserver/TestSubscriber
receives an onError or onComplete events, whichever happens first.
| ||||||||||
final U |
awaitCount(int atLeast, Runnable waitStrategy)
Await until the TestObserver/TestSubscriber receives the given
number of items or terminates by waiting according to the wait
strategy and up to 5000 milliseconds of timeout.
| ||||||||||
final U |
awaitCount(int atLeast, Runnable waitStrategy, long timeoutMillis)
Await until the TestObserver/TestSubscriber receives the given
number of items or terminates.
| ||||||||||
final U |
awaitCount(int atLeast)
Await until the TestObserver/TestSubscriber receives the given
number of items or terminates by sleeping 10 milliseconds at a time
up to 5000 milliseconds of timeout.
| ||||||||||
final U |
awaitDone(long time, TimeUnit unit)
Awaits until the internal latch is counted down.
| ||||||||||
final boolean |
awaitTerminalEvent(long duration, TimeUnit unit)
Awaits the specified amount of time or until this TestObserver/TestSubscriber
receives an onError or onComplete events, whichever happens first.
| ||||||||||
final boolean |
awaitTerminalEvent()
Waits until the any terminal event has been received by this TestObserver/TestSubscriber
or returns false if the wait has been interrupted.
| ||||||||||
final U |
clearTimeout()
Clears the timeout flag set by the await methods when they timed out.
| ||||||||||
final long |
completions()
Returns the number of times onComplete was called.
| ||||||||||
final int |
errorCount()
Returns the number of onError exceptions received.
| ||||||||||
final List<Throwable> |
errors()
Returns a shared list of received onError exceptions.
| ||||||||||
final List<List<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.
| ||||||||||
final boolean |
isTerminated()
Returns true if TestObserver/TestSubscriber received any onError or onComplete events.
| ||||||||||
final boolean | isTimeout() | ||||||||||
final Thread |
lastThread()
Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber.
| ||||||||||
static String |
valueAndClass(Object o)
Appends the class name to a non-null value.
| ||||||||||
final int |
valueCount()
Returns the number of onNext values received.
| ||||||||||
final List<T> |
values()
Returns a shared list of received onNext values.
| ||||||||||
final U |
withTag(CharSequence tag)
Set the tag displayed along with an assertion failure's
other state information.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
final AssertionError |
fail(String message)
Fail with the given message and add the sequence of errors as suppressed ones.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
The number of completions.
The latch that indicates an onError or onComplete has been called.
Indicates that one of the awaitX method has timed out.
Assert that this TestObserver/TestSubscriber received exactly one onComplete event.
Assert that the TestObserver/TestSubscriber has received a Disposable but no other events.
Assert that this TestObserver/TestSubscriber received exactly the specified onError event value.
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
or assertError(Predicate)
to test with different condition.
error | the error to check |
---|
Asserts that this TestObserver/TestSubscriber received exactly one onError event which is an instance of the specified errorClass class.
errorClass | the error class to expect |
---|
Asserts that this TestObserver/TestSubscriber received exactly one onError event for which the provided predicate returns true.
errorPredicate | the predicate that receives the error Throwable and should return true for expected errors. |
---|
Assert that there is a single error and it has the given message.
message | the message expected |
---|
Assert that the upstream signalled the specified values in order and then failed with a Throwable for which the provided predicate returns true.
errorPredicate | the predicate that receives the error Throwable and should return true for expected errors. |
---|---|
values | the expected values, asserted in order |
Assert that the upstream signalled the specified values in order and then failed with a specific class or subclass of Throwable.
error | the expected exception (parent) class |
---|---|
values | the expected values, asserted in order |
Assert that the upstream signalled the specified values in order, then failed with a specific class or subclass of Throwable and with the given exact error message.
error | the expected exception (parent) class |
---|---|
message | the expected failure message |
values | the expected values, asserted in order |
Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which the provided predicate returns true.
History: 2.0.5 - experimental
valuePredicate | the predicate that receives the onNext value and should return true for the expected value. |
---|
Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to the given value with respect to Objects.equals.
History: 2.0.5 - experimental
value | the value to expect not being received |
---|
Assert that this TestObserver/TestSubscriber has not received any onError event.
Asserts that some awaitX method has not timed out.
History: 2.0.7 - experimental
Assert that this TestObserver/TestSubscriber has not received any onNext events.
Assert that this TestObserver/TestSubscriber has not received any onComplete event.
Assert that the onSubscribe method hasn't been called at all.
Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero).
Assert that the upstream signalled the specified values in order and completed normally.
values | the expected values, asserted in order |
---|
Assert that the onSubscribe method was called exactly once.
Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero).
Asserts that some awaitX method has timed out.
History: 2.0.7 - experimental
Asserts that this TestObserver/TestSubscriber received exactly one onNext value for which the provided predicate returns true.
valuePredicate | the predicate that receives the onNext value and should return true for the expected value. |
---|
Assert that this TestObserver/TestSubscriber received exactly one onNext value which is equal to the given value with respect to Objects.equals.
value | the value to expect |
---|
Asserts that this TestObserver/TestSubscriber received an onNext value at the given index for the provided predicate returns true.
index | the position to assert on |
---|---|
valuePredicate | the predicate that receives the onNext value and should return true for the expected value. |
Assert that this TestObserver/TestSubscriber received the specified number onNext events.
count | the expected number of onNext events |
---|
Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order.
sequence | the sequence of expected values in order |
---|
Assert that the TestObserver/TestSubscriber received only the specified values in any order.
This helps asserting when the order of the values is not guaranteed, i.e., when merging asynchronous streams.
expected | the collection of values expected in any order |
---|
Assert that the TestObserver/TestSubscriber received only the specified values in the specified order.
values | the values expected |
---|
Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events.
InterruptedException | if the current thread is interrupted while waiting |
---|
Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.
time | the waiting time |
---|---|
unit | the time unit of the waiting time |
InterruptedException | if the current thread is interrupted while waiting |
---|
Await until the TestObserver/TestSubscriber receives the given number of items or terminates by waiting according to the wait strategy and up to 5000 milliseconds of timeout.
History: 2.0.7 - experimental
atLeast | the number of items expected at least |
---|---|
waitStrategy | a Runnable called when the current received count
hasn't reached the expected value and there was
no terminal event either, see BaseTestConsumer.TestWaitStrategy
for examples |
Await until the TestObserver/TestSubscriber receives the given number of items or terminates.
History: 2.0.7 - experimental
atLeast | the number of items expected at least |
---|---|
waitStrategy | a Runnable called when the current received count
hasn't reached the expected value and there was
no terminal event either, see BaseTestConsumer.TestWaitStrategy
for examples |
timeoutMillis | if positive, the await ends if the specified amount of time has passed no matter how many items were received |
Await until the TestObserver/TestSubscriber receives the given number of items or terminates by sleeping 10 milliseconds at a time up to 5000 milliseconds of timeout.
History: 2.0.7 - experimental
atLeast | the number of items expected at least |
---|
Awaits until the internal latch is counted down.
If the wait times out or gets interrupted, the TestObserver/TestSubscriber is cancelled.
time | the waiting time |
---|---|
unit | the time unit of the waiting time |
RuntimeException | wrapping an InterruptedException if the wait is interrupted |
---|
Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.
duration | the waiting time |
---|---|
unit | the time unit of the waiting time |
Waits until the any terminal event has been received by this TestObserver/TestSubscriber or returns false if the wait has been interrupted.
Clears the timeout flag set by the await methods when they timed out.
History: 2.0.7 - experimental
Returns the number of times onComplete was called.
Returns the number of onError exceptions received.
Returns a shared list of received onError exceptions.
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.
Returns true if TestObserver/TestSubscriber received any onError or onComplete events.
History: 2.0.7 - experimental
Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber.
Appends the class name to a non-null value.
o | the object |
---|
Returns the number of onNext values received.
Returns a shared list of received onNext values.
Set the tag displayed along with an assertion failure's other state information.
History: 2.0.7 - experimental
tag | the string to display (null won't print any tag) |
---|
Fail with the given message and add the sequence of errors as suppressed ones.
Note this is deliberately the only fail method. Most of the times an assertion would fail but it is possible it was due to an exception somewhere. This construct will capture those potential errors and report it along with the original failure.
message | the message to use |
---|