Top Description Inners Fields Constructors Methods
io.reactivex.observers

public abstract Class BaseTestConsumer<T, U extends io.reactivex.observers.BaseTestConsumer<T, U>>

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.disposables.Disposable
Known Direct Subclasses
io.reactivex.observers.TestObserver, io.reactivex.subscribers.TestSubscriber
Type Parameters
<T>
the value type consumed
<U>
the subclass of this BaseTestConsumer
Imports
java.util.*, java.util.concurrent.*, io.reactivex.Notification, io.reactivex.disposables.Disposable, io.reactivex.exceptions.CompositeException, io.reactivex.functions.Predicate, io.reactivex.internal.functions.*, io.reactivex.internal.util.*

Base class with shared infrastructure to support TestSubscriber and TestObserver.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
BaseTestConsumer.TestWaitStrategy

Enumeration of default wait strategies when waiting for a specific number of items in BaseTestConsumer#awaitCount(int, Runnable).

Field Summary

Modifier and TypeField and Description
protected boolean
protected long
completions

The number of completions.

protected final CountDownLatch
done

The latch that indicates an onError or onComplete has been called.

protected final List<Throwable>
errors

The list of errors received.

protected int
protected int
protected Thread
lastThread

The last thread seen by the observer.

protected CharSequence
tag

The optional tag associated with this test consumer.

protected boolean
timeout

Indicates that one of the awaitX method has timed out.

protected final List<T>
values

The list of values received.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final U

Returns:

this
assertComplete
()

Assert that this TestObserver/TestSubscriber received exactly one onComplete event.

public final U

Returns:

this
assertEmpty
()

Assert that the TestObserver/TestSubscriber has received a Disposable but no other events.

public final U

Returns:

this
assertError
(Throwable
the error to check
error
)

Assert that this TestObserver/TestSubscriber received exactly the specified onError event value.

public final U

Returns:

this
assertError
(Class<? extends Throwable>
the error class to expect
errorClass
)

Asserts that this TestObserver/TestSubscriber received exactly one onError event which is an instance of the specified errorClass class.

public final U

Returns:

this
assertError
(Predicate<Throwable>
the predicate that receives the error Throwable and should return true for expected errors.
errorPredicate
)

Asserts that this TestObserver/TestSubscriber received exactly one onError event for which the provided predicate returns true.

public final U

Returns:

this
assertErrorMessage
(String
the message expected
message
)

Assert that there is a single error and it has the given message.

public final U

Returns:

this
assertFailure
(Class<? extends Throwable>
the expected exception (parent) class
error
,
T...
the expected values, asserted in order
values
)

Assert that the upstream signalled the specified values in order and then failed with a specific class or subclass of Throwable.

public final U

Returns:

this
assertFailure
(Predicate<Throwable>
the predicate that receives the error Throwable and should return true for expected errors.
errorPredicate
,
T...
the expected values, asserted in order
values
)

Assert that the upstream signalled the specified values in order and then failed with a Throwable for which the provided predicate returns true.

public final U

Returns:

this
assertFailureAndMessage
(Class<? extends Throwable>
the expected exception (parent) class
error
,
String
the expected failure message
message
,
T...
the expected values, asserted in order
values
)

Assert that the upstream signalled the specified values in order, then failed with a specific class or subclass of Throwable and with the given exact error message.

public final U

Returns:

this
assertNever
(T
the value to expect not being received
value
)

Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to the given value with respect to null-safe Object.equals.

public final U

Returns:

this
assertNever
(Predicate<? super T>
the predicate that receives the onNext value and should return true for the expected value.
valuePredicate
)

Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which the provided predicate returns true.

public final U

Returns:

this
assertNoErrors
()

Assert that this TestObserver/TestSubscriber has not received any onError event.

public final U

Returns:

this
assertNotComplete
()

Assert that this TestObserver/TestSubscriber has not received any onComplete event.

public final U

Returns:

this
assertNoTimeout
()

Asserts that some awaitX method has not timed out.

public abstract U

Returns:

