Package com.opencqrs.framework.command
Interface ExpectDsl.Succeeding
- Enclosing interface:
ExpectDsl
public static interface ExpectDsl.Succeeding
Fluent API for assertions after successful command execution.
Succeeding is the central hub of the
assertion API — it can be reached from ExpectDsl.Outcome.succeeds(), from ExpectDsl.All.and(), from
ExpectDsl.Next.and(), or from any terminal method on ExpectDsl.Next.
All assertion methods return Succeeding to allow free chaining between result/state assertions and
event assertions:
.succeeds()
.havingResult(expectedResult)
.nextEvents()
.matches(e -> e.ofType(OrderPlacedEvent.class))
.noMore()
.allEvents()
.count(1)
.and()
.havingState(expectedState);
-
Method Summary
Modifier and TypeMethodDescriptionReturns an interface for asserting against all captured events as a whole.havingResult(@Nullable Object expected) Asserts that the command handler returned the expected result usingObject.equals(Object).havingState(@Nullable Object state) Asserts that the final instance state equals the expected state usingObject.equals(Object).Returns an interface for asserting against events sequentially using a cursor.resultSatisfying(Consumer<@Nullable Object> assertion) Asserts that the command result satisfies custom assertions.stateExtracting(Function<@Nullable Object, T> extractor, T expected) Extracts a value from the final instance state and asserts it equals the expected value.stateSatisfying(Consumer<@Nullable Object> assertion) Asserts that the final instance state satisfies custom assertions.Asserts that no events were published by the command handler.
-
Method Details
-
withoutEvents
ExpectDsl.Succeeding withoutEvents()Asserts that no events were published by the command handler.- Returns:
thisfor method chaining- Throws:
AssertionError- if any events were published
-
havingResult
Asserts that the command handler returned the expected result usingObject.equals(Object). The result is the value returned by theCommandHandlerimplementation.- Parameters:
expected- the expected result value (may benull)- Returns:
thisfor method chaining- Throws:
AssertionError- if the results are not equal
-
resultSatisfying
Asserts that the command result satisfies custom assertions.Example:
.succeeds() .resultSatisfying(result -> assertThat(result).isInstanceOf(OrderId.class));- Parameters:
assertion- a consumer receiving the command result for custom assertions- Returns:
thisfor method chaining- Throws:
AssertionError- if thrown by the consumer
-
havingState
Asserts that the final instance state equals the expected state usingObject.equals(Object). The state is captured after all published events have been processed by theStateRebuildingHandlerDefinitions.- Parameters:
state- the expected final state- Returns:
thisfor method chaining- Throws:
AssertionError- if the states are not equal or no state was captured
-
stateSatisfying
Asserts that the final instance state satisfies custom assertions.Example:
.succeeds() .stateSatisfying(state -> { OrderState order = (OrderState) state; assertThat(order.status()).isEqualTo(OrderStatus.CONFIRMED); });- Parameters:
assertion- a consumer receiving the final state for custom assertions- Returns:
thisfor method chaining- Throws:
AssertionError- if thrown by the consumer
-
stateExtracting
Extracts a value from the final instance state and asserts it equals the expected value. Useful for verifying specific state fields without matching the entire state object.Example:
.succeeds() .stateExtracting(state -> ((OrderState) state).status(), OrderStatus.CONFIRMED);- Type Parameters:
T- the extracted value type- Parameters:
extractor- function to extract a value from the stateexpected- the expected extracted value (may benull)- Returns:
thisfor method chaining- Throws:
AssertionError- if the extracted values are not equal or no state was captured
-
allEvents
ExpectDsl.All allEvents()Returns an interface for asserting against all captured events as a whole. Use this when you need to verify the complete set of events without cursor-based navigation. Each call operates on the full event list.- Returns:
- an
ExpectDsl.Allinterface for event assertions - See Also:
-
nextEvents
ExpectDsl.Next nextEvents()Returns an interface for asserting against events sequentially using a cursor. Each call creates a fresh cursor starting at position 0. Use this when you need to navigate through events in order, skip events, or verify that no more events exist after a certain point.Navigation methods (
ExpectDsl.Next.skipping(int),ExpectDsl.Next.matches(Consumer)) advance the cursor and returnExpectDsl.Nextfor further navigation. Consuming methods (ExpectDsl.Next.single(Consumer),ExpectDsl.Next.once(Consumer),ExpectDsl.Next.any(Consumer),ExpectDsl.Next.every(Consumer),ExpectDsl.Next.none(Consumer),ExpectDsl.Next.exactly(Object...),ExpectDsl.Next.noMore(),ExpectDsl.Next.remaining(int)) consume remaining events and returnExpectDsl.Succeeding.Example:
.succeeds() .nextEvents() .matches(e -> e.ofType(OrderPlacedEvent.class)) .skipping(1) .noMore() .havingResult(expectedId);- Returns:
- a
ExpectDsl.Nextinterface for sequential event assertions - See Also:
-