Interface PublisherProbe<T>
- All Known Implementing Classes:
PublisherProbe.DefaultPublisherProbe,TestPublisher
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...
- Author:
- Simon Baslé
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault voidCheck that the probe was cancelled at least once, or throw anAssertionError.default voidCheck that the probe was never cancelled, or throw anAssertionError.default voidCheck that the probe was never requested, or throw anAssertionError.default voidCheck that the probe was never subscribed to, or throw anAssertionError.default voidCheck that the probe was requested at least once, or throw anAssertionError.default voidCheck that the probe was subscribed to at least once, or throw anAssertionError.static <T> PublisherProbe<T>empty()Create aPublisherProbeof whichflux()andmono()versions will simply complete, capturing subscription, cancellation and request events around them.flux()Return aFluxversion of the probe.mono()Return aMonoversion of the probe.static <T> PublisherProbe<T>Create aPublisherProbeout of aPublisher, ensuring that itsflux()andmono()versions will propagate signals from this publisher while capturing subscription, cancellation and request events around it.longbooleanbooleanboolean
-
Method Details
-
assertWasNotSubscribed
default void assertWasNotSubscribed()Check that the probe was never subscribed to, or throw anAssertionError. -
assertWasSubscribed
default void assertWasSubscribed()Check that the probe was subscribed to at least once, or throw anAssertionError. -
assertWasNotCancelled
default void assertWasNotCancelled()Check that the probe was never cancelled, or throw anAssertionError. -
assertWasCancelled
default void assertWasCancelled()Check that the probe was cancelled at least once, or throw anAssertionError. -
assertWasNotRequested
default void assertWasNotRequested()Check that the probe was never requested, or throw anAssertionError. -
assertWasRequested
default void assertWasRequested()Check that the probe was requested at least once, or throw anAssertionError. -
mono
Return aMonoversion of the probe. Note all calls to mono() andflux()are backed by the samePublisherProbeand as such influence a single state.If the probe was
created out of a Publisher, theFluxwill forward the signals from this publisher (up to oneSubscriber.onNext(Object)though).Otherwiseit will simply complete.- Returns:
- a
Monoversion of the probe.
-
flux
Return aFluxversion of the probe. Note all calls tomono()and flux() are backed by the samePublisherProbeand as such influence a single state.If the probe was
created out of a Publisher, theFluxwill forward the signals from this publisherOtherwiseit will simply complete.- Returns:
- a
Fluxversion of the probe.
-
wasSubscribed
boolean wasSubscribed()- Returns:
- true if the probe was subscribed to at least once.
-
subscribeCount
long subscribeCount()- Returns:
- how many times probe was subscribed
-
wasCancelled
boolean wasCancelled()- Returns:
- true if the probe was cancelled to at least once.
-
wasRequested
boolean wasRequested()- Returns:
- true if the probe was requested at least once.
-
of
Create aPublisherProbeout of aPublisher, ensuring that itsflux()andmono()versions will propagate signals from this publisher while capturing subscription, cancellation and request events around it.- Type Parameters:
T- the type of the source publisher.- Parameters:
source- the source publisher to mimic and probe.- Returns:
- a probe that mimics the publisher.
-
empty
Create aPublisherProbeof whichflux()andmono()versions will simply complete, capturing subscription, cancellation and request events around them.- Type Parameters:
T- the type of the empty probe.- Returns:
- a probe that mimics an empty publisher.
-