this
assertNotSubscribed
()

Assert that the onSubscribe method hasn't been called at all.

public final U

Returns:

this
assertNotTerminated
()

Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero).

public final U

Returns:

this
assertNoValues
()

Assert that this TestObserver/TestSubscriber has not received any onNext events.

public final U

Returns:

this
assertResult
(T...
the expected values, asserted in order
values
)

Assert that the upstream signalled the specified values in order and completed normally.

public abstract U

Returns:

this
assertSubscribed
()

Assert that the onSubscribe method was called exactly once.

public final U

Returns:

this
assertTerminated
()

Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero).

public final U

Returns:

this
assertTimeout
()

Asserts that some awaitX method has timed out.

public final U

Returns:

this
assertValue
(T
the value to expect
value
)

Assert that this TestObserver/TestSubscriber received exactly one onNext value which is equal to the given value with respect to Objects.equals.

public final U

Returns:

this
assertValue
(Predicate<T>
the predicate that receives the onNext value and should return true for the expected value.
valuePredicate
)

Asserts that this TestObserver/TestSubscriber received exactly one onNext value for which the provided predicate returns true.

public final U

Returns:

this
assertValueAt
(int
the position to assert on
index
,
T
the value to expect
value
)

Asserts that this TestObserver/TestSubscriber received an onNext value at the given index which is equal to the given value with respect to null-safe Object.equals.

public final U

Returns:

this
assertValueAt
(int
the position to assert on
index
,
Predicate<T>
the predicate that receives the onNext value and should return true for the expected value.
valuePredicate
)

Asserts that this TestObserver/TestSubscriber received an onNext value at the given index for the provided predicate returns true.

public final U

Returns:

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

Assert that this TestObserver/TestSubscriber received the specified number onNext events.

public final U

Returns:

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

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order.

public final U

Returns:

this
assertValueSequence
(Iterable<? extends T>
the sequence of expected values in order
sequence
)

Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order.

public final U

Returns:

this
assertValueSequenceOnly
(Iterable<? extends T>
the sequence of expected values in order
sequence
)

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating.

public final U

Returns:

this
assertValueSet
(Collection<? extends T>
the collection of values expected in any order
expected
)

Assert that the TestObserver/TestSubscriber received only items that are in the specified collection as well, irrespective of the order they were received.

public final U

Returns:

this
assertValueSetOnly
(Collection<? extends T>
the collection of values expected in any order
expected
)

Assert that the TestObserver/TestSubscriber received only the specified values in any order without terminating.

public final U

Returns:

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

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating.

public final U

Returns:

this
await
()

Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events.

public final boolean

Returns:

true if the TestObserver/TestSubscriber terminated, false if timeout happened
await
(long
the waiting time
time
,
TimeUnit
the time unit of the waiting time
unit
)

Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.

public final U

Returns:

this
awaitCount
(int
the number of items expected at least
atLeast
)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates by sleeping 10 milliseconds at a time up to 5000 milliseconds of timeout.

public final U

Returns:

this
awaitCount
(int
the number of items expected at least
atLeast
,
Runnable
a Runnable called when the current received count hasn't reached the expected value and there was no terminal event either, see TestWaitStrategy for examples
waitStrategy
)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates by waiting according to the wait strategy and up to 5000 milliseconds of timeout.

public final U

Returns:

this
awaitCount
(int
the number of items expected at least
atLeast
,
Runnable
a Runnable called when the current received count hasn't reached the expected value and there was no terminal event either, see TestWaitStrategy for examples
waitStrategy
,
long
if positive, the await ends if the specified amount of time has passed no matter how many items were received
timeoutMillis
)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates.

public final U

Returns:

this
awaitDone
(long
the waiting time
time
,
TimeUnit
the time unit of the waiting time
unit
)

Awaits until the internal latch is counted down.

public final boolean

Returns:

true if the TestObserver/TestSubscriber terminated, false if the wait has been interrupted
awaitTerminalEvent
()

Waits until the any terminal event has been received by this TestObserver/TestSubscriber or returns false if the wait has been interrupted.

