public class TestSubscriber<T> extends Subscriber<T>
TestSubscriber is a variety of Subscriber that you can use for unit testing, to perform
assertions, inspect received events, or wrap a mocked Subscriber.| Constructor and Description |
|---|
TestSubscriber() |
TestSubscriber(Observer<T> delegate) |
TestSubscriber(Subscriber<T> delegate) |
| Modifier and Type | Method and Description |
|---|---|
void |
assertNoErrors()
Assert that this
Subscriber has received no onError notifications. |
void |
assertReceivedOnNext(java.util.List<T> items)
Assert that a particular sequence of items was received by this
Subscriber in order. |
void |
assertTerminalEvent()
Assert that a single terminal event occurred, either
onCompleted() or onError(java.lang.Throwable). |
void |
assertUnsubscribed()
Assert that this
Subscriber is unsubscribed. |
void |
awaitTerminalEvent()
Blocks until this
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification). |
void |
awaitTerminalEvent(long timeout,
java.util.concurrent.TimeUnit unit)
Blocks until this
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification), or until a timeout expires. |
void |
awaitTerminalEventAndUnsubscribeOnTimeout(long timeout,
java.util.concurrent.TimeUnit unit)
Blocks until this
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification), or until a timeout expires; if the
Subscriber is interrupted before either of these events take place, this method unsubscribes the
Subscriber from the Observable). |
java.lang.Thread |
getLastSeenThread()
Returns the last thread that was in use when an item or notification was received by this
Subscriber. |
java.util.List<Notification<T>> |
getOnCompletedEvents()
Get the
Notifications representing each time this Subscriber was notified of sequence
completion via onCompleted(), as a List. |
java.util.List<java.lang.Throwable> |
getOnErrorEvents()
|
java.util.List<T> |
getOnNextEvents()
Get the sequence of items observed by this
Subscriber, as an ordered List. |
void |
onCompleted()
Notifies the Subscriber that the
Observable has finished sending push-based notifications. |
void |
onError(java.lang.Throwable e)
Notifies the Subscriber that the
Observable has experienced an error condition. |
void |
onNext(T t)
Provides the Subscriber with a new item to observe.
|
void |
requestMore(long n)
Allow calling the protected
Subscriber.request(long) from unit tests. |
add, isUnsubscribed, onStart, request, setProducer, unsubscribepublic TestSubscriber(Subscriber<T> delegate)
public TestSubscriber()
public void onCompleted()
Observable has finished sending push-based notifications.
The Observable will not call this method if it calls onError(java.lang.Throwable).
public java.util.List<Notification<T>> getOnCompletedEvents()
Notifications representing each time this Subscriber was notified of sequence
completion via onCompleted(), as a List.onCompleted() methodpublic void onError(java.lang.Throwable e)
Observable has experienced an error condition.
If the Observable calls this method, it will not thereafter call onNext(T) or
onCompleted().
e - the exception encountered by the Observablepublic java.util.List<java.lang.Throwable> getOnErrorEvents()
onError(java.lang.Throwable) methodpublic void onNext(T t)
The Observable may call this method 0 or more times.
The Observable will not call this method again after it calls either onCompleted() or
onError(java.lang.Throwable).
t - the item emitted by the Observablepublic void requestMore(long n)
Subscriber.request(long) from unit tests.n - the maximum number of items you want the Observable to emit to the Subscriber at this time, or
Long.MAX_VALUE if you want the Observable to emit items at its own pacepublic java.util.List<T> getOnNextEvents()
Subscriber, as an ordered List.public void assertReceivedOnNext(java.util.List<T> items)
Subscriber in order.items - the sequence of items expected to have been observedjava.lang.AssertionError - if the sequence of items observed does not exactly match itemspublic void assertTerminalEvent()
onCompleted() or onError(java.lang.Throwable).java.lang.AssertionError - if not exactly one terminal event notification was receivedpublic void assertUnsubscribed()
Subscriber is unsubscribed.java.lang.AssertionError - if this Subscriber is not unsubscribedpublic void assertNoErrors()
Subscriber has received no onError notifications.java.lang.AssertionError - if this Subscriber has received one or more onError notificationspublic void awaitTerminalEvent()
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification).java.lang.RuntimeException - if the Subscriber is interrupted before the Observable is able to completepublic void awaitTerminalEvent(long timeout,
java.util.concurrent.TimeUnit unit)
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification), or until a timeout expires.timeout - the duration of the timeoutunit - the units in which timeout is expressedjava.lang.RuntimeException - if the Subscriber is interrupted before the Observable is able to completepublic void awaitTerminalEventAndUnsubscribeOnTimeout(long timeout,
java.util.concurrent.TimeUnit unit)
Subscriber receives a notification that the Observable is complete
(either an onCompleted or onError notification), or until a timeout expires; if the
Subscriber is interrupted before either of these events take place, this method unsubscribes the
Subscriber from the Observable).timeout - the duration of the timeoutunit - the units in which timeout is expressedpublic java.lang.Thread getLastSeenThread()
Subscriber.Thread on which this Subscriber last received an item or notification from the
Observable it is subscribed to