Interface TestSubscriber<T>

All Superinterfaces:
CoreSubscriber<T>, Scannable, Subscriber<T>
All Known Subinterfaces:
ConditionalTestSubscriber<T>

public interface TestSubscriber<T> extends CoreSubscriber<T>, Scannable
A CoreSubscriber that can be attached to any Publisher to later assert which events occurred at runtime. This can be used as an alternative to StepVerifier for more complex scenarios, e.g. more than one possible outcome, racing...

The subscriber can be fine tuned with a builder(), which also allows to produce a Fuseable.ConditionalSubscriber variant if needed.

Subscriber-inherited methods never throw, but a few failure conditions might be met, which fall into two categories.

The first category are "protocol errors": when the occurrence of an incoming signal doesn't follow the Reactive Streams specification. The case must be covered explicitly in the specification, and leads to the signal being added to the getProtocolErrors() list. All protocol errors imply that the Publisher has terminated already. The list of detected protocol errors is:

The second category are "subscription failures", which are the only ones for which TestSubscriber internally performs an assertion. These failure conditions always lead to a cancellation of the subscription and are represented as an AssertionError. The assertion error is thrown by all the getXxx and isXxx accessors, the block() methods and the expectTerminalError()/expectTerminalSignal() methods. The possible subscription failures are:

  • the TestSubscriber has already received a Subscription (ie. it is being reused). Both subscriptions are cancelled.
  • the incoming Subscription is not capable of fusion, but fusion was required by the user
  • the incoming Subscription is capable of fusion, but this was forbidden by the user
  • the incoming Subscription is capable of fusion, but the negotiated fusion mode is not the one required by the user
  • onNext(null) is received, which should denote ASYNC fusion, but ASYNC fusion hasn't been established
Author:
Simon Baslé