public final boolean

Returns:

true if the TestObserver/TestSubscriber terminated, false if timeout or interrupt happened
awaitTerminalEvent
(long
the waiting time
duration
,
TimeUnit
the time unit of the waiting time
unit
)

Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.

public final U

Returns:

this
clearTimeout
()

Clears the timeout flag set by the await methods when they timed out.

public final long

Returns:

the number of times onComplete was called
completions
()

Returns the number of times onComplete was called.

public final int

Returns:

the number of onError exceptions received
errorCount
()

Returns the number of onError exceptions received.

public final List<Throwable>

Returns:

a list of received events onError exceptions
errors
()

Returns a shared list of received onError exceptions.

protected final AssertionError

Returns:

AssertionError the prepared AssertionError instance
fail
(String
the message to use
message
)

Fail with the given message and add the sequence of errors as suppressed ones.

public final List<List<Object>>

Returns:

a list of (values, errors, completion-notifications)
getEvents
()

Returns a list of 3 other lists: the first inner list contains the plain values received; the second list contains the potential errors and the final list contains the potential completions as Notifications.

public final boolean

Returns:

true if TestObserver/TestSubscriber received any onError or onComplete events
isTerminated
()

Returns true if TestObserver/TestSubscriber received any onError or onComplete events.

public final boolean

Returns:

true if one of the timeout-based await methods has timed out.

History: 2.0.7 - experimental

isTimeout
()

Returns true if an await timed out.

public final Thread

Returns:

the last thread which called the onXXX methods
lastThread
()

Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber.

public static String

Returns:

the string representation
valueAndClass
(Object
the object
o
)

Appends the class name to a non-null value.

public final int

Returns:

the number of onNext values received
valueCount
()

Returns the number of onNext values received.

public final List<T>

Returns:

a list of received onNext values
values
()

Returns a shared list of received onNext values.

public final U

Returns:

