Package com.opencqrs.framework.command
Interface ExpectDsl.Failing
- Enclosing interface:
ExpectDsl
public static interface ExpectDsl.Failing
Fluent API for assertions after failed command execution. Provides methods to verify the exception type and
precondition violations.
All assertion methods return this to allow method chaining:
.fails()
.throwing(IllegalStateException.class)
.throwsSatisfying(ex -> assertThat(ex.getMessage()).contains("invalid"));
-
Method Summary
Modifier and TypeMethodDescription<T extends Throwable>
ExpectDsl.FailingAsserts that the thrown exception is an instance of the specified type.<T extends Throwable>
ExpectDsl.Failingthrowing(T t) Asserts that the thrown exception matches the specified throwable by type and message.<T extends Throwable>
ExpectDsl.FailingthrowsSatisfying(Consumer<T> assertion) Asserts that the thrown exception satisfies custom assertions.Asserts that the command failed due to aCommand.SubjectConditionviolation.violatingExactly(Command.SubjectCondition condition) Asserts that the command failed due to a specificCommand.SubjectConditionviolation.
-
Method Details
-
throwing
Asserts that the thrown exception is an instance of the specified type.- Type Parameters:
T- the exception type- Parameters:
t- the expected exception class- Returns:
thisfor method chaining- Throws:
AssertionError- if the exception is not of the expected type
-
throwing
Asserts that the thrown exception matches the specified throwable by type and message. The actual exception must be an instance of the same class and have an equalmessage.- Type Parameters:
T- the exception type- Parameters:
t- the expected throwable to compare against- Returns:
thisfor method chaining- Throws:
AssertionError- if the exception type or message differs
-
throwsSatisfying
Asserts that the thrown exception satisfies custom assertions.Example:
.fails() .throwsSatisfying((IllegalArgumentException ex) -> assertThat(ex.getMessage()).contains("order not found"));- Type Parameters:
T- the exception type- Parameters:
assertion- a consumer receiving the exception for custom assertions- Returns:
thisfor method chaining- Throws:
AssertionError- if thrown by the consumer
-
violatingAnyCondition
ExpectDsl.Failing violatingAnyCondition()Asserts that the command failed due to aCommand.SubjectConditionviolation. This matches eitherCommand.SubjectCondition.PRISTINEorCommand.SubjectCondition.EXISTSviolations.- Returns:
thisfor method chaining- Throws:
AssertionError- if the failure was not due to a precondition violation
-
violatingExactly
Asserts that the command failed due to a specificCommand.SubjectConditionviolation.Example:
// Command requires the subject to not exist yet .fails() .violatingExactly(Command.SubjectCondition.PRISTINE);- Parameters:
condition- the expected violated condition (Command.SubjectCondition.PRISTINEorCommand.SubjectCondition.EXISTS)- Returns:
thisfor method chaining- Throws:
IllegalArgumentException- ifCommand.SubjectCondition.NONEis passedAssertionError- if the failure was not due to the specified condition
-