Class AssertMulti<T>

java.lang.Object
io.smallrye.mutiny.helpers.test.AssertMulti<T>
Type Parameters:
T - the type of items emitted by the Multi

@Experimental("This is an experimental API in Mutiny 3.x") public final class AssertMulti<T> extends Object
A declarative step verifier for Multi streams.

Build a sequence of expectations, then call verify() to subscribe and validate each step:

 AssertMulti.create(multi)
         .expectNext(1, 2, 3)
         .expectNextMatches(i -> i > 3, "greater than 3")
         .expectComplete()
         .verify();
 
By default, the subscriber requests Long.MAX_VALUE items (unbounded demand). Use withInitialRequest(0) for explicit backpressure testing:
 AssertMulti.create(multi)
         .withInitialRequest(0)
         .thenRequest(2)
         .expectNext(1, 2)
         .thenRequest(1)
         .expectNext(3)
         .expectComplete()
         .verify();
 
  • Method Details

    • create

      public static <T> AssertMulti<T> create(Multi<T> multi)
      Create a new AssertMulti for the given Multi.
      Type Parameters:
      T - the item type
      Parameters:
      multi - the Multi to verify, must not be null
      Returns:
      a new AssertMulti
    • create

      public static <T> AssertMulti<T> create(Multi<T> multi, Context context)
      Create a new AssertMulti for the given Multi with a subscription Context.
      Type Parameters:
      T - the item type
      Parameters:
      multi - the Multi to verify, must not be null
      context - the context, must not be null
      Returns:
      a new AssertMulti
    • withInitialRequest

      public AssertMulti<T> withInitialRequest(long n)
      Set the initial number of items to request from upstream on subscription.

      Defaults to Long.MAX_VALUE (unbounded). Set to 0 to disable initial demand and control backpressure explicitly with thenRequest(long).

      Parameters:
      n - the initial request count, must be >= 0
      Returns:
      this AssertMulti
    • expectNext

      public AssertMulti<T> expectNext(T expected)
      Expect the next item to be equal to expected.
      Parameters:
      expected - the expected item
      Returns:
      this AssertMulti
    • expectNext

      @SafeVarargs public final AssertMulti<T> expectNext(T... expected)
      Expect the next items to be equal to expected in order.
      Parameters:
      expected - the expected items
      Returns:
      this AssertMulti
    • expectNextMatches

      public AssertMulti<T> expectNextMatches(Predicate<? super T> predicate, String description)
      Expect the next item to match the given predicate.
      Parameters:
      predicate - the predicate to test, must not be null
      description - a description for error messages
      Returns:
      this AssertMulti
    • expectNextCount

      public AssertMulti<T> expectNextCount(int count)
      Expect that the next count items are received (values are not checked).
      Parameters:
      count - the number of items to expect, must be positive
      Returns:
      this AssertMulti
    • consumeNext

      public AssertMulti<T> consumeNext(Consumer<? super T> consumer)
      Consume and inspect the next item. The consumer should throw an AssertionError if the item is not acceptable.
      Parameters:
      consumer - the consumer, must not be null
      Returns:
      this AssertMulti
    • consumeNextItems

      public AssertMulti<T> consumeNextItems(int count, Consumer<? super List<T>> consumer)
      Consume and inspect the next count items as a list. The consumer should throw an AssertionError if the items are not acceptable.
      Parameters:
      count - the number of items to collect, must be positive
      consumer - the consumer, must not be null
      Returns:
      this AssertMulti
    • thenRequest

      public AssertMulti<T> thenRequest(long n)
      Request n items from upstream. Use with withInitialRequest(0) for explicit backpressure testing.
      Parameters:
      n - the number of items to request, must be positive
      Returns:
      this AssertMulti
    • expectComplete

      public AssertMulti<T> expectComplete()
      Expect the stream to complete.
      Returns:
      this AssertMulti
    • expectFailure

      public AssertMulti<T> expectFailure()
      Expect the stream to fail with any failure.
      Returns:
      this AssertMulti
    • expectFailure

      public AssertMulti<T> expectFailure(Class<? extends Throwable> type)
      Expect the stream to fail with a specific failure type.
      Parameters:
      type - the expected failure type
      Returns:
      this AssertMulti
    • expectFailure

      public AssertMulti<T> expectFailure(Class<? extends Throwable> type, String messageSubstring)
      Expect the stream to fail with a specific failure type and message substring.
      Parameters:
      type - the expected failure type
      messageSubstring - a substring expected in the failure message
      Returns:
      this AssertMulti
    • expectFailure

      public AssertMulti<T> expectFailure(Consumer<Throwable> validator)
      Expect the stream to fail and validate the failure with a consumer.
      Parameters:
      validator - the failure validator, must not be null
      Returns:
      this AssertMulti
    • thenCancel

      public AssertMulti<T> thenCancel()
      Cancel the subscription at this point in the step sequence.
      Returns:
      this AssertMulti
    • verify

      public void verify()
      Subscribe to the Multi and execute all steps with the default timeout.
      Throws:
      AssertionError - if any step fails
    • verify

      public void verify(Duration timeout)
      Subscribe to the Multi and execute all steps with the given timeout per step.
      Parameters:
      timeout - the maximum wait time per step, must not be null
      Throws:
      AssertionError - if any step fails