this
withTag
(CharSequence
the string to display (null won't print any tag)
tag
)

Set the tag displayed along with an assertion failure's other state information.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkSubscriptionOnceback to summary
protected boolean checkSubscriptionOnce
completionsback to summary
protected long completions

The number of completions.

doneback to summary
protected final CountDownLatch done

The latch that indicates an onError or onComplete has been called.

errorsback to summary
protected final List<Throwable> errors

The list of errors received.

establishedFusionModeback to summary
protected int establishedFusionMode
initialFusionModeback to summary
protected int initialFusionMode
lastThreadback to summary
protected Thread lastThread

The last thread seen by the observer.

tagback to summary
protected CharSequence tag

The optional tag associated with this test consumer.

Since
2.0.7
timeoutback to summary
protected boolean timeout

Indicates that one of the awaitX method has timed out.

Since
2.0.7
valuesback to summary
protected final List<T> values

The list of values received.

Constructor Detail

BaseTestConsumerback to summary
public BaseTestConsumer()

Method Detail

assertCompleteback to summary
public final U assertComplete()

Assert that this TestObserver/TestSubscriber received exactly one onComplete event.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertEmptyback to summary
public final U assertEmpty()

Assert that the TestObserver/TestSubscriber has received a Disposable but no other events.

Returns:U

this

assertErrorback to summary
public final U assertError(Throwable error)

Assert that this TestObserver/TestSubscriber received exactly the specified onError event value.

The comparison is performed via Objects.equals(); since most exceptions don't implement equals(), this assertion may fail. Use the assertError(Class) overload to test against the class of an error instead of an instance of an error or assertError(Predicate) to test with different condition.

Parameters
error:Throwable

the error to check

Returns:U

this

See Also
assertError(Class), assertError(Predicate)
assertErrorback to summary
public final U assertError(Class<? extends Throwable> errorClass)

Asserts that this TestObserver/TestSubscriber received exactly one onError event which is an instance of the specified errorClass class.

Parameters
errorClass:Class<? extends Throwable>

the error class to expect

Returns:U

this

Annotations
@SuppressWarnings:unchecked, rawtypes, cast
assertErrorback to summary
public final U assertError(Predicate<Throwable> errorPredicate)

Asserts that this TestObserver/TestSubscriber received exactly one onError event for which the provided predicate returns true.

Parameters
errorPredicate:Predicate<Throwable>

the predicate that receives the error Throwable and should return true for expected errors.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertErrorMessageback to summary
public final U assertErrorMessage(String message)

Assert that there is a single error and it has the given message.

Parameters
message:String

the message expected

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertFailureback to summary
public final U assertFailure(Class<? extends Throwable> error, T... values)

Assert that the upstream signalled the specified values in order and then failed with a specific class or subclass of Throwable.

Parameters
error:Class<? extends Throwable>

the expected exception (parent) class

values:T[]

the expected values, asserted in order

Returns:U

this

assertFailureback to summary
public final U assertFailure(Predicate<Throwable> errorPredicate, T... values)

Assert that the upstream signalled the specified values in order and then failed with a Throwable for which the provided predicate returns true.

Parameters
errorPredicate:Predicate<Throwable>

the predicate that receives the error Throwable and should return true for expected errors.

values:T[]

the expected values, asserted in order

Returns:U

this

assertFailureAndMessageback to summary
public final U assertFailureAndMessage(Class<? extends Throwable> error, String message, T... values)

Assert that the upstream signalled the specified values in order, then failed with a specific class or subclass of Throwable and with the given exact error message.

Parameters
error:Class<? extends Throwable>

the expected exception (parent) class

message:String

the expected failure message

values:T[]

the expected values, asserted in order

Returns:U

this

assertNeverback to summary
public final U assertNever(T value)

Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to the given value with respect to null-safe Object.equals.

History: 2.0.5 - experimental

Parameters
value:T

the value to expect not being received

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
assertNeverback to summary
public final U assertNever(Predicate<? super T> valuePredicate)

Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which the provided predicate returns true.

History: 2.0.5 - experimental

Parameters
valuePredicate:Predicate<? super T>

the predicate that receives the onNext value and should return true for the expected value.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
assertNoErrorsback to summary
public final U assertNoErrors()

Assert that this TestObserver/TestSubscriber has not received any onError event.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertNotCompleteback to summary
public final U assertNotComplete()

Assert that this TestObserver/TestSubscriber has not received any onComplete event.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertNoTimeoutback to summary
public final U assertNoTimeout()

Asserts that some awaitX method has not timed out.

History: 2.0.7 - experimental

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
assertNotSubscribedback to summary
public abstract U assertNotSubscribed()

Assert that the onSubscribe method hasn't been called at all.

Returns:U

this

assertNotTerminatedback to summary
public final U assertNotTerminated()

Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero).

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertNoValuesback to summary
public final U assertNoValues()

Assert that this TestObserver/TestSubscriber has not received any onNext events.

Returns:U

this

assertResultback to summary
public final U assertResult(T... values)

Assert that the upstream signalled the specified values in order and completed normally.

Parameters
values:T[]

the expected values, asserted in order

Returns:U

this

See Also
assertFailure(Class, Object...), assertFailure(Predicate, Object...), assertFailureAndMessage(Class, String, Object...)
assertSubscribedback to summary
public abstract U assertSubscribed()

Assert that the onSubscribe method was called exactly once.

Returns:U

this

assertTerminatedback to summary
public final U assertTerminated()

Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero).

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertTimeoutback to summary
public final U assertTimeout()

Asserts that some awaitX method has timed out.

History: 2.0.7 - experimental

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
assertValueback to summary
public final U assertValue(T value)

Assert that this TestObserver/TestSubscriber received exactly one onNext value which is equal to the given value with respect to Objects.equals.

Parameters
value:T

the value to expect

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValueback to summary
public final U assertValue(Predicate<T> valuePredicate)

Asserts that this TestObserver/TestSubscriber received exactly one onNext value for which the provided predicate returns true.

Parameters
valuePredicate:Predicate<T>

