T
- Type of items received by this Subscriber
.public final class TestPublisherSubscriber<T> extends java.lang.Object implements PublisherSource.Subscriber<T>, PublisherSource.Subscription
PublisherSource.Subscriber
that can be used to verify the signals delivered by a PublisherSource
. By default, it
asserts that items are not delivered without sufficient demand. (This can be disabled with
TestPublisherSubscriber.Builder.disableDemandCheck()
.)
The PublisherSource.Subscription
received by #onSubscribe(Subscription)
is exposed through the PublisherSource.Subscription
interface methods.
TestPublisherSubscriber.Builder
Modifier and Type | Class and Description |
---|---|
static class |
TestPublisherSubscriber.Builder<T>
Allows for creating
TestPublisherSubscriber s with non-default settings. |
IGNORE_CANCEL
Constructor and Description |
---|
TestPublisherSubscriber()
Create a
TestPublisherSubscriber with the defaults. |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the
PublisherSource.Subscription received by #onSubscribe(Subscription) . |
java.lang.Throwable |
error()
Get the last
Throwable received by onError(Throwable) . |
boolean |
isCompleted()
|
boolean |
isErrored()
|
boolean |
isTerminated()
|
java.util.List<T> |
items()
Get the list of items received through
onNext(Object) . |
void |
onComplete()
Callback to signal completion of the
PublisherSource for this Subscriber . |
void |
onError(java.lang.Throwable t)
Callback to receive an
error for this Subscriber . |
void |
onNext(T item)
Callback to receive a
data element for this Subscriber . |
void |
onSubscribe(PublisherSource.Subscription s)
Callback to receive a
PublisherSource.Subscription for this Subscriber . |
void |
request(long n)
|
PublisherSource.Subscription |
subscription()
Returns the
PublisherSource.Subscription received by #onSubscribe(Subscription) , or null if no
PublisherSource.Subscription has been received. |
boolean |
subscriptionReceived()
Returns
true if #onSubscribe(Subscription) has been called, false otherwise. |
java.lang.Throwable |
takeError()
Get the last
Throwable received by onError(Throwable) , and clears the internal value. |
java.util.List<T> |
takeItems()
Get the list of items received through
onNext(Object) , and clear the internal list. |
TerminalNotification |
takeTerminal()
Get the last
TerminalNotification onError(Throwable) or onComplete() received, and
clears the internal value. |
TerminalNotification |
terminal()
|
public TestPublisherSubscriber()
TestPublisherSubscriber
with the defaults.TestPublisherSubscriber.Builder
public boolean subscriptionReceived()
true
if #onSubscribe(Subscription)
has been called, false
otherwise.true
if #onSubscribe(Subscription)
has been called, false
otherwise.public PublisherSource.Subscription subscription()
PublisherSource.Subscription
received by #onSubscribe(Subscription)
, or null
if no
PublisherSource.Subscription
has been received.PublisherSource.Subscription
received by #onSubscribe(Subscription)
, or null
if no
PublisherSource.Subscription
has been received.public java.util.List<T> items()
onNext(Object)
.public java.util.List<T> takeItems()
onNext(Object)
, and clear the internal list.@Nullable public TerminalNotification terminal()
TerminalNotification
, or null
if none have been received.@Nullable public TerminalNotification takeTerminal()
TerminalNotification
onError(Throwable)
or onComplete()
received, and
clears the internal value.TerminalNotification
, or null
if none have been received.@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 isCompleted()
true
if onComplete()
was the most recently received terminal signal, false
otherwise.public boolean isErrored()
true
if onError(Throwable)
was the most recently received terminal signal,
false
otherwise.public boolean isTerminated()
true
if either onComplete()
or onError(Throwable)
have been received,
false
otherwise.public void request(long n)
n
items via the PublisherSource.Subscription
received by #onSubscribe(Subscription)
.
If no PublisherSource.Subscription
has been received yet, requests will be buffered and sent once one is received.
request
in interface PublisherSource.Subscription
n
- Number of items to request.public void cancel()
PublisherSource.Subscription
received by #onSubscribe(Subscription)
.
If no PublisherSource.Subscription
has been received yet, the cancellation will be buffered, and the
PublisherSource.Subscription
will be cancelled when it is received.
cancel
in interface Cancellable
public void onSubscribe(PublisherSource.Subscription s)
PublisherSource.Subscriber
PublisherSource.Subscription
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onSubscribe
in interface PublisherSource.Subscriber<T>
s
- PublisherSource.Subscription
for this Subscriber
.public void onNext(T item)
PublisherSource.Subscriber
data
element for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onNext
in interface PublisherSource.Subscriber<T>
item
- A data
element.public void onError(java.lang.Throwable t)
PublisherSource.Subscriber
error
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onError
in interface PublisherSource.Subscriber<T>
t
- error
for this Subscriber
.public void onComplete()
PublisherSource.Subscriber
PublisherSource
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onComplete
in interface PublisherSource.Subscriber<T>