public final class TestSubscriberBuilder extends Object
TestSubscriber
, also
allowing for a Fuseable.ConditionalSubscriber
variant.
Notably, it allows the created instance to enforce fusion compatibility
(by assuming a Fuseable
source publisher and expecting a
Fuseable.QueueSubscription
).
See TestSubscriber.builder()
to obtain a new builder.
Note that all methods mutate the builder configuration, so reuse is discouraged.
Modifier and Type | Method and Description |
---|---|
<T> TestSubscriber<T> |
build()
Create a
TestSubscriber according to this builder. |
<T> ConditionalTestSubscriber<T> |
buildConditional(Predicate<? super T> tryOnNext)
Create a
Fuseable.ConditionalSubscriber variant of TestSubscriber according
to this builder. |
TestSubscriberBuilder |
contextPut(Object key,
Object value)
Enrich the
Context with a single entry. |
TestSubscriberBuilder |
contextPutAll(ContextView toAdd)
Enrich the
Context by putting all entries of the given ContextView in it. |
TestSubscriberBuilder |
initialRequest(long initialRequest)
Set the request to be made upon receiving the
Subscription
in Subscriber.onSubscribe(Subscription) . |
TestSubscriberBuilder |
initialRequestUnbounded()
Set the request to be made upon receiving the
Subscription
in Subscriber.onSubscribe(Subscription) to be an
unbounded request, ie. |
TestSubscriberBuilder |
requireFusion(int exactMode)
Expect fusion to be possible with the
TestSubscriber , with Fuseable.NONE ) being a special case. |
TestSubscriberBuilder |
requireFusion(int requestedMode,
int negotiatedMode)
Expect fusion to be possible with the
TestSubscriber , with both parameters set to Fuseable.NONE being a special case. |
TestSubscriberBuilder |
requireNotFuseable()
|
public TestSubscriberBuilder contextPut(Object key, Object value)
Context
with a single entry.key
- the key to put/set in the Context
of the future TestSubscriber
value
- the value to associate with the keyContext
public TestSubscriberBuilder contextPutAll(ContextView toAdd)
Context
by putting all entries of the given ContextView
in it.toAdd
- the ContextView
to add to the Context
of the future TestSubscriber
ContextView
's key/value pairs added to the Context
public TestSubscriberBuilder initialRequest(long initialRequest)
Subscription
in Subscriber.onSubscribe(Subscription)
. Default is Long.MAX_VALUE
.initialRequest
- the request to be made at subscriptionpublic TestSubscriberBuilder initialRequestUnbounded()
Subscription
in Subscriber.onSubscribe(Subscription)
to be an
unbounded request, ie. Long.MAX_VALUE
.public TestSubscriberBuilder requireFusion(int exactMode)
TestSubscriber
, with Fuseable.NONE
) being a special case.
Fusion will be negotiated at subscription, enforcing the need for a Fuseable.QueueSubscription
to be passed.
Furthermore, the fusion mode returned from the negotiation with the Fuseable.QueueSubscription
is expected to be the same as the provided mode.
Use requireFusion(Fuseable.NONE)
to remove any previously fusion requirement, as well as
removing type enforcement on the subscription (a vanilla Subscription
becomes acceptable).
Use requireNotFuseable()
to strictly enforce that the Subscription
MUST NOT be a Fuseable.QueueSubscription
.
exactMode
- the requested fusion mode, expected in return from the negotiation with the Fuseable.QueueSubscription
public TestSubscriberBuilder requireFusion(int requestedMode, int negotiatedMode)
TestSubscriber
, with both parameters set to Fuseable.NONE
being a special case.
Fusion will be negotiated at subscription, enforcing the need for a Fuseable.QueueSubscription
to be passed.
Furthermore, the negotiatedMode
is expected to be negotiated by the subscription
in response to requesting requestedMode
.
Use requireFusion(Fuseable.NONE, Fuseable.NONE)
to remove any previously fusion requirement, as well as
removing type enforcement on the subscription (a vanilla Subscription
becomes acceptable).
Use requireNotFuseable()
to strictly enforce that the Subscription
MUST NOT be a Fuseable.QueueSubscription
.
requestedMode
- the fusion mode requested to the Fuseable.QueueSubscription
negotiatedMode
- the fusion mode expected from the negotiation with the Fuseable.QueueSubscription
public TestSubscriberBuilder requireNotFuseable()
Subscription
passed to the TestSubscriber
isn't a Fuseable.QueueSubscription
.
This is stricter than requireFusion(Fuseable.NONE, Fuseable.NONE)
, which merely disables fusion but still accepts
the incoming subscription to be a QueueSubscription.Fuseable.QueueSubscription
public <T> ConditionalTestSubscriber<T> buildConditional(Predicate<? super T> tryOnNext)
Fuseable.ConditionalSubscriber
variant of TestSubscriber
according
to this builder.
The provided Predicate
will be used as the implementation
of Fuseable.ConditionalSubscriber.tryOnNext(Object)
.T
- the type of elements received by the TestSubscriber
, defined by the predicatetryOnNext
- the Predicate
to use as the tryOnNext
implementationConditionalTestSubscriber
public <T> TestSubscriber<T> build()
TestSubscriber
according to this builder.T
- the type of elements to be received by the subscriberTestSubscriber