the predicate that receives the onNext value and should return true for the expected value.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValueAtback to summary
public final U assertValueAt(int index, T value)

Asserts that this TestObserver/TestSubscriber received an onNext value at the given index which is equal to the given value with respect to null-safe Object.equals.

History: 2.1.3 - experimental

Parameters
index:int

the position to assert on

value:T

the value to expect

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.2
assertValueAtback to summary
public final U assertValueAt(int index, Predicate<T> valuePredicate)

Asserts that this TestObserver/TestSubscriber received an onNext value at the given index for the provided predicate returns true.

Parameters
index:int

the position to assert on

valuePredicate:Predicate<T>

the predicate that receives the onNext value and should return true for the expected value.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValueCountback to summary
public final U assertValueCount(int count)

Assert that this TestObserver/TestSubscriber received the specified number onNext events.

Parameters
count:int

the expected number of onNext events

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValuesback to summary
public final U assertValues(T... values)

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order.

Parameters
values:T[]

the values expected

Returns:U

this

Annotations
@SuppressWarnings:unchecked
See Also
assertValueSet(Collection)
assertValueSequenceback to summary
public final U assertValueSequence(Iterable<? extends T> sequence)

Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order.

Parameters
sequence:Iterable<? extends T>

the sequence of expected values in order

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValueSequenceOnlyback to summary
public final U assertValueSequenceOnly(Iterable<? extends T> sequence)

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating.

History: 2.1.14 - experimental

Parameters
sequence:Iterable<? extends T>

the sequence of expected values in order

Returns:U

this

Since
2.2
assertValueSetback to summary
public final U assertValueSet(Collection<? extends T> expected)

Assert that the TestObserver/TestSubscriber received only items that are in the specified collection as well, irrespective of the order they were received.

This helps asserting when the order of the values is not guaranteed, i.e., when merging asynchronous streams.

To ensure that only the expected items have been received, no more and no less, in any order, apply assertValueCount(int) with expected.size().

Parameters
expected:Collection<? extends T>

the collection of values expected in any order

Returns:U

this

Annotations
@SuppressWarnings:unchecked
assertValueSetOnlyback to summary
public final U assertValueSetOnly(Collection<? extends T> expected)

Assert that the TestObserver/TestSubscriber received only the specified values in any order without terminating.

History: 2.1.14 - experimental

Parameters
expected:Collection<? extends T>

the collection of values expected in any order

Returns:U

this

Since
2.2
assertValuesOnlyback to summary
public final U assertValuesOnly(T... values)

Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating.

History: 2.1.4 - experimental

Parameters
values:T[]

the values expected

Returns:U

this

Since
2.2
awaitback to summary
public final U await() throws InterruptedException

Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events.

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Exceptions
InterruptedException:
if the current thread is interrupted while waiting
See Also
awaitTerminalEvent()
awaitback to summary
public final boolean await(long time, TimeUnit unit) throws InterruptedException

Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.

Parameters
time:long

the waiting time

unit:TimeUnit

the time unit of the waiting time

Returns:boolean

true if the TestObserver/TestSubscriber terminated, false if timeout happened

Exceptions
InterruptedException:
if the current thread is interrupted while waiting
See Also
awaitTerminalEvent(long, TimeUnit)
awaitCountback to summary
public final U awaitCount(int atLeast)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates by sleeping 10 milliseconds at a time up to 5000 milliseconds of timeout.

History: 2.0.7 - experimental

Parameters
atLeast:int

the number of items expected at least

Returns:U

this

Since
2.1
See Also
awaitCount(int, Runnable, long)
awaitCountback to summary
public final U awaitCount(int atLeast, Runnable waitStrategy)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates by waiting according to the wait strategy and up to 5000 milliseconds of timeout.

History: 2.0.7 - experimental

Parameters
atLeast:int

the number of items expected at least

waitStrategy:Runnable

a Runnable called when the current received count hasn't reached the expected value and there was no terminal event either, see TestWaitStrategy for examples

Returns:U

this

