TestSubscriber is a variety of Subscriber that you can use for unit testing, to perform
assertions, inspect received events, or wrap a mocked Subscriber.
| Modifier and Type | Field and Description |
|---|---|
| private int | completions
The number of onCompleted() calls. |
| private final Observer | |
| private final List | |
| private static final Observer | INERT
The shared no-op observer. |
| private volatile Thread | |
| private final CountDownLatch | |
| private volatile int | valueCount
Written after an onNext value has been added to the |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | TestSubscriber(long
the initial request value, negative value will revert to the default unbounded behavior initialRequest)Constructs a TestSubscriber with the initial request to be requested from upstream. |
| public | TestSubscriber(Observer<T>
the Observer instance to wrap delegate, long the initial request value, negative value will revert to the default unbounded behavior initialRequest)Constructs a TestSubscriber with the initial request to be requested from upstream and a delegate Observer to wrap. |
| public | TestSubscriber(Subscriber<T>
the subscriber to delegate to. delegate)Constructs a TestSubscriber which requests Long.MAX_VALUE and delegates events to the given Subscriber. |
| public | TestSubscriber(Observer<T>
the observer to delegate to. delegate)Constructs a TestSubscriber which requests Long.MAX_VALUE and delegates events to the given Observer. |
| public | TestSubscriber()
Constructs a TestSubscriber with an initial request of Long.MAX_VALUE and no delegation. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | assertError(Class<? extends Throwable>
the class to check the error against. clazz)Asserts that there is exactly one error event which is a subclass of the given class. |
| public void | assertError(Throwable
the throwable to check throwable)Asserts that there is a single onError event with the exact exception. |
| pack-priv final void | assertionError(String
the message to use for the error message)Combines an assertion error message with the current completion and error state of this TestSubscriber, giving more information when some assertXXX check fails. |
| private void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | assertReceivedOnNext(List<T>
the sequence of items expected to have been observed items)Asserts that a particular sequence of items was received by this |
| public void | |
| public void | |
| public void | assertValue(T
the item to check value)Asserts that there is only a single received onNext event and that it marks the emission of a specific item. |
| public void | assertValueCount(int
the expected number of onNext events count)Asserts that the given number of onNext events are received. |
| public void | assertValues(T...
the items to check values)Asserts that the received onNext events, in order, are the specified items. |
| public final void | assertValuesAndClear(T
the expected first value expectedFirstValue, T... the optional rest values expectedRestValues)Assert that the TestSubscriber contains the given first and optional rest values exactly and if so, clears the internal list of values. |
| public void | awaitTerminalEvent()
Blocks until this |
| public void | awaitTerminalEvent(long
the duration of the timeout timeout, TimeUnit the units in which unit)timeout is expressedBlocks until this |
| public void | awaitTerminalEventAndUnsubscribeOnTimeout(long
the duration of the timeout timeout, TimeUnit the units in which unit)timeout is expressedBlocks until this |
| public final boolean | Returns: true if the expected number of onNext events happenedthe expected number of onNext events expected, long the time to wait for the events timeout, TimeUnit the time unit of waiting unit)Wait until the current committed value count is less than the expected amount by sleeping 1 unit at most timeout times and return true if at least the required amount of onNext values have been received. |
| public static < the value type T> TestSubscriber | Returns: the created TestSubscriber instanceFactory method to construct a TestSubscriber with an initial request of Long.MAX_VALUE and no delegation. |
| public static < the value type T> TestSubscriber | Returns: the created TestSubscriber instancethe initial request amount, negative values revert to the default unbounded mode initialRequest)Factory method to construct a TestSubscriber with the given initial request amount and no delegation. |
| public static < the value type T> TestSubscriber | Returns: the created TestSubscriber instancethe observer to delegate events to delegate, long the initial request amount, negative values revert to the default unbounded mode initialRequest)Factory method to construct a TestSubscriber which delegates events to the given Observer and issues the given initial request amount. |
| public static < the value type T> TestSubscriber | Returns: the created TestSubscriber instancethe subscriber to delegate events to delegate)Factory method to construct a TestSubscriber which delegates events to the given Subscriber and an issues an initial request of Long.MAX_VALUE. |
| public static < the value type T> TestSubscriber | |
| public final int | Returns: the number of times onCompleted was called on this TestSubscriber.Returns the number of times onCompleted was called on this TestSubscriber. |
| public Thread | Returns: theThread on which this Subscriber last received an item or notification from the
Observable it is subscribed toReturns the last thread that was in use when an item or notification was received by this
|
| public List | Returns: a list of Notifications representing calls to this Subscriber'sonCompleted method
Deprecated
use
Returns the getCompletions() instead.
Notifications representing each time this Subscriber was notified of sequence
completion via onCompleted, as a List.
|
| public List | Returns: a list of the Throwables that were passed to this Subscriber'sonError methodReturns the |
| public List | Returns: a list of items observed by this Subscriber, in the order in which they were observedReturns the sequence of items observed by this |
| public final int | Returns: the committed number of onNext elementsReturns the committed number of onNext elements that are safe to be
read from |
| public void | onCompleted()
Implements rx. Observable has finished sending push-based notifications.
|
| public void | onError(Throwable
the exception encountered by the Observable e)Implements rx. Observable has experienced an error condition.
|
| public void | onNext(T
the item emitted by the Observable t)Implements rx. |
| public void | requestMore(long
the maximum number of items you want the Observable to emit to the Subscriber at this time, or
n)Long.MAX_VALUE if you want the Observable to emit items at its own paceAllows calling the protected |
| completions | back to summary |
|---|---|
| private int completions The number of onCompleted() calls. | |
| delegate | back to summary |
|---|---|
| private final Observer<T> delegate | |
| errors | back to summary |
|---|---|
| private final List<Throwable> errors | |
| INERT | back to summary |
|---|---|
| private static final Observer<Object> INERT The shared no-op observer. | |
| lastSeenThread | back to summary |
|---|---|
| private volatile Thread lastSeenThread | |
| latch | back to summary |
|---|---|
| private final CountDownLatch latch | |
| valueCount | back to summary |
|---|---|
| private volatile int valueCount Written after an onNext value has been added to the | |
| values | back to summary |
|---|---|
| private final List<T> values | |
| TestSubscriber | back to summary |
|---|---|
| public TestSubscriber(long initialRequest) Constructs a TestSubscriber with the initial request to be requested from upstream.
| |
| TestSubscriber | back to summary |
|---|---|
| public TestSubscriber(Observer<T> delegate, long initialRequest) Constructs a TestSubscriber with the initial request to be requested from upstream and a delegate Observer to wrap.
| |
| TestSubscriber | back to summary |
|---|---|
| public TestSubscriber(Subscriber<T> delegate) Constructs a TestSubscriber which requests Long.MAX_VALUE and delegates events to the given Subscriber.
| |
| TestSubscriber | back to summary |
|---|---|
| public TestSubscriber(Observer<T> delegate) Constructs a TestSubscriber which requests Long.MAX_VALUE and delegates events to the given Observer.
| |
| TestSubscriber | back to summary |
|---|---|
| public TestSubscriber() Constructs a TestSubscriber with an initial request of Long.MAX_VALUE and no delegation. | |
| assertCompleted | back to summary |
|---|---|
| public void assertCompleted() Asserts that there is exactly one completion event.
| |
| assertError | back to summary |
|---|---|
| public void assertError(Class<? extends Throwable> clazz) Asserts that there is exactly one error event which is a subclass of the given class.
| |
| assertError | back to summary |
|---|---|
| public void assertError(Throwable throwable) Asserts that there is a single onError event with the exact exception.
| |
| assertionError | back to summary |
|---|---|
| pack-priv final void assertionError(String message) Combines an assertion error message with the current completion and error state of this TestSubscriber, giving more information when some assertXXX check fails.
| |
| assertItem | back to summary |
|---|---|
| private void assertItem(T expected, int i) | |
| assertNoErrors | back to summary |
|---|---|
| public void assertNoErrors() Asserts that this
| |
| assertNotCompleted | back to summary |
|---|---|
| public void assertNotCompleted() Asserts that there is no completion event.
| |
| assertNoTerminalEvent | back to summary |
|---|---|
| public void assertNoTerminalEvent() Asserts that there are no onError and onCompleted events.
| |
| assertNoValues | back to summary |
|---|---|
| public void assertNoValues() Asserts that there are no onNext events received.
| |
| assertReceivedOnNext | back to summary |
|---|---|
| public void assertReceivedOnNext(List<T> items) Asserts that a particular sequence of items was received by this
| |
| assertTerminalEvent | back to summary |
|---|---|
| public void assertTerminalEvent() Asserts that a single terminal event occurred, either
| |
| assertUnsubscribed | back to summary |
|---|---|
| public void assertUnsubscribed() Asserts that this
| |
| assertValue | back to summary |
|---|---|
| public void assertValue(T value) Asserts that there is only a single received onNext event and that it marks the emission of a specific item.
| |
| assertValueCount | back to summary |
|---|---|
| public void assertValueCount(int count) Asserts that the given number of onNext events are received.
| |
| assertValues | back to summary |
|---|---|
| public void assertValues(T... values) Asserts that the received onNext events, in order, are the specified items.
| |
| assertValuesAndClear | back to summary |
|---|---|
| public final void assertValuesAndClear(T expectedFirstValue, T... expectedRestValues) Assert that the TestSubscriber contains the given first and optional rest values exactly and if so, clears the internal list of values.
| |
| awaitTerminalEvent | back to summary |
|---|---|
| public void awaitTerminalEvent() Blocks until this
| |
| awaitTerminalEvent | back to summary |
|---|---|
| public void awaitTerminalEvent(long timeout, TimeUnit unit) Blocks until this
| |
| awaitTerminalEventAndUnsubscribeOnTimeout | back to summary |
|---|---|
| public void awaitTerminalEventAndUnsubscribeOnTimeout(long timeout, TimeUnit unit) Blocks until this
| |
| awaitValueCount | back to summary |
|---|---|
| public final boolean awaitValueCount(int expected, long timeout, TimeUnit unit) Wait until the current committed value count is less than the expected amount by sleeping 1 unit at most timeout times and return true if at least the required amount of onNext values have been received.
| |
| create | back to summary |
|---|---|
| public static <T> TestSubscriber Factory method to construct a TestSubscriber with an initial request of Long.MAX_VALUE and no delegation.
| |
| create | back to summary |
|---|---|
| public static <T> TestSubscriber Factory method to construct a TestSubscriber with the given initial request amount and no delegation.
| |
| create | back to summary |
|---|---|
| public static <T> TestSubscriber Factory method to construct a TestSubscriber which delegates events to the given Observer and issues the given initial request amount.
| |
| create | back to summary |
|---|---|
| public static <T> TestSubscriber Factory method to construct a TestSubscriber which delegates events to the given Subscriber and an issues an initial request of Long.MAX_VALUE.
| |
| create | back to summary |
|---|---|
| public static <T> TestSubscriber Factory method to construct a TestSubscriber which delegates events to the given Observer and an issues an initial request of Long.MAX_VALUE.
| |
| getCompletions | back to summary |
|---|---|
| public final int getCompletions() Returns the number of times onCompleted was called on this TestSubscriber.
| |
| getLastSeenThread | back to summary |
|---|---|
| public Thread getLastSeenThread() Returns the last thread that was in use when an item or notification was received by this
| |
| getOnCompletedEvents | back to summary |
|---|---|
| public List Deprecated use Returns the
| |
| getOnErrorEvents | back to summary |
|---|---|
| public List Returns the | |
| getOnNextEvents | back to summary |
|---|---|
| public List Returns the sequence of items observed by this
| |
| getValueCount | back to summary |
|---|---|
| public final int getValueCount() Returns the committed number of onNext elements that are safe to be
read from
| |
| onCompleted | back to summary |
|---|---|
| public void onCompleted() Implements rx. Notifies the Subscriber that the
The
| |
| onError | back to summary |
|---|---|
| public void onError(Throwable e) Implements rx. Notifies the Subscriber that the
If the | |
| onNext | back to summary |
|---|---|
| public void onNext(T t) Implements rx. Provides the Subscriber with a new item to observe.
The
The
| |
| requestMore | back to summary |
|---|---|
| public void requestMore(long n) Allows calling the protected
| |