Package com.opencqrs.framework.command
Interface ExpectDsl.Next
- Enclosing interface:
ExpectDsl
public static interface ExpectDsl.Next
Fluent API for asserting against events sequentially using a consuming cursor. This interface maintains position
state, allowing navigation through events in order.
The cursor starts at position 0 (first event). There are two categories of methods:
- Navigating (
skipping(int),matches(Consumer)) — advance the cursor and returnNextfor further chaining. - Consuming (
single(Consumer),once(Consumer),any(Consumer),every(Consumer),none(Consumer),exactly(Object...),noMore(),remaining(int)) — consume remaining events and returnExpectDsl.Succeedingfor result/state assertions or further event assertions.
All consuming matcher methods operate on the remaining events from the current cursor position.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionand()Returns to theExpectDsl.Succeedinginterface to access result/state assertions or switch to a different event assertion mode (ExpectDsl.Succeeding.allEvents(),ExpectDsl.Succeeding.nextEvents()).any(Consumer<ExpectDsl.EventValidator> consumer) Consumes all remaining events and asserts that at least one of them matches the validation.every(Consumer<ExpectDsl.EventValidator> consumer) Consumes all remaining events and asserts that every one of them matches the validation.Consumes all remaining events and asserts that the remaining event payloads match exactly the provided payloads in order, usingObject.equals(Object).matches(Consumer<ExpectDsl.EventValidator> consumer) Consumes exactly one event at the current cursor position and validates it using the provided consumer.noMore()Asserts that no more events exist from the current cursor position.none(Consumer<ExpectDsl.EventValidator> consumer) Consumes all remaining events and asserts that none of them match the validation.once(Consumer<ExpectDsl.EventValidator> consumer) Consumes all remaining events and asserts that exactly one of them matches the validation.remaining(int count) Asserts that exactly the specified number of events remain from the current cursor position.single(Consumer<ExpectDsl.EventValidator> consumer) Asserts that exactly one event remains from the current cursor position and that it matches the validation.skipping(int num) Advances the cursor by the specified number of events.
-
Method Details
-
skipping
Advances the cursor by the specified number of events. Subsequent assertions will operate on events starting from the new cursor position.- Parameters:
num- the number of events to skip (must be non-negative)- Returns:
thisfor method chaining- Throws:
AssertionError- if skipping would move past the end of the event list
-
noMore
ExpectDsl.Succeeding noMore()Asserts that no more events exist from the current cursor position.Example:
.nextEvents() .skipping(2) .noMore() .havingResult(expectedId);- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if events exist at or after the current cursor position
-
remaining
Asserts that exactly the specified number of events remain from the current cursor position. This is a convenience shortcut forskipping(count).noMore().- Parameters:
count- the expected number of remaining events (must be non-negative)- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if the remaining event count differs
-
single
Asserts that exactly one event remains from the current cursor position and that it matches the validation. The remaining stream must have length 1, then the event is consumed.To assert that exactly one remaining event matches in a stream of any length, use
once(Consumer).Example:
.nextEvents().single(e -> e.ofType(OrderPlacedEvent.class));
- Parameters:
consumer- a consumer that validates the event viaExpectDsl.EventValidator- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if the remaining event count is not exactly 1 or the event fails validation
-
once
Consumes all remaining events and asserts that exactly one of them matches the validation. The remaining stream may have any length.- Parameters:
consumer- a consumer that validates events viaExpectDsl.EventValidator- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if zero or more than one remaining event matches
-
any
Consumes all remaining events and asserts that at least one of them matches the validation. The remaining stream may have any length (multiple matches are allowed) but must contain at least one matching event.- Parameters:
consumer- a consumer that validates events viaExpectDsl.EventValidator- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if no remaining event matches or the remaining stream is empty
-
every
Consumes all remaining events and asserts that every one of them matches the validation. The remaining stream must contain at least one event — an empty remaining stream causes an assertion error (fail-fast).- Parameters:
consumer- a consumer that validates each event viaExpectDsl.EventValidator- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if any remaining event fails validation or no remaining events exist
-
exactly
Consumes all remaining events and asserts that the remaining event payloads match exactly the provided payloads in order, usingObject.equals(Object). Only payloads are compared — meta-data and subject are ignored. The number of remaining events must equal the number of expected payloads.- Parameters:
events- the expected event payloads in order- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if the remaining event count doesn't match or any payload differs
-
none
Consumes all remaining events and asserts that none of them match the validation.- Parameters:
consumer- a consumer that validates events viaExpectDsl.EventValidator- Returns:
- a
ExpectDsl.Succeedinginterface for further assertions - Throws:
AssertionError- if any remaining event matches
-
matches
Consumes exactly one event at the current cursor position and validates it using the provided consumer. Advances the cursor by one. This is a navigating operation that returnsExpectDsl.Nextfor further chaining.- Parameters:
consumer- a consumer that validates the event viaExpectDsl.EventValidator- Returns:
thisfor further navigation- Throws:
AssertionError- if no more events remain at the current cursor position, or if the event fails validation
-
and
ExpectDsl.Succeeding and()Returns to theExpectDsl.Succeedinginterface to access result/state assertions or switch to a different event assertion mode (ExpectDsl.Succeeding.allEvents(),ExpectDsl.Succeeding.nextEvents()).- Returns:
- a
ExpectDsl.Succeedinginterface
-