public interface PublisherProbe<T>
Publisher
(Mono or Flux) for tests involving control flow. For instance, you might
have a Mono.switchIfEmpty(Mono) and you want to make sure that your code
branched into the "if empty" case. The contract of this interface does not cover what
signals the Publisher emits, although factory methods of(Publisher)
and empty() produce probes that do emit signals like a common sequence.
The PublisherProbe acts as a probe capturing subscription, cancellation and
request events. Later, it can be used post completion to check if that particular
probe was hit.
Even though TestPublisher implements PublisherProbe, prefer creating
probes through the static empty() and of(Publisher) methods.
This is because the TestPublisher exposes assertions from PublisherProbe
but still requires you to 1) use the TestPublisher emit methods
and 2) use the TestPublisher.Violation.CLEANUP_ON_TERMINATE in order for these assertions to
be usable post-completion...
| Modifier and Type | Interface and Description |
|---|---|
static class |
PublisherProbe.DefaultPublisherProbe<T> |
| Modifier and Type | Method and Description |
|---|---|
default void |
assertWasCancelled()
Check that the probe was cancelled at least once, or throw an
AssertionError. |
default void |
assertWasNotCancelled()
Check that the probe was never cancelled, or throw an
AssertionError. |
default void |
assertWasNotRequested()
Check that the probe was never requested, or throw an
AssertionError. |
default void |
assertWasNotSubscribed()
Check that the probe was never subscribed to, or throw an
AssertionError. |
default void |
assertWasRequested()
Check that the probe was requested at least once, or throw an
AssertionError. |
default void |
assertWasSubscribed()
Check that the probe was subscribed to at least once, or throw an
AssertionError. |
static <T> PublisherProbe<T> |
empty()
Create a
PublisherProbe of which flux() and mono()
versions will simply complete, capturing subscription, cancellation and request
events around them. |
Flux<T> |
flux()
Return a
Flux version of the probe. |
Mono<T> |
mono()
Return a
Mono version of the probe. |
static <T> PublisherProbe<T> |
of(Publisher<? extends T> source)
Create a
PublisherProbe out of a Publisher, ensuring that its
flux() and mono() versions will propagate signals from this
publisher while capturing subscription, cancellation and request events around it. |
long |
subscribeCount() |
boolean |
wasCancelled() |
boolean |
wasRequested() |
boolean |
wasSubscribed() |
default void assertWasNotSubscribed()
AssertionError.default void assertWasSubscribed()
AssertionError.default void assertWasNotCancelled()
AssertionError.default void assertWasCancelled()
AssertionError.default void assertWasNotRequested()
AssertionError.default void assertWasRequested()
AssertionError.Mono<T> mono()
Mono version of the probe. Note all calls to mono() and
flux() are backed by the same PublisherProbe and as such influence
a single state.
If the probe was created out of a Publisher, the Flux
will forward the signals from this publisher (up to one Subscriber.onNext(Object) though).
Otherwise it will simply complete.
Mono version of the probe.Flux<T> flux()
Flux version of the probe. Note all calls to mono() and
flux() are backed by the same PublisherProbe and as such influence
a single state.
If the probe was created out of a Publisher, the Flux
will forward the signals from this publisher
Otherwise it will simply complete.
Flux version of the probe.boolean wasSubscribed()
long subscribeCount()
boolean wasCancelled()
boolean wasRequested()
static <T> PublisherProbe<T> of(Publisher<? extends T> source)
PublisherProbe out of a Publisher, ensuring that its
flux() and mono() versions will propagate signals from this
publisher while capturing subscription, cancellation and request events around it.T - the type of the source publisher.source - the source publisher to mimic and probe.static <T> PublisherProbe<T> empty()
PublisherProbe of which flux() and mono()
versions will simply complete, capturing subscription, cancellation and request
events around them.T - the type of the empty probe.