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 Summary
Modifier and TypeMethodDescriptionconsumeNext(Consumer<? super T> consumer) Consume and inspect the next item.consumeNextItems(int count, Consumer<? super List<T>> consumer) Consume and inspect the nextcountitems as a list.static <T> AssertMulti<T> Create a newAssertMultifor the givenMulti.static <T> AssertMulti<T> Expect the stream to complete.Expect the stream to fail with any failure.expectFailure(Class<? extends Throwable> type) Expect the stream to fail with a specific failure type.expectFailure(Class<? extends Throwable> type, String messageSubstring) Expect the stream to fail with a specific failure type and message substring.expectFailure(Consumer<Throwable> validator) Expect the stream to fail and validate the failure with a consumer.expectNext(T expected) Expect the next item to be equal toexpected.final AssertMulti<T> expectNext(T... expected) Expect the next items to be equal toexpectedin order.expectNextCount(int count) Expect that the nextcountitems are received (values are not checked).expectNextMatches(Predicate<? super T> predicate, String description) Expect the next item to match the given predicate.Cancel the subscription at this point in the step sequence.thenRequest(long n) Requestnitems from upstream.voidverify()Subscribe to the Multi and execute all steps with the default timeout.voidSubscribe to the Multi and execute all steps with the given timeout per step.withInitialRequest(long n) Set the initial number of items to request from upstream on subscription.
-
Method Details
-
create
Create a newAssertMultifor the givenMulti.- Type Parameters:
T- the item type- Parameters:
multi- the Multi to verify, must not benull- Returns:
- a new AssertMulti
-
create
- Type Parameters:
T- the item type- Parameters:
multi- the Multi to verify, must not benullcontext- the context, must not benull- Returns:
- a new AssertMulti
-
withInitialRequest
Set the initial number of items to request from upstream on subscription.Defaults to
Long.MAX_VALUE(unbounded). Set to0to disable initial demand and control backpressure explicitly withthenRequest(long).- Parameters:
n- the initial request count, must be>= 0- Returns:
- this AssertMulti
-
expectNext
Expect the next item to be equal toexpected.- Parameters:
expected- the expected item- Returns:
- this AssertMulti
-
expectNext
Expect the next items to be equal toexpectedin order.- Parameters:
expected- the expected items- Returns:
- this AssertMulti
-
expectNextMatches
Expect the next item to match the given predicate.- Parameters:
predicate- the predicate to test, must not benulldescription- a description for error messages- Returns:
- this AssertMulti
-
expectNextCount
Expect that the nextcountitems are received (values are not checked).- Parameters:
count- the number of items to expect, must be positive- Returns:
- this AssertMulti
-
consumeNext
Consume and inspect the next item. The consumer should throw anAssertionErrorif the item is not acceptable.- Parameters:
consumer- the consumer, must not benull- Returns:
- this AssertMulti
-
consumeNextItems
Consume and inspect the nextcountitems as a list. The consumer should throw anAssertionErrorif the items are not acceptable.- Parameters:
count- the number of items to collect, must be positiveconsumer- the consumer, must not benull- Returns:
- this AssertMulti
-
thenRequest
Requestnitems from upstream. Use withwithInitialRequest(0)for explicit backpressure testing.- Parameters:
n- the number of items to request, must be positive- Returns:
- this AssertMulti
-
expectComplete
Expect the stream to complete.- Returns:
- this AssertMulti
-
expectFailure
Expect the stream to fail with any failure.- Returns:
- this AssertMulti
-
expectFailure
Expect the stream to fail with a specific failure type.- Parameters:
type- the expected failure type- Returns:
- this AssertMulti
-
expectFailure
Expect the stream to fail with a specific failure type and message substring.- Parameters:
type- the expected failure typemessageSubstring- a substring expected in the failure message- Returns:
- this AssertMulti
-
expectFailure
Expect the stream to fail and validate the failure with a consumer.- Parameters:
validator- the failure validator, must not benull- Returns:
- this AssertMulti
-
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
Subscribe to the Multi and execute all steps with the given timeout per step.- Parameters:
timeout- the maximum wait time per step, must not benull- Throws:
AssertionError- if any step fails
-