Since
2.1
See Also
awaitCount(int, Runnable, long)
awaitCountback to summary
public final U awaitCount(int atLeast, Runnable waitStrategy, long timeoutMillis)

Await until the TestObserver/TestSubscriber receives the given number of items or terminates.

History: 2.0.7 - experimental

Parameters
atLeast:int

the number of items expected at least

waitStrategy:Runnable

a Runnable called when the current received count hasn't reached the expected value and there was no terminal event either, see TestWaitStrategy for examples

timeoutMillis:long

if positive, the await ends if the specified amount of time has passed no matter how many items were received

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
awaitDoneback to summary
public final U awaitDone(long time, TimeUnit unit)

Awaits until the internal latch is counted down.

If the wait times out or gets interrupted, the TestObserver/TestSubscriber is cancelled.

Parameters
time:long

the waiting time

unit:TimeUnit

the time unit of the waiting time

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Exceptions
RuntimeException:
wrapping an InterruptedException if the wait is interrupted
awaitTerminalEventback to summary
public final boolean awaitTerminalEvent()

Waits until the any terminal event has been received by this TestObserver/TestSubscriber or returns false if the wait has been interrupted.

Returns:boolean

true if the TestObserver/TestSubscriber terminated, false if the wait has been interrupted

awaitTerminalEventback to summary
public final boolean awaitTerminalEvent(long duration, TimeUnit unit)

Awaits the specified amount of time or until this TestObserver/TestSubscriber receives an onError or onComplete events, whichever happens first.

Parameters
duration:long

the waiting time

unit:TimeUnit

the time unit of the waiting time

Returns:boolean

true if the TestObserver/TestSubscriber terminated, false if timeout or interrupt happened

clearTimeoutback to summary
public final U clearTimeout()

Clears the timeout flag set by the await methods when they timed out.

History: 2.0.7 - experimental

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
See Also
isTimeout()
completionsback to summary
public final long completions()

Returns the number of times onComplete was called.

Returns:long

the number of times onComplete was called

errorCountback to summary
public final int errorCount()

Returns the number of onError exceptions received.

Returns:int

the number of onError exceptions received

errorsback to summary
public final List<Throwable> errors()

Returns a shared list of received onError exceptions.

Note that accessing the errors via certain methods of the List interface while the upstream is still actively emitting more items or errors may result in a ConcurrentModificationException.

The List#size() method will return the number of errors already received by this TestObserver/TestSubscriber in a thread-safe manner that can be read via List#get(int)) method (index range of 0 to List.size() - 1).

A view of the returned List can be created via List#subList(int, int) by using the bounds 0 (inclusive) to List#size() (exclusive) which, when accessed in a read-only fashion, should be also thread-safe and not throw any ConcurrentModificationException.

Returns:List<Throwable>

a list of received events onError exceptions

failback to summary
protected final AssertionError fail(String message)

Fail with the given message and add the sequence of errors as suppressed ones.

Note this is deliberately the only fail method. Most of the times an assertion would fail but it is possible it was due to an exception somewhere. This construct will capture those potential errors and report it along with the original failure.

Parameters
message:String

the message to use

Returns:AssertionError

AssertionError the prepared AssertionError instance

getEventsback to summary
public final List<List<Object>> getEvents()

Returns a list of 3 other lists: the first inner list contains the plain values received; the second list contains the potential errors and the final list contains the potential completions as Notifications.

Returns:List<List<Object>>

a list of (values, errors, completion-notifications)

Annotations
@SuppressWarnings:rawtypes, unchecked
isTerminatedback to summary
public final boolean isTerminated()

Returns true if TestObserver/TestSubscriber received any onError or onComplete events.

Returns:boolean

true if TestObserver/TestSubscriber received any onError or onComplete events

isTimeoutback to summary
public final boolean isTimeout()

Returns true if an await timed out.

Returns:boolean

true if one of the timeout-based await methods has timed out.

History: 2.0.7 - experimental

Since
2.1
See Also
clearTimeout(), assertTimeout(), assertNoTimeout()
lastThreadback to summary
public final Thread lastThread()

Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber.

