Package com.opencqrs.framework.command
Class CommandHandlingTestFixture.EventAsserter
java.lang.Object
com.opencqrs.framework.command.CommandHandlingTestFixture.EventAsserter
- All Implemented Interfaces:
EventAsserting
- Enclosing class:
CommandHandlingTestFixture<C extends Command>
public static class CommandHandlingTestFixture.EventAsserter
extends Object
implements EventAsserting
Fluent API helper class for asserting captured events.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAsserts that the event subject equals the command's subject.Asserts that the event meta-data equals the expected map usingObject.equals(Object).metaDataSatisfying(Consumer<Map<String, ?>> assertion) Asserts that the event meta-data satisfies custom assertions.Asserts that the event has no meta-data (empty map).payload(E expected) Asserts that the event payload equals the expected value usingObject.equals(Object).payloadExtracting(Function<E, R> extractor, R expected) Extracts a value from the event payload and asserts it equals the expected value.payloadSatisfying(Consumer<E> assertion) Asserts that the event payload satisfies custom assertions.payloadType(Class<?> type) Asserts that the event payload is an instance of the specified type.Asserts that the event subject equals the expected value.subjectSatisfying(Consumer<String> assertion) Asserts that the event subject satisfies custom assertions.
-
Method Details
-
payloadType
Description copied from interface:EventAssertingAsserts that the event payload is an instance of the specified type.- Specified by:
payloadTypein interfaceEventAsserting- Parameters:
type- the expected payload class- Returns:
thisfor further assertions
-
payload
Description copied from interface:EventAssertingAsserts that the event payload equals the expected value usingObject.equals(Object).- Specified by:
payloadin interfaceEventAsserting- Type Parameters:
E- the payload type- Parameters:
expected- the expected payload- Returns:
thisfor further assertions- Throws:
AssertionError- if the payloads are not equal
-
payloadExtracting
public <E,R> CommandHandlingTestFixture.EventAsserter payloadExtracting(Function<E, R> extractor, R expected) throws AssertionErrorDescription copied from interface:EventAssertingExtracts a value from the event payload and asserts it equals the expected value. Useful for comparing specific fields without matching the entire payload.Example:
a.payloadExtracting((MyEvent e) -> e.name(), "expected-name")- Specified by:
payloadExtractingin interfaceEventAsserting- Type Parameters:
E- the payload typeR- the extracted value type- Parameters:
extractor- function to extract a value from the payloadexpected- the expected extracted value (may benull)- Returns:
thisfor further assertions- Throws:
AssertionError- if the extracted values are not equal
-
payloadSatisfying
public <E> CommandHandlingTestFixture.EventAsserter payloadSatisfying(Consumer<E> assertion) throws AssertionError Description copied from interface:EventAssertingAsserts that the event payload satisfies custom assertions.- Specified by:
payloadSatisfyingin interfaceEventAsserting- Type Parameters:
E- the payload type- Parameters:
assertion- consumer receiving the payload- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
metaData
public CommandHandlingTestFixture.EventAsserter metaData(Map<String, ?> expected) throws AssertionErrorDescription copied from interface:EventAssertingAsserts that the event meta-data equals the expected map usingObject.equals(Object).- Specified by:
metaDatain interfaceEventAsserting- Parameters:
expected- the expected meta-data- Returns:
thisfor further assertions- Throws:
AssertionError- if the meta-data maps are not equal
-
metaDataSatisfying
public CommandHandlingTestFixture.EventAsserter metaDataSatisfying(Consumer<Map<String, ?>> assertion) throws AssertionErrorDescription copied from interface:EventAssertingAsserts that the event meta-data satisfies custom assertions.- Specified by:
metaDataSatisfyingin interfaceEventAsserting- Parameters:
assertion- consumer receiving the meta-data map- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
noMetaData
Description copied from interface:EventAssertingAsserts that the event has no meta-data (empty map).- Specified by:
noMetaDatain interfaceEventAsserting- Returns:
thisfor further assertions- Throws:
AssertionError- if the meta-data is not empty
-
subject
Description copied from interface:EventAssertingAsserts that the event subject equals the expected value.- Specified by:
subjectin interfaceEventAsserting- Parameters:
expected- the expected subject- Returns:
thisfor further assertions- Throws:
AssertionError- if the subjects are not equal
-
subjectSatisfying
public CommandHandlingTestFixture.EventAsserter subjectSatisfying(Consumer<String> assertion) throws AssertionError Description copied from interface:EventAssertingAsserts that the event subject satisfies custom assertions.- Specified by:
subjectSatisfyingin interfaceEventAsserting- Parameters:
assertion- consumer receiving the subject- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
commandSubject
Description copied from interface:EventAssertingAsserts that the event subject equals the command's subject. Convenience method equivalent tosubject(command.getSubject()).- Specified by:
commandSubjectin interfaceEventAsserting- Returns:
thisfor further assertions- Throws:
AssertionError- if the subjects do not match
-