Top Description Methods
rx.observers

public Interface AssertableSubscriber<T>

extends Observer<T>, Subscription
Known Direct Implementers
rx.internal.observers.AssertableSubscriberObservable
Type Parameters
<T>
the value type consumed by this Observer
Imports
java.util.List, java.util.concurrent.TimeUnit, rx.*, rx.functions.Action0

Interface for asserting the state of a sequence under testing with a 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

Since
1.3

Method Summary

Modifier and TypeMethod and Description
public AssertableSubscriber<T>

Returns:

this
assertCompleted
()

Assert that this Observer received exaclty one onCompleted signal.

public AssertableSubscriber<T>

Returns:

this
assertError
(Class<? extends Throwable>
the expected type of the onError signal received
clazz
)

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

public AssertableSubscriber<T>

Returns:

this
assertError
(Throwable
the Throwable instance expected
throwable
)

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

public AssertableSubscriber<T>

Returns:

this
assertFailure
(Class<? extends Throwable>
the expected Throwable subclass type
errorClass
,
T...
the expected values
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).

public AssertableSubscriber<T>

Returns:

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

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>

Returns:

this
assertNoErrors
()

Assert that this Observer has not received any onError signal.

public AssertableSubscriber<T>

Returns:

this
assertNotCompleted
()

Assert that this Observer received no onCompleted signal.

public AssertableSubscriber<T>

Returns:

this
assertNoTerminalEvent
()

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

public AssertableSubscriber<T>

Returns:

this
assertNoValues
()

Assert that no onNext signals were received so far.

public AssertableSubscriber<T>

Returns:

