Top Description Fields Constructors Methods
rx.internal.observers

public Class AssertableSubscriberObservable<T>

extends Subscriber<T>
implements AssertableSubscriber<T>
Class Inheritance
All Implemented Interfaces
rx.observers.AssertableSubscriber, rx.Subscription, rx.Observer
Type Parameters
<T>
the value type
Imports
java.util.List, java.util.concurrent.TimeUnit, rx.Producer, .Subscriber, rx.functions.Action0, rx.observers.TestSubscriber, .AssertableSubscriber

A AssertableSubscriber is a variety of Subscriber that you can use for unit testing, to perform assertions or inspect received events. AssertableSubscriber is a duplicate of TestSubscriber but supports method chaining where possible.
Since
1.3

Field Summary

Modifier and TypeField and Description
private final TestSubscriber<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public AssertableSubscriber<T>
assertCompleted()

Implements rx.observers.AssertableSubscriber.assertCompleted.

Assert that this Observer received exaclty one onCompleted signal.
public AssertableSubscriber<T>
assertError(Class<? extends Throwable>
the expected type of the onError signal received
clazz
)

Implements rx.observers.AssertableSubscriber.assertError.

Assert that this Observer received one onError signal with the given subclass of a Throwable as type.
public AssertableSubscriber<T>
assertError(Throwable
the Throwable instance expected
throwable
)

Implements rx.observers.AssertableSubscriber.assertError.

Assert that this Observer received one onError signal with the object-equals of the given Throwable instance
public final AssertableSubscriber<T>
assertFailure(Class<? extends Throwable>
the expected Throwable subclass type
errorClass
,
T...
the expected values
values
)

Implements rx.observers.AssertableSubscriber.assertFailure.

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).
public final AssertableSubscriber<T>
assertFailureAndMessage(Class<? extends Throwable>
the expected Throwable subclass type
errorClass
,
String
the expected error message returned by Throwable#getMessage()
message
,
T...
the expected values
values
)

Implements rx.observers.AssertableSubscriber.assertFailureAndMessage.

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).
public AssertableSubscriber<T>
assertNoErrors()

Implements rx.observers.AssertableSubscriber.assertNoErrors.

Assert that this Observer has not received any onError signal.
public AssertableSubscriber<T>
assertNotCompleted()

Implements rx.observers.AssertableSubscriber.assertNotCompleted.

Assert that this Observer received no onCompleted signal.
public AssertableSubscriber<T>
assertNoTerminalEvent()

Implements rx.observers.AssertableSubscriber.assertNoTerminalEvent.

Assert that no onError or onCompleted signals were received so far.
public AssertableSubscriber<T>
assertNoValues()

Implements rx.observers.AssertableSubscriber.assertNoValues.

Assert that no onNext signals were received so far.
public AssertableSubscriber<T>
assertReceivedOnNext(List<T>
the List of items expected
items
)

Implements rx.observers.AssertableSubscriber.assertReceivedOnNext.

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.
public final AssertableSubscriber<T>
assertResult(T...
the values expected
values
)

Implements rx.observers.AssertableSubscriber.assertResult.

Assert that this Observer received the specified items in the given order followed by a completion signal and no errors.
public AssertableSubscriber<T>
assertTerminalEvent()

Implements rx.observers.AssertableSubscriber.assertTerminalEvent.

Assert that this Observer received either an onError or onCompleted signal.
public AssertableSubscriber<T>
assertUnsubscribed()

Implements rx.observers.AssertableSubscriber.assertUnsubscribed.

Assert that this Observer has been unsubscribed via unsubscribe() or by a wrapping SafeSubscriber.
public AssertableSubscriber<T>
assertValue(T
the single value expected
value
)

Implements rx.observers.AssertableSubscriber.assertValue.

Assert that this Observer received exactly the given single expected value (compared via null-safe object equals).
public AssertableSubscriber<T>
assertValueCount(int
the expected number of onNext signals
count
)

Implements rx.observers.AssertableSubscriber.assertValueCount.

Assert that this Observer received exactly the given count of onNext signals.
public AssertableSubscriber<T>
assertValues(T...
the expected values
values
)

Implements rx.observers.AssertableSubscriber.assertValues.

Assert that this Observer received exactly the given expected values (compared via null-safe object equals) in the given order.
public final AssertableSubscriber<T>
assertValuesAndClear(T
the first value expected
expectedFirstValue
,
T...
the rest of the values expected
expectedRestValues
)

Implements rx.observers.AssertableSubscriber.assertValuesAndClear.

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.
public AssertableSubscriber<T>
awaitTerminalEvent()

Implements rx.observers.AssertableSubscriber.awaitTerminalEvent.

