T
- Type of the result of this Subscriber
.public final class TestSingleSubscriber<T> extends java.lang.Object implements SingleSource.Subscriber<T>, Cancellable
SingleSource.Subscriber
that can be used to verify the signals delivered by a SingleSource
.
The Cancellable
received by onSubscribe(Cancellable)
is exposed through the Cancellable
interface methods.
TestSingleSubscriber.Builder
Modifier and Type | Class and Description |
---|---|
static class |
TestSingleSubscriber.Builder<T>
Allows for creating
TestSingleSubscriber s with non-default settings. |
IGNORE_CANCEL
Constructor and Description |
---|
TestSingleSubscriber()
Create a
TestSingleSubscriber with the defaults. |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the
Cancellable received by onSubscribe(Cancellable) . |
Cancellable |
cancellable()
Returns the
Cancellable received by onSubscribe(Cancellable) , or null if no
Cancellable has been received. |
boolean |
cancellableReceived()
|
java.lang.Throwable |
error()
Get the last
Throwable received by onError(Throwable) . |
boolean |
hasResult()
|
boolean |
isErrored()
|
boolean |
isSuccess()
|
void |
onError(java.lang.Throwable t)
Failed terminal state.
|
void |
onSubscribe(Cancellable s)
Called when the associated
SingleSource is subscribed via SingleSource.subscribe(Subscriber) . |
void |
onSuccess(T result)
Success terminal state.
|
T |
result()
Get the result received through
onSuccess(Object) . |
java.lang.Throwable |
takeError()
Get the last
Throwable received by onError(Throwable) , and clears the internal value. |
T |
takeResult()
Get the result received through
onSuccess(Object) , and clear the internal value. |
public TestSingleSubscriber()
TestSingleSubscriber
with the defaults.TestSingleSubscriber.Builder
public boolean cancellableReceived()
true
if onSubscribe(Cancellable)
has been called, false
otherwise.public Cancellable cancellable()
Cancellable
received by onSubscribe(Cancellable)
, or null
if no
Cancellable
has been received.Cancellable
received by onSubscribe(Cancellable)
, or null
if no
Cancellable
has been received.public boolean hasResult()
true
if onSuccess(Object)
was the most recently received signal, false
otherwise.@Nullable public T result()
onSuccess(Object)
.@Nullable public T takeResult()
onSuccess(Object)
, and clear the internal value.@Nullable public java.lang.Throwable error()
Throwable
received by onError(Throwable)
.Throwable
, or null
if none have been received.@Nullable public java.lang.Throwable takeError()
Throwable
received by onError(Throwable)
, and clears the internal value.Throwable
, or null
if none have been received.public boolean isSuccess()
true
if onSuccess(Object)
was the most recently received signal, false
otherwise.public boolean isErrored()
true
if onError(Throwable)
was the most recently received signal, false
otherwise.public void cancel()
Cancellable
received by onSubscribe(Cancellable)
.
If no Cancellable
has been received yet, the cancellation will be buffered, and the
Cancellable
will be cancelled when it is received.
cancel
in interface Cancellable
public void onSubscribe(Cancellable s)
SingleSource.Subscriber
SingleSource
is subscribed via SingleSource.subscribe(Subscriber)
.onSubscribe
in interface SingleSource.Subscriber<T>
s
- A Cancellable
that can be used to cancel the asynchronous computation for
this subscriber.public void onSuccess(T result)
SingleSource.Subscriber
No further events will be sent.
onSuccess
in interface SingleSource.Subscriber<T>
result
- of the SingleSource
.public void onError(java.lang.Throwable t)
SingleSource.Subscriber
No further events will be sent.
onError
in interface SingleSource.Subscriber<T>
t
- the throwable signaled.