this
assertReceivedOnNext
(List<T>
the List of items expected
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.

public AssertableSubscriber<T>

Returns:

this
assertResult
(T...
the values expected
values
)

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

public AssertableSubscriber<T>

Returns:

this
assertTerminalEvent
()

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

public AssertableSubscriber<T>

Returns:

this
assertUnsubscribed
()

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

public AssertableSubscriber<T>

Returns:

this
assertValue
(T
the single value expected
value
)

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

public AssertableSubscriber<T>

Returns:

this
assertValueCount
(int
the expected number of onNext signals
count
)

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

public AssertableSubscriber<T>

Returns:

this
assertValues
(T...
the expected values
values
)

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

public AssertableSubscriber<T>

Returns:

this
assertValuesAndClear
(T
the first value expected
expectedFirstValue
,
T...
the rest of the values expected
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.

public AssertableSubscriber<T>

Returns:

this
awaitTerminalEvent
()

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

public AssertableSubscriber<T>

Returns:

this
awaitTerminalEvent
(long
the time to wait for the terminal event
timeout
,
TimeUnit
the time unit of the wait time
unit
)

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

public AssertableSubscriber<T>

Returns:

this
awaitTerminalEventAndUnsubscribeOnTimeout
(long
the time to wait for the terminal event
timeout
,
TimeUnit
the time unit of the wait time
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.

public AssertableSubscriber<T>

Returns:

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

Assert that this Observer receives at least the given number of onNext signals within the specified timeout period.

public int

Returns:

the number of onCompleted signals received
getCompletions
()

Returns the number of onCompleted signals received by this Observer.

public Thread

Returns:

this
getLastSeenThread
()

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

public List<Throwable>

Returns:

this
getOnErrorEvents
()

Returns a list of received onError signals.

public List<T>

Returns:

the List of received onNext events.
getOnNextEvents
()

Returns the list of received onNext events.

public int

Returns:

the number of onNext signals received.
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 boolean
isUnsubscribed()

Redeclares rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
public void
onStart()

Allows manually calling the onStart method of the underlying Subscriber.

public AssertableSubscriber<T>

Returns:

this
perform
(Action0
the action to perform, not null
action
)

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

public AssertableSubscriber<T>

Returns:

this
requestMore
(long
the amount requested, non-negative
n
)

Requests the specified amount of items from upstream.

public void
setProducer(Producer
the producer to use, not null
p
)

Allows manually calling the setProducer method of the underlying Subscriber.

public void
unsubscribe()

Redeclares rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
Inherited from rx.Observer:
onCompletedonErroronNext

Method Detail

assertCompletedback to summary
public AssertableSubscriber<T> assertCompleted()

Assert that this Observer received exaclty one onCompleted signal.

Returns:AssertableSubscriber<T>

this

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

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

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

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

assertFailureback to summary
public AssertableSubscriber<T> assertFailure(Class<? extends 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).

Parameters
errorClass:Class<? extends Throwable>

the expected Throwable subclass type

values:T[]

the expected values

Returns:AssertableSubscriber<T>

this

assertFailureAndMessageback to summary
public AssertableSubscriber<T> assertFailureAndMessage(Class<? extends Throwable> errorClass, 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).

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

assertNoErrorsback to summary
public AssertableSubscriber<T> assertNoErrors()

Assert that this Observer has not received any onError signal.

Returns:AssertableSubscriber<T>

this

assertNotCompletedback to summary
public AssertableSubscriber<T> assertNotCompleted()

Assert that this Observer received no onCompleted signal.

Returns:AssertableSubscriber<T>

this

assertNoTerminalEventback to summary
public AssertableSubscriber<T> assertNoTerminalEvent()

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

Returns:AssertableSubscriber<T>

this

assertNoValuesback to summary
public AssertableSubscriber<T> assertNoValues()

Assert that no onNext signals were received so far.

Returns:AssertableSubscriber<T>

this

assertReceivedOnNextback to summary
public AssertableSubscriber<T> assertReceivedOnNext(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.

Parameters
items:List<T>

the List of items expected

Returns:AssertableSubscriber<T>

this

assertResultback to summary
public 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.

Parameters
values:T[]

the values expected

Returns:AssertableSubscriber<T>

this

assertTerminalEventback to summary
public AssertableSubscriber<T> assertTerminalEvent()

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

Returns:AssertableSubscriber<T>

this

assertUnsubscribedback to summary
public AssertableSubscriber<T> assertUnsubscribed()

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

Returns:AssertableSubscriber<T>

this

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

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

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

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

assertValuesback to summary
public 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.

Parameters
values:T[]

the expected values

Returns:AssertableSubscriber<T>

this

assertValuesAndClearback to summary
public 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.

Parameters
expectedFirstValue:T

the first value expected

expectedRestValues:T[]

the rest of the values expected

Returns:AssertableSubscriber<T>

this

awaitTerminalEventback to summary
public AssertableSubscriber<T> awaitTerminalEvent()

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

Returns:AssertableSubscriber<T>

this

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

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

awaitTerminalEventAndUnsubscribeOnTimeoutback to summary
public AssertableSubscriber<T> awaitTerminalEventAndUnsubscribeOnTimeout(long timeout, 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.

Parameters
timeout:long

the time to wait for the terminal event

unit:TimeUnit

the time unit of the wait time

Returns:AssertableSubscriber<T>

this

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

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

getCompletionsback to summary
public int getCompletions()

Returns the number of onCompleted signals received by this Observer.

Returns:int

the number of onCompleted signals received

getLastSeenThreadback to summary
public Thread getLastSeenThread()

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

Returns:Thread

this

getOnErrorEventsback to summary
public List<Throwable> getOnErrorEvents()

Returns a list of received onError signals.

Returns:List<Throwable>

this

getOnNextEventsback to summary
public List<T> 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.

getValueCountback to summary
public 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().

Returns:int

the number of onNext signals received.

isUnsubscribedback to summary
public boolean isUnsubscribed()

Redeclares rx.Subscription.isUnsubscribed.

Doc from rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.

Returns:boolean

true if this Subscription is currently unsubscribed, false otherwise

Annotations
@Override
onStartback to summary
public void onStart()

Allows manually calling the onStart method of the underlying Subscriber.

performback to summary
public AssertableSubscriber<T> perform(Action0 action)

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

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

Requests the specified amount of items from upstream.

Parameters
n:long

the amount requested, non-negative

Returns:AssertableSubscriber<T>

this

setProducerback to summary
public void setProducer(Producer p)

Allows manually calling the setProducer method of the underlying Subscriber.

Parameters
p:Producer

the producer to use, not null

unsubscribeback to summary
public void unsubscribe()

Redeclares rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the 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).

Annotations
@Override