Waits for an onError or {code onCompleted} terminal event indefinitely.
public AssertableSubscriber<T>
awaitTerminalEvent(long
the time to wait for the terminal event
timeout
,
TimeUnit
the time unit of the wait time
unit
)

Implements rx.observers.AssertableSubscriber.awaitTerminalEvent.

Waits for an onError or {code onCompleted} terminal event for the given amount of timeout.
public AssertableSubscriber<T>
awaitTerminalEventAndUnsubscribeOnTimeout(long
the time to wait for the terminal event
timeout
,
TimeUnit
the time unit of the wait time
unit
)

Implements rx.observers.AssertableSubscriber.awaitTerminalEventAndUnsubscribeOnTimeout.

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.
public final AssertableSubscriber<T>
awaitValueCount(int
the expected (at least) number of onNext signals
expected
,
long
the timeout to wait to receive the given number of onNext events
timeout
,
TimeUnit
the time unit
unit
)

Implements rx.observers.AssertableSubscriber.awaitValueCount.

Assert that this Observer receives at least the given number of onNext signals within the specified timeout period.
public static <T> AssertableSubscriberObservable<T>
create(long initialRequest)

public final int
getCompletions()

Implements rx.observers.AssertableSubscriber.getCompletions.

Returns the number of onCompleted signals received by this Observer.
public Thread
getLastSeenThread()

Implements rx.observers.AssertableSubscriber.getLastSeenThread.

Returns the Thread that has called the last onNext, onError or onCompleted methods of this Observer.
public List<Throwable>
getOnErrorEvents()

Implements rx.observers.AssertableSubscriber.getOnErrorEvents.

Returns a list of received onError signals.
public List<T>
getOnNextEvents()

Implements rx.observers.AssertableSubscriber.getOnNextEvents.

Returns the list of received onNext events.
public final int
getValueCount()

Implements rx.observers.AssertableSubscriber.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().
public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
e
)

Implements rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
t
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
public void
onStart()

Overrides rx.Subscriber.onStart.

Implements rx.observers.AssertableSubscriber.onStart.

Allows manually calling the onStart method of the underlying Subscriber.
public final AssertableSubscriber<T>
perform(Action0
the action to perform, not null
action
)

Implements rx.observers.AssertableSubscriber.perform.

Performs an action given by the Action0 callback in a fluent manner.
public AssertableSubscriber<T>
requestMore(long
the amount requested, non-negative
n
)

Implements rx.observers.AssertableSubscriber.requestMore.

Requests the specified amount of items from upstream.
public void
setProducer(Producer
the producer to use, not null
p
)

Overrides rx.Subscriber.setProducer.

Implements rx.observers.AssertableSubscriber.setProducer.

Allows manually calling the setProducer method of the underlying Subscriber.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from rx.Subscriber:
addisUnsubscribedrequestunsubscribe

Field Detail

tsback to summary
private final TestSubscriber<T> ts

Constructor Detail

AssertableSubscriberObservableback to summary
public AssertableSubscriberObservable(TestSubscriber<T> ts)

Method Detail

assertCompletedback to summary
public AssertableSubscriber<T> assertCompleted()

Implements rx.observers.AssertableSubscriber.assertCompleted.

Doc from rx.observers.AssertableSubscriber.assertCompleted.

Assert that this Observer received exaclty one onCompleted signal.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertErrorback to summary
public AssertableSubscriber<T> assertError(Class<? extends Throwable> clazz)

Implements rx.observers.AssertableSubscriber.assertError.

Doc from rx.observers.AssertableSubscriber.assertError.

Assert that this Observer received one onError signal with the given subclass of a Throwable as type.

Parameters
clazz:Class<? extends Throwable>

the expected type of the onError signal received

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertErrorback to summary
public AssertableSubscriber<T> assertError(Throwable throwable)

Implements rx.observers.AssertableSubscriber.assertError.

Doc from rx.observers.AssertableSubscriber.assertError.

Assert that this Observer received one onError signal with the object-equals of the given Throwable instance

Parameters
throwable:Throwable

the Throwable instance expected

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertFailureback to summary
public final AssertableSubscriber<T> assertFailure(Class<? extends Throwable> errorClass, T... values)

Implements rx.observers.AssertableSubscriber.assertFailure.

Doc from rx.observers.AssertableSubscriber.assertFailure.

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).

Parameters
errorClass:Class<? extends Throwable>

the expected Throwable subclass type

values:T[]

the expected values

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertFailureAndMessageback to summary
public final AssertableSubscriber<T> assertFailureAndMessage(Class<? extends Throwable> errorClass, String message, T... values)

Implements rx.observers.AssertableSubscriber.assertFailureAndMessage.

Doc from rx.observers.AssertableSubscriber.assertFailureAndMessage.

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).

Parameters
errorClass:Class<? extends Throwable>