Returns:Thread

the last thread which called the onXXX methods

valueAndClassback to summary
public static String valueAndClass(Object o)

Appends the class name to a non-null value.

Parameters
o:Object

the object

Returns:String

the string representation

valueCountback to summary
public final int valueCount()

Returns the number of onNext values received.

Returns:int

the number of onNext values received

valuesback to summary
public final List<T> values()

Returns a shared list of received onNext values.

Note that accessing the items via certain methods of the List interface while the upstream is still actively emitting more items may result in a ConcurrentModificationException.

The List#size() method will return the number of items already received by this TestObserver/TestSubscriber in a thread-safe manner that can be read via List#get(int)) method (index range of 0 to List.size() - 1).

A view of the returned List can be created via List#subList(int, int) by using the bounds 0 (inclusive) to List#size() (exclusive) which, when accessed in a read-only fashion, should be also thread-safe and not throw any ConcurrentModificationException.

Returns:List<T>

a list of received onNext values

withTagback to summary
public final U withTag(CharSequence tag)

Set the tag displayed along with an assertion failure's other state information.

History: 2.0.7 - experimental

Parameters
tag:CharSequence

the string to display (null won't print any tag)

Returns:U

this

Annotations
@SuppressWarnings:unchecked
Since
2.1
io.reactivex.observers back to summary

public sealed Enum BaseTestConsumer.TestWaitStrategy

extends Enum<BaseTestConsumer.TestWaitStrategy>
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Enumeration of default wait strategies when waiting for a specific number of items in BaseTestConsumer#awaitCount(int, Runnable).

History: 2.0.7 - experimental

Since
2.1

Field Summary

Modifier and TypeField and Description
public static final BaseTestConsumer.TestWaitStrategy
SLEEP_1000MS

The current thread sleeps for 1000 milliseconds.

public static final BaseTestConsumer.TestWaitStrategy
SLEEP_100MS

The current thread sleeps for 100 milliseconds.

public static final BaseTestConsumer.TestWaitStrategy
SLEEP_10MS

The current thread sleeps for 10 milliseconds.

public static final BaseTestConsumer.TestWaitStrategy
SLEEP_1MS

The current thread sleeps for 1 millisecond.

public static final BaseTestConsumer.TestWaitStrategy
SPIN

The wait loop will spin as fast as possible.

public static final BaseTestConsumer.TestWaitStrategy
YIELD

The current thread will be yielded.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public abstract void
run()

Redeclares java.lang.Runnable.run.

Runs this operation.
pack-priv static void
sleep(int millis)

public static BaseTestConsumer.TestWaitStrategy
public static BaseTestConsumer.TestWaitStrategy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

SLEEP_1000MSback to summary
public static final BaseTestConsumer.TestWaitStrategy SLEEP_1000MS

The current thread sleeps for 1000 milliseconds.

SLEEP_100MSback to summary
public static final BaseTestConsumer.TestWaitStrategy SLEEP_100MS

The current thread sleeps for 100 milliseconds.

SLEEP_10MSback to summary
public static final BaseTestConsumer.TestWaitStrategy SLEEP_10MS

The current thread sleeps for 10 milliseconds.

SLEEP_1MSback to summary
public static final BaseTestConsumer.TestWaitStrategy SLEEP_1MS

The current thread sleeps for 1 millisecond.

SPINback to summary
public static final BaseTestConsumer.TestWaitStrategy SPIN

The wait loop will spin as fast as possible.

YIELDback to summary
public static final BaseTestConsumer.TestWaitStrategy YIELD

The current thread will be yielded.

Constructor Detail

TestWaitStrategyback to summary
private TestWaitStrategy()

Method Detail

runback to summary
public abstract void run()

Redeclares java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
sleepback to summary
pack-priv static void sleep(int millis)
valueOfback to summary
public static BaseTestConsumer.TestWaitStrategy valueOf(String name)
valuesback to summary
public static BaseTestConsumer.TestWaitStrategy[] values()