public abstract class TestPublisher<T> extends Object implements Publisher<T>
Publisher
that you can directly manipulate, triggering
onNext
, onComplete
and
onError
events, for testing purposes.
You can assert the state of the publisher using its assertXXX
methods,
usually inside a StepVerifier
's
then
callback.
The TestPublisher can also be made more lenient towards the RS spec
and allow "spec violations", as enumerated in TestPublisher.Violation
. Use the
createNoncompliant(Violation, Violation...)
factory method to create such
a misbehaving publisher.
Modifier and Type | Class and Description |
---|---|
static class |
TestPublisher.Violation
Possible misbehavior for a
TestPublisher . |
Constructor and Description |
---|
TestPublisher() |
Modifier and Type | Method and Description |
---|---|
abstract TestPublisher<T> |
assertCancelled()
Asserts that this publisher has had at least one subscriber that has been cancelled.
|
abstract TestPublisher<T> |
assertCancelled(int n)
Asserts that this publisher has had at least n subscribers that have been cancelled.
|
abstract TestPublisher<T> |
assertMinRequested(long n)
Assert that the current minimum request of all this publisher's subscribers
is >=
n . |
abstract TestPublisher<T> |
assertNoRequestOverflow()
Asserts that this publisher has had no subscriber with request overflow.
|
abstract TestPublisher<T> |
assertNoSubscribers()
Asserts that this publisher has no subscribers.
|
abstract TestPublisher<T> |
assertNotCancelled()
Asserts that this publisher has had no cancelled subscribers.
|
abstract TestPublisher<T> |
assertRequestOverflow()
Asserts that this publisher has had subscriber that saw request overflow,
that is received an onNext event despite having a requested amount of 0 at
the time.
|
abstract TestPublisher<T> |
assertSubscribers()
Asserts that this publisher has subscribers.
|
abstract TestPublisher<T> |
assertSubscribers(int n)
Asserts that this publisher has exactly n subscribers.
|
abstract TestPublisher<T> |
complete()
Triggers
completion of this publisher. |
static <T> TestPublisher<T> |
create()
Create a standard
TestPublisher . |
static <T> TestPublisher<T> |
createNoncompliant(TestPublisher.Violation first,
TestPublisher.Violation... rest)
Create a
noncompliant TestPublisher
with a given set of reactive streams spec violations that will be overlooked. |
TestPublisher<T> |
emit(T... values)
Combine emitting items and completing this publisher.
|
abstract TestPublisher<T> |
error(Throwable t)
Triggers an
error signal to the subscribers. |
abstract reactor.core.publisher.Flux<T> |
flux()
Convenience method to wrap this
TestPublisher to a Flux . |
abstract reactor.core.publisher.Mono<T> |
mono()
Convenience method to wrap this
TestPublisher to a Mono . |
abstract TestPublisher<T> |
next(T value)
Send 1
onNext signal to the subscribers. |
TestPublisher<T> |
next(T first,
T... rest)
Send 1-n
onNext signals to the subscribers. |
public static <T> TestPublisher<T> create()
TestPublisher
.T
- the type of the publisherTestPublisher
public static <T> TestPublisher<T> createNoncompliant(TestPublisher.Violation first, TestPublisher.Violation... rest)
noncompliant
TestPublisher
with a given set of reactive streams spec violations that will be overlooked.T
- the type of the publisherfirst
- the first allowed TestPublisher.Violation
rest
- additional optional violationsTestPublisher
public abstract reactor.core.publisher.Flux<T> flux()
TestPublisher
to a Flux
.public abstract reactor.core.publisher.Mono<T> mono()
TestPublisher
to a Mono
.public abstract TestPublisher<T> assertMinRequested(long n)
n
.n
- the expected minimum requestTestPublisher
for chaining.public abstract TestPublisher<T> assertSubscribers()
TestPublisher
for chaining.public abstract TestPublisher<T> assertSubscribers(int n)
n
- the expected number of subscribersTestPublisher
for chaining.public abstract TestPublisher<T> assertNoSubscribers()
TestPublisher
for chaining.public abstract TestPublisher<T> assertCancelled()
TestPublisher
for chaining.public abstract TestPublisher<T> assertCancelled(int n)
n
- the expected number of subscribers to have been cancelled.TestPublisher
for chaining.public abstract TestPublisher<T> assertNotCancelled()
TestPublisher
for chaining.public abstract TestPublisher<T> assertRequestOverflow()
TestPublisher
for chaining.public abstract TestPublisher<T> assertNoRequestOverflow()
TestPublisher
for chaining.public abstract TestPublisher<T> next(T value)
onNext
signal to the subscribers.value
- the item to emitTestPublisher
for chaining.public abstract TestPublisher<T> error(Throwable t)
error
signal to the subscribers.t
- the Throwable
to triggerTestPublisher
for chaining.public abstract TestPublisher<T> complete()
completion
of this publisher.TestPublisher
for chaining.@SafeVarargs public final TestPublisher<T> next(T first, T... rest)
onNext
signals to the subscribers.first
- the first item to emitrest
- the optional remaining items to emitTestPublisher
for chaining.next
@SafeVarargs public final TestPublisher<T> emit(T... values)
values
- the values to emit to subscribersTestPublisher
for chaining.next
,
complete