the expected Throwable subclass type

message:String

the expected error message returned by Throwable#getMessage()

values:T[]

the expected values

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertNoErrorsback to summary
public AssertableSubscriber<T> assertNoErrors()

Implements rx.observers.AssertableSubscriber.assertNoErrors.

Doc from rx.observers.AssertableSubscriber.assertNoErrors.

Assert that this Observer has not received any onError signal.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertNotCompletedback to summary
public AssertableSubscriber<T> assertNotCompleted()

Implements rx.observers.AssertableSubscriber.assertNotCompleted.

Doc from rx.observers.AssertableSubscriber.assertNotCompleted.

Assert that this Observer received no onCompleted signal.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertNoTerminalEventback to summary
public AssertableSubscriber<T> assertNoTerminalEvent()

Implements rx.observers.AssertableSubscriber.assertNoTerminalEvent.

Doc from rx.observers.AssertableSubscriber.assertNoTerminalEvent.

Assert that no onError or onCompleted signals were received so far.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertNoValuesback to summary
public AssertableSubscriber<T> assertNoValues()

Implements rx.observers.AssertableSubscriber.assertNoValues.

Doc from rx.observers.AssertableSubscriber.assertNoValues.

Assert that no onNext signals were received so far.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertReceivedOnNextback to summary
public AssertableSubscriber<T> assertReceivedOnNext(List<T> items)

Implements rx.observers.AssertableSubscriber.assertReceivedOnNext.

Doc from rx.observers.AssertableSubscriber.assertReceivedOnNext.

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.

Parameters
items:List<T>

the List of items expected

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertResultback to summary
public final AssertableSubscriber<T> assertResult(T... values)

Implements rx.observers.AssertableSubscriber.assertResult.

Doc from rx.observers.AssertableSubscriber.assertResult.

Assert that this Observer received the specified items in the given order followed by a completion signal and no errors.

Parameters
values:T[]

the values expected

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertTerminalEventback to summary
public AssertableSubscriber<T> assertTerminalEvent()

Implements rx.observers.AssertableSubscriber.assertTerminalEvent.

Doc from rx.observers.AssertableSubscriber.assertTerminalEvent.

Assert that this Observer received either an onError or onCompleted signal.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertUnsubscribedback to summary
public AssertableSubscriber<T> assertUnsubscribed()

Implements rx.observers.AssertableSubscriber.assertUnsubscribed.

Doc from rx.observers.AssertableSubscriber.assertUnsubscribed.

Assert that this Observer has been unsubscribed via unsubscribe() or by a wrapping SafeSubscriber.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertValueback to summary
public AssertableSubscriber<T> assertValue(T value)

Implements rx.observers.AssertableSubscriber.assertValue.

Doc from rx.observers.AssertableSubscriber.assertValue.

Assert that this Observer received exactly the given single expected value (compared via null-safe object equals).

Parameters
value:T

the single value expected

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertValueCountback to summary
public AssertableSubscriber<T> assertValueCount(int count)

Implements rx.observers.AssertableSubscriber.assertValueCount.

Doc from rx.observers.AssertableSubscriber.assertValueCount.

Assert that this Observer received exactly the given count of onNext signals.

Parameters
count:int

the expected number of onNext signals

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertValuesback to summary
public AssertableSubscriber<T> assertValues(T... values)

Implements rx.observers.AssertableSubscriber.assertValues.

Doc from rx.observers.AssertableSubscriber.assertValues.

Assert that this Observer received exactly the given expected values (compared via null-safe object equals) in the given order.

Parameters
values:T[]

the expected values

Returns:AssertableSubscriber<T>

this

Annotations
@Override
assertValuesAndClearback to summary
public final AssertableSubscriber<T> assertValuesAndClear(T expectedFirstValue, T... expectedRestValues)

Implements rx.observers.AssertableSubscriber.assertValuesAndClear.

Doc from rx.observers.AssertableSubscriber.assertValuesAndClear.

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.

Parameters
expectedFirstValue:T

the first value expected

expectedRestValues:T[]

the rest of the values expected

Returns:AssertableSubscriber<T>

this

Annotations
@Override
awaitTerminalEventback to summary
public AssertableSubscriber<T> awaitTerminalEvent()

Implements rx.observers.AssertableSubscriber.awaitTerminalEvent.

Doc from rx.observers.AssertableSubscriber.awaitTerminalEvent.

Waits for an onError or {code onCompleted} terminal event indefinitely.

Returns:AssertableSubscriber<T>

this

Annotations
@Override
awaitTerminalEventback to summary
public AssertableSubscriber<T> awaitTerminalEvent(long timeout, TimeUnit unit)

Implements rx.observers.AssertableSubscriber.awaitTerminalEvent.

Doc from rx.observers.AssertableSubscriber.awaitTerminalEvent.

Waits for an onError or {code onCompleted} terminal event for the given amount of timeout.

Parameters
timeout:long

the time to wait for the terminal event

unit:TimeUnit

the time unit of the wait time

Returns:AssertableSubscriber<T>

this

Annotations
@Override
awaitTerminalEventAndUnsubscribeOnTimeoutback to summary
public AssertableSubscriber<T> awaitTerminalEventAndUnsubscribeOnTimeout(long timeout, TimeUnit unit)

Implements rx.observers.AssertableSubscriber.awaitTerminalEventAndUnsubscribeOnTimeout.

Doc from rx.observers.AssertableSubscriber.awaitTerminalEventAndUnsubscribeOnTimeout.

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.

Parameters
timeout:long

the time to wait for the terminal event

unit:TimeUnit

the time unit of the wait time

Returns:AssertableSubscriber<T>

this

Annotations
@Override
awaitValueCountback to summary
public final AssertableSubscriber<T> awaitValueCount(int expected, long timeout, TimeUnit unit)

Implements rx.observers.AssertableSubscriber.awaitValueCount.

Doc from rx.observers.AssertableSubscriber.awaitValueCount.

Assert that this Observer receives at least the given number of 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.

Parameters
expected:int

the expected (at least) number of onNext signals

timeout:long

the timeout to wait to receive the given number of onNext events

unit:TimeUnit

the time unit

Returns:AssertableSubscriber<T>

this

Annotations
@Override
createback to summary
public static <T> AssertableSubscriberObservable<T> create(long initialRequest)
getCompletionsback to summary
public final int getCompletions()

Implements rx.observers.AssertableSubscriber.getCompletions.

Doc from rx.observers.AssertableSubscriber.getCompletions.

Returns the number of onCompleted signals received by this Observer.

Returns:int

the number of onCompleted signals received

Annotations
@Override
getLastSeenThreadback to summary
public Thread getLastSeenThread()

Implements rx.observers.AssertableSubscriber.getLastSeenThread.

Doc from rx.observers.AssertableSubscriber.getLastSeenThread.

Returns the Thread that has called the last onNext, onError or onCompleted methods of this Observer.

Returns:Thread

this

Annotations
@Override
getOnErrorEventsback to summary
public List<Throwable> getOnErrorEvents()

Implements rx.observers.AssertableSubscriber.getOnErrorEvents.

Doc from rx.observers.AssertableSubscriber.getOnErrorEvents.

Returns a list of received onError signals.

Returns:List<Throwable>

this

Annotations
@Override
getOnNextEventsback to summary
public List<T> getOnNextEvents()

Implements rx.observers.AssertableSubscriber.getOnNextEvents.

Doc from rx.observers.AssertableSubscriber.getOnNextEvents.

Returns the list of received 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.

Returns:List<T>

the List of received onNext events.

Annotations
@Override
getValueCountback to summary
public final int getValueCount()

Implements rx.observers.AssertableSubscriber.getValueCount.

Doc from rx.observers.AssertableSubscriber.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().

Returns:int

the number of onNext signals received.

Annotations
@Override
onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Doc from rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(Throwable e)

Implements rx.Observer.onError.

Doc from rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onCompleted.

Parameters
e:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements rx.Observer.onNext.

Doc from rx.Observer.onNext.

Provides the Observer with a new item to observe.

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.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override
onStartback to summary
public void onStart()

Overrides rx.Subscriber.onStart.

Implements rx.observers.AssertableSubscriber.onStart.

Doc from rx.observers.AssertableSubscriber.onStart.

Allows manually calling the onStart method of the underlying Subscriber.

Annotations
@Override
performback to summary
public final AssertableSubscriber<T> perform(Action0 action)

Implements rx.observers.AssertableSubscriber.perform.

Doc from rx.observers.AssertableSubscriber.perform.

Performs an action given by the Action0 callback in a fluent manner.

Parameters
action:Action0

the action to perform, not null

Returns:AssertableSubscriber<T>

this

Annotations
@Override
requestMoreback to summary
public AssertableSubscriber<T> requestMore(long n)

Implements rx.observers.AssertableSubscriber.requestMore.

Doc from rx.observers.AssertableSubscriber.requestMore.

Requests the specified amount of items from upstream.

Parameters
n:long

the amount requested, non-negative

Returns:AssertableSubscriber<T>

this

Annotations
@Override
setProducerback to summary
public void setProducer(Producer p)

Overrides rx.Subscriber.setProducer.

Implements rx.observers.AssertableSubscriber.setProducer.

Doc from rx.observers.AssertableSubscriber.setProducer.

Allows manually calling the setProducer method of the underlying Subscriber.

Parameters
p:Producer

the producer to use, not null

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override