T
- the value type consumed by this Observerpublic interface AssertableSubscriber<T> extends Observer<T>, Subscription
test()
method of a reactive base class.
This interface is not intended to be implemented outside of RxJava.
This interface extends Observer
and allows injecting onXXX signals into
the testing process.
History: 1.2.3 - experimental
Modifier and Type | Method and Description |
---|---|
AssertableSubscriber<T> |
assertCompleted()
Assert that this Observer received exaclty one
onCompleted signal. |
AssertableSubscriber<T> |
assertError(java.lang.Class<? extends java.lang.Throwable> clazz)
Assert that this Observer received one
onError signal with
the given subclass of a Throwable as type. |
AssertableSubscriber<T> |
assertError(java.lang.Throwable throwable)
Assert that this Observer received one
onError signal with the
object-equals of the given Throwable instance |
AssertableSubscriber<T> |
assertFailure(java.lang.Class<? extends java.lang.Throwable> errorClass,
T... values)
Assert that this Observer received the specified items in the given order followed
by an error signal of the given type (but no completion signal).
|
AssertableSubscriber<T> |
assertFailureAndMessage(java.lang.Class<? extends java.lang.Throwable> errorClass,
java.lang.String message,
T... values)
Assert that this Observer received the specified items in the given order followed
by an error signal of the given type and with the exact error message (but no completion signal).
|
AssertableSubscriber<T> |
assertNoErrors()
Assert that this Observer has not received any
onError signal. |
AssertableSubscriber<T> |
assertNotCompleted()
Assert that this Observer received no
onCompleted signal. |
AssertableSubscriber<T> |
assertNoTerminalEvent()
Assert that no
onError or onCompleted signals were received so far. |
AssertableSubscriber<T> |
assertNoValues()
Assert that no
onNext signals were received so far. |
AssertableSubscriber<T> |
assertReceivedOnNext(java.util.List<T> items)
Assert that this Observer received the given list of items as
onNext signals
in the same order and with the default null-safe object equals comparison. |
AssertableSubscriber<T> |
assertResult(T... values)
Assert that this Observer received the specified items in the given order followed
by a completion signal and no errors.
|
AssertableSubscriber<T> |
assertTerminalEvent()
Assert that this Observer received either an
onError or onCompleted signal. |
AssertableSubscriber<T> |
assertUnsubscribed()
Assert that this Observer has been unsubscribed via
unsubscribe() or by a wrapping
SafeSubscriber . |
AssertableSubscriber<T> |
assertValue(T value)
Assert that this Observer received exactly the given single expected value
(compared via null-safe object equals).
|
AssertableSubscriber<T> |
assertValueCount(int count)
Assert that this Observer received exactly the given count of
onNext signals. |
AssertableSubscriber<T> |
assertValues(T... values)
Assert that this Observer received exactly the given expected values
(compared via null-safe object equals) in the given order.
|
AssertableSubscriber<T> |
assertValuesAndClear(T expectedFirstValue,
T... expectedRestValues)
Assert that this Observer received exactly the given values (compared via
null-safe object equals) and if so, clears the internal buffer of the
underlying Subscriber of these values.
|
AssertableSubscriber<T> |
awaitTerminalEvent()
Waits for an
onError or {code onCompleted} terminal event indefinitely. |
AssertableSubscriber<T> |
awaitTerminalEvent(long timeout,
java.util.concurrent.TimeUnit unit)
Waits for an
onError or {code onCompleted} terminal event for the given
amount of timeout. |
AssertableSubscriber<T> |
awaitTerminalEventAndUnsubscribeOnTimeout(long timeout,
java.util.concurrent.TimeUnit unit)
Waits for an
onError or {code onCompleted} terminal event for the given
amount of timeout and unsubscribes the sequence if the timeout passed or the
wait itself is interrupted. |
AssertableSubscriber<T> |
awaitValueCount(int expected,
long timeout,
java.util.concurrent.TimeUnit unit)
Assert that this Observer receives at least the given number of
onNext
signals within the specified timeout period. |
int |
getCompletions()
Returns the number of
onCompleted signals received by this Observer. |
java.lang.Thread |
getLastSeenThread()
Returns the Thread that has called the last
onNext , onError or
onCompleted methods of this Observer. |
java.util.List<java.lang.Throwable> |
getOnErrorEvents()
Returns a list of received
onError signals. |
java.util.List<T> |
getOnNextEvents()
Returns the list of received
onNext events. |
int |
getValueCount()
Returns the number of
onNext signals received by this Observer in
a thread-safe manner; one can read up to this number of elements from
the List returned by getOnNextEvents() . |
boolean |
isUnsubscribed()
Indicates whether this
Subscription is currently unsubscribed. |
void |
onStart()
Allows manually calling the
onStart method of the underlying Subscriber. |
AssertableSubscriber<T> |
perform(Action0 action)
Performs an action given by the Action0 callback in a fluent manner.
|
AssertableSubscriber<T> |
requestMore(long n)
Requests the specified amount of items from upstream.
|
void |
setProducer(Producer p)
Allows manually calling the
setProducer method of the underlying Subscriber. |
void |
unsubscribe()
Stops the receipt of notifications on the
Subscriber that was registered when this Subscription
was received. |
onCompleted, onError, onNext
void onStart()
onStart
method of the underlying Subscriber.void setProducer(Producer p)
setProducer
method of the underlying Subscriber.p
- the producer to use, not nullint getCompletions()
onCompleted
signals received by this Observer.onCompleted
signals receivedjava.util.List<java.lang.Throwable> getOnErrorEvents()
onError
signals.int getValueCount()
onNext
signals received by this Observer in
a thread-safe manner; one can read up to this number of elements from
the List
returned by getOnNextEvents()
.onNext
signals received.AssertableSubscriber<T> requestMore(long n)
n
- the amount requested, non-negativejava.util.List<T> getOnNextEvents()
onNext
events.
If the sequence hasn't completed yet and is asynchronous, use the
getValueCount()
method to determine how many elements are safe
to be read from the list returned by this method.
onNext
events.AssertableSubscriber<T> assertReceivedOnNext(java.util.List<T> items)
onNext
signals
in the same order and with the default null-safe object equals comparison.items
- the List of items expectedAssertableSubscriber<T> awaitValueCount(int expected, long timeout, java.util.concurrent.TimeUnit unit)
onNext
signals within the specified timeout period.
Note that it is possible the AssertionError thrown by this method will contain an actual value >= to the expected one in case there is an emission race or unexpected delay on the emitter side. In this case, increase the timeout amount to avoid false positives.
expected
- the expected (at least) number of onNext
signalstimeout
- the timeout to wait to receive the given number of onNext
eventsunit
- the time unitAssertableSubscriber<T> assertTerminalEvent()
onError
or onCompleted
signal.AssertableSubscriber<T> assertUnsubscribed()
unsubscribe()
or by a wrapping
SafeSubscriber
.AssertableSubscriber<T> assertNoErrors()
onError
signal.AssertableSubscriber<T> awaitTerminalEvent()
onError
or {code onCompleted} terminal event indefinitely.AssertableSubscriber<T> awaitTerminalEvent(long timeout, java.util.concurrent.TimeUnit unit)
onError
or {code onCompleted} terminal event for the given
amount of timeout.timeout
- the time to wait for the terminal eventunit
- the time unit of the wait timeAssertableSubscriber<T> awaitTerminalEventAndUnsubscribeOnTimeout(long timeout, java.util.concurrent.TimeUnit unit)
onError
or {code onCompleted} terminal event for the given
amount of timeout and unsubscribes the sequence if the timeout passed or the
wait itself is interrupted.timeout
- the time to wait for the terminal eventunit
- the time unit of the wait timejava.lang.Thread getLastSeenThread()
onNext
, onError
or
onCompleted
methods of this Observer.AssertableSubscriber<T> assertCompleted()
onCompleted
signal.AssertableSubscriber<T> assertNotCompleted()
onCompleted
signal.AssertableSubscriber<T> assertError(java.lang.Class<? extends java.lang.Throwable> clazz)
onError
signal with
the given subclass of a Throwable as type.clazz
- the expected type of the onError
signal receivedAssertableSubscriber<T> assertError(java.lang.Throwable throwable)
onError
signal with the
object-equals of the given Throwable instancethrowable
- the Throwable instance expectedAssertableSubscriber<T> assertNoTerminalEvent()
onError
or onCompleted
signals were received so far.AssertableSubscriber<T> assertNoValues()
onNext
signals were received so far.AssertableSubscriber<T> assertValueCount(int count)
onNext
signals.count
- the expected number of onNext
signalsAssertableSubscriber<T> assertValues(T... values)
values
- the expected valuesAssertableSubscriber<T> assertValue(T value)
value
- the single value expectedAssertableSubscriber<T> assertValuesAndClear(T expectedFirstValue, T... expectedRestValues)
expectedFirstValue
- the first value expectedexpectedRestValues
- the rest of the values expectedAssertableSubscriber<T> perform(Action0 action)
action
- the action to perform, not nullvoid unsubscribe()
Subscription
Subscriber
that was registered when this Subscription
was received.
This allows deregistering an Subscriber
before it has finished receiving all events (i.e. before
onCompleted is called).
unsubscribe
in interface Subscription
boolean isUnsubscribed()
Subscription
Subscription
is currently unsubscribed.isUnsubscribed
in interface Subscription
true
if this Subscription
is currently unsubscribed, false
otherwiseAssertableSubscriber<T> assertResult(T... values)
values
- the values expectedAssertableSubscriber<T> assertFailure(java.lang.Class<? extends java.lang.Throwable> errorClass, T... values)
errorClass
- the expected Throwable subclass typevalues
- the expected valuesAssertableSubscriber<T> assertFailureAndMessage(java.lang.Class<? extends java.lang.Throwable> errorClass, java.lang.String message, T... values)
errorClass
- the expected Throwable subclass typemessage
- the expected error message returned by Throwable.getMessage()
values
- the expected values