Package reactor.test

Class StepVerifierOptions

java.lang.Object
reactor.test.StepVerifierOptions

public class StepVerifierOptions extends Object
Options for a StepVerifier, including the initial request amount, VirtualTimeScheduler supplier and toggles for some checks.
Author:
Simon Basle
  • Method Details

    • create

      public static StepVerifierOptions create()
      Create a new default set of options for a StepVerifier that can be tuned using the various available non-getter methods (which can be chained).
    • copy

      public StepVerifierOptions copy()
      Make a copy of this StepVerifierOptions instance.
      Returns:
      a copy of the options that can be further mutated without impacting the original
    • checkUnderRequesting

      public StepVerifierOptions checkUnderRequesting(boolean enabled)
      Activate or deactivate the StepVerifier check of request amount being too low. Defauts to true.
      Parameters:
      enabled - true if the check should be enabled.
      Returns:
      this instance, to continue setting the options.
    • isCheckUnderRequesting

      public boolean isCheckUnderRequesting()
      Returns:
      true if the StepVerifier receiving these options should activate the check of request amount being too low.
    • initialRequest

      public StepVerifierOptions initialRequest(long initialRequest)
      Set the amount the StepVerifier should request initially. Defaults to unbounded request (Long.MAX_VALUE).
      Parameters:
      initialRequest - the initial request amount.
      Returns:
      this instance, to continue setting the options.
    • getInitialRequest

      public long getInitialRequest()
      Returns:
      the initial request amount to be made by the StepVerifier receiving these options.
    • valueFormatter

      public StepVerifierOptions valueFormatter(@Nullable ValueFormatters.ToStringConverter valueFormatter)
      Set up a custom value formatter to be used in error messages when presenting expected and actual values. This is intended for classes that have obscure Object.toString() implementation that cannot be overridden.

      This is a Function capable of formatting an arbitrary Object to String, with the intention of detecting elements from the sequence under test and applying customized String conversion to them (and simply calling Object.toString() on other objects).

      See ValueFormatters for factories of such functions.

      Parameters:
      valueFormatter - the custom value to String formatter, or null to deactivate custom formatting
      Returns:
      this instance, to continue setting the options
    • getValueFormatter

      public @Nullable ValueFormatters.ToStringConverter getValueFormatter()
      Get the custom object formatter to use when producing messages. The formatter should be able to work with any Object, usually filtering types matching the content of the sequence under test, and applying a simple String conversion on other objects.
      Returns:
      the custom value formatter, or null if no specific formatting has been defined.
    • extractor

      public <T> StepVerifierOptions extractor(ValueFormatters.Extractor<T> extractor)
      Add an ValueFormatters.Extractor, replacing any existing ValueFormatters.Extractor that targets the same Class (as in ValueFormatters.Extractor.getTargetClass()).

      Note that by default, default extractors for Signal, Iterable and Object[] are in place.

      Type Parameters:
      T - the type of container considered by this extractor
      Parameters:
      extractor - the extractor to add / set
      Returns:
      this instance, to continue setting the options
    • getExtractors

      public Collection<ValueFormatters.Extractor<?>> getExtractors()
      Get the list of value extractors added to the options, including default ones at the end (unless they've been individually replaced).

      The Collection is a copy, and mutating the collection doesn't mutate the configured extractors in this StepVerifierOptions.

      Returns:
      the collection of value ValueFormatters.Extractor
    • virtualTimeSchedulerSupplier

      public StepVerifierOptions virtualTimeSchedulerSupplier(Supplier<? extends VirtualTimeScheduler> vtsLookup)
      Set a supplier for a VirtualTimeScheduler, which is mandatory for a StepVerifier to work with virtual time. Defaults to null.
      Parameters:
      vtsLookup - the supplier of VirtualTimeScheduler to use.
      Returns:
      this instance, to continue setting the options.
    • getVirtualTimeSchedulerSupplier

      public @Nullable Supplier<? extends VirtualTimeScheduler> getVirtualTimeSchedulerSupplier()
      Returns:
      the supplier of VirtualTimeScheduler to be used by the StepVerifier receiving these options.
    • withInitialContext

      public StepVerifierOptions withInitialContext(Context context)
      Set an initial Context to be propagated by the StepVerifier when it subscribes to the sequence under test.
      Parameters:
      context - the Context to propagate.
      Returns:
      this instance, to continue setting the options.
    • getInitialContext

      public @Nullable Context getInitialContext()
      Returns:
      the Context to be propagated initially by the StepVerifier.
    • scenarioName

      public StepVerifierOptions scenarioName(@Nullable String scenarioName)
      Give a name to the whole scenario tested by the configured StepVerifier. That name would be mentioned in exceptions and assertion errors raised by the StepVerifier, allowing to better distinguish error sources in unit tests where multiple StepVerifier are used.
      Parameters:
      scenarioName - the name of the scenario, null to deactivate
      Returns:
      this instance, to continue setting the options.
    • getScenarioName

      public @Nullable String getScenarioName()
      Returns:
      the name given to the configured StepVerifier, or null if none.