Class CommandHandlingTestFixture.Expect
- Enclosing class:
CommandHandlingTestFixture<I,
C extends Command, R>
CommandHandler
execution for assertion.
This class provides stateful event assertions, effectively iterating through the events published during a
command handler execution. Methods within this
annotated using
CommandHandlingTestFixture.Expect.StatefulAssertion
represent stateful assertions and thus both rely on previous stateful assertions and
proceed through the captured event stream, if invoked.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
Marker annotation for assertion methods withinCommandHandlingTestFixture.Expect
which proceed through the captured event stream, if invoked. -
Method Summary
Modifier and TypeMethodDescription<E> CommandHandlingTestFixture<I,
C, R>.Expect expectAnyEvent
(E payload) Asserts that any event's payload in the remaining set of captured events is equal to the given payload.Asserts that any of the remaining events in the set of captured events asserts successfully using the given event asserting consumer.<E> CommandHandlingTestFixture<I,
C, R>.Expect expectAnyEventSatisfying
(Consumer<E> assertion) Verifies that any event in the remaining set of captured events asserts using the given custom assertionConsumer
.expectAnyEventType
(Class<?> type) Asserts that any event in the remaining set of captured events Class.isAssignableFrom(Class) is assignable} to the given event type.Asserts that theCommandHandler
could not be executed because it violates the specifiedCommand.SubjectCondition
.expectEvents
(Object... events) Asserts that the next event payloads within the captured event stream are equal to the given events in order.expectEventsInAnyOrder
(Object... events) Asserts that the next event payloads within the captured event stream are equal to the given events in any order.expectEventsSatisfying
(Consumer<List<Object>> assertion) Asserts that the next event payloads within the captured event stream are successfully asserted by the given consumer.expectEventTypes
(Class<?>... types) Asserts that the next event payloads within the captured event stream Class.isAssignableFrom(Class) are assignable} to the given event types in order.expectEventTypesInAnyOrder
(Class<?>... types) Asserts that the next event payloads within the captured event stream Class.isAssignableFrom(Class) are assignable} to the given event types in any order.expectException
(Class<T> t) Asserts that theCommandHandler
executed exceptionally by throwing an exception of the given class.expectExceptionSatisfying
(Consumer<T> assertion) Asserts that theCommandHandler
executed exceptionally and allows for further custom assertions using the providedConsumer
.<E> CommandHandlingTestFixture<I,
C, R>.Expect expectNextEvent
(E payload) Asserts that the next payload payload within the captured payload stream is equal to the given payload.Asserts the next event within the captured event stream using the given event asserting consumer.<E> CommandHandlingTestFixture<I,
C, R>.Expect expectNextEventSatisfying
(Consumer<E> assertion) Asserts that next event within the captured event stream is successfully asserted by the givenConsumer
.expectNextEventType
(Class<?> type) Asserts that next event within the captured event stream Class.isAssignableFrom(Class) is assignable} to the given event type.Asserts that none of the remaining events in the captured event stream satisfies the given assertion criteria.expectNoEventOfType
(Class<?> type) Asserts that none of the remaining events in the captured event stream is assignable to the given type.Asserts that no event was captured as part of the published event stream.Asserts that no more events have been captured.expectNumEvents
(int num) Asserts that number of events captured as part of the published event stream matches the given number.expectResult
(R expected) expectResultSatisfying
(Consumer<R> assertion) <E> CommandHandlingTestFixture<I,
C, R>.Expect expectSingleEvent
(E payload) Asserts that a single payload was captured as part of the published payload stream whose payload is equal to the expected one.Asserts that a single event was captured as part of the published event stream which using the given event asserting consumer.<E> CommandHandlingTestFixture<I,
C, R>.Expect expectSingleEventSatisfying
(Consumer<E> assertion) Asserts that a single event was captured as part of the published event stream which matches the custom assertion provided asConsumer
.expectSingleEventType
(Class<?> type) Asserts that a single event was captured as part of the published event stream which Class.isAssignableFrom(Class) is assignable} to the given event type.expectState
(I state) <R> CommandHandlingTestFixture<I,
C, R>.Expect expectStateExtracting
(Function<I, R> extractor, R expected) expectStateSatisfying
(Consumer<I> assertion) Asserts that theCommandHandler
executed non exceptionally.Asserts that theCommandHandler
executed exceptionally, irrespective of the exception type.skipEvents
(int num) Skips the given number of next events for upcoming assertions.
-
Method Details
-
expectSuccessfulExecution
Asserts that theCommandHandler
executed non exceptionally.- Returns:
this
for further assertions- Throws:
AssertionError
- if theCommandHandler
terminated exceptionally
-
expectUnsuccessfulExecution
Asserts that theCommandHandler
executed exceptionally, irrespective of the exception type.- Returns:
this
for further assertions- Throws:
AssertionError
- if theCommandHandler
terminated non exceptionally
-
expectResult
- Throws:
AssertionError
-
expectResultSatisfying
public CommandHandlingTestFixture<I,C, expectResultSatisfyingR>.Expect (Consumer<R> assertion) throws AssertionError - Throws:
AssertionError
-
expectException
public <T extends Throwable> CommandHandlingTestFixture<I,C, expectExceptionR>.Expect (Class<T> t) throws AssertionError Asserts that theCommandHandler
executed exceptionally by throwing an exception of the given class.- Type Parameters:
T
- the generic exception type- Parameters:
t
- the expected exception class- Returns:
this
for further assertions- Throws:
AssertionError
- if theCommandHandler
executed non exceptionally or an exception was thrown that is not assignable to the requested type
-
expectExceptionSatisfying
public <T extends Throwable> CommandHandlingTestFixture<I,C, expectExceptionSatisfyingR>.Expect (Consumer<T> assertion) throws AssertionError Asserts that theCommandHandler
executed exceptionally and allows for further custom assertions using the providedConsumer
.- Type Parameters:
T
- the generic exception type- Parameters:
assertion
- a consumer for custom assertions of the captured exception- Returns:
this
for further assertions- Throws:
AssertionError
- if theCommandHandler
executed non exceptionally or if thrown by the given consumer
-
expectCommandSubjectConditionViolated
public CommandHandlingTestFixture<I,C, expectCommandSubjectConditionViolated() throws AssertionErrorR>.Expect Asserts that theCommandHandler
could not be executed due to a violatedCommand.SubjectCondition
.This method must not be used together with
CommandHandlingTestFixture.givenState(Object)
, since no event subjects may be available for assertion in that case.- Returns:
this
for further assertions- Throws:
AssertionError
- if noCommand.SubjectCondition
was violated
-
expectCommandSubjectConditionViolated
public CommandHandlingTestFixture<I,C, expectCommandSubjectConditionViolatedR>.Expect (Command.SubjectCondition expected) throws AssertionError Asserts that theCommandHandler
could not be executed because it violates the specifiedCommand.SubjectCondition
.This method must not be used together with
CommandHandlingTestFixture.givenState(Object)
, since no event subjects may be available for assertion in that case.- Parameters:
expected
- the subject condition expected to be violated- Returns:
this
for further assertions- Throws:
AssertionError
- if no or any other than the specifiedCommand.SubjectCondition
was violated
-
expectState
Asserts that the (potentially altered) state resulting from the @link CommandHandler} execution is equal to the given state.- Parameters:
state
- the expected state- Returns:
this
for further assertions- Throws:
AssertionError
- if the captured state isnull
or not equal to the expected state
-
expectStateExtracting
public <R> CommandHandlingTestFixture<I,C, expectStateExtractingR>.Expect (Function<I, R> extractor, R expected) throws AssertionErrorAsserts that the (potentially altered) state resulting from the @link CommandHandler} execution is equal to the given state using the extractor function.- Type Parameters:
R
- the result type of the extractor function- Parameters:
extractor
- extractor function applied to the state before comparisonexpected
- the extracted state expected, may benull
if needed- Returns:
this
for further assertions- Throws:
AssertionError
- if the captured state isnull
or the extracted state is not as expected
-
expectStateSatisfying
public CommandHandlingTestFixture<I,C, expectStateSatisfyingR>.Expect (Consumer<I> assertion) throws AssertionError Asserts the (potentially altered) state resulting from the @link CommandHandler} execution using the givenConsumer
.- Parameters:
assertion
- the consumer used for custom state assertions- Returns:
this
for further assertions- Throws:
AssertionError
- if thrown by the given consumer
-
expectEvents
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectEventsR>.Expect (Object... events) throws AssertionError Asserts that the next event payloads within the captured event stream are equal to the given events in order.- Parameters:
events
- the expected events- Returns:
this
for further assertions- Throws:
AssertionError
- if less captured events remain than expected or any of the expected events is not equal
-
expectEventTypes
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectEventTypesR>.Expect (Class<?>... types) throws AssertionError Asserts that the next event payloads within the captured event stream Class.isAssignableFrom(Class) are assignable} to the given event types in order.- Parameters:
types
- the expected event types- Returns:
this
for further assertions- Throws:
AssertionError
- if less captured events remain than expected or any of the expected event types is not assignable
-
expectEventsSatisfying
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectEventsSatisfyingR>.Expect (Consumer<List<Object>> assertion) throws AssertionError Asserts that the next event payloads within the captured event stream are successfully asserted by the given consumer.- Parameters:
assertion
- consumer asserting the remaining events- Returns:
this
for further assertions- Throws:
AssertionError
- if thrown by the consumer
-
expectEventsInAnyOrder
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectEventsInAnyOrderR>.Expect (Object... events) throws AssertionError Asserts that the next event payloads within the captured event stream are equal to the given events in any order.- Parameters:
events
- the expected events (in any order)- Returns:
this
for further assertions- Throws:
AssertionError
- if less captured events remain than expected or any of the expected events is not equal
-
expectEventTypesInAnyOrder
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectEventTypesInAnyOrderR>.Expect (Class<?>... types) throws AssertionError Asserts that the next event payloads within the captured event stream Class.isAssignableFrom(Class) are assignable} to the given event types in any order.- Parameters:
types
- the expected event types (in any order)- Returns:
this
for further assertions- Throws:
AssertionError
- if less captured events remain than expected or any of the expected event type is not assignable
-
expectNextEvent
@StatefulAssertion public <E> CommandHandlingTestFixture<I,C, expectNextEventR>.Expect (E payload) throws AssertionError Asserts that the next payload payload within the captured payload stream is equal to the given payload.- Type Parameters:
E
- the generic payload type- Parameters:
payload
- the expected payload- Returns:
this
for further assertions- Throws:
AssertionError
- if no captured events remain or the next payload does not equal the expected one
-
expectNextEvent
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectNextEventR>.Expect (Consumer<CommandHandlingTestFixture.EventAsserter> assertion) Asserts the next event within the captured event stream using the given event asserting consumer.- Parameters:
assertion
- consumer for further event assertion- Returns:
this
for further assertions- Throws:
AssertionError
- if no captured events remain or if thrown by the event assertion consumer
-
expectNextEventType
@StatefulAssertion public CommandHandlingTestFixture<I,C, expectNextEventTypeR>.Expect (Class<?> type) throws AssertionError Asserts that next event within the captured event stream Class.isAssignableFrom(Class) is assignable} to the given event type.- Parameters:
type
- the expected event type- Returns:
this
for further assertions- Throws:
AssertionError
- if no captured events remain or the next event is not assignable to the expected type
-
expectNextEventSatisfying
@StatefulAssertion public <E> CommandHandlingTestFixture<I,C, expectNextEventSatisfyingR>.Expect (Consumer<E> assertion) throws AssertionError Asserts that next event within the captured event stream is successfully asserted by the givenConsumer
.- Type Parameters:
E
- the generic event type- Parameters:
assertion
- custom assertion applied to the next event- Returns:
this
for further assertions- Throws:
AssertionError
- if no captured events remain or if thrown by the custom assertion
-
expectNoMoreEvents
Asserts that no more events have been captured.- Returns:
this
for further assertions- Throws:
AssertionError
- if there are any remaining events
-
expectSingleEvent
public <E> CommandHandlingTestFixture<I,C, expectSingleEventR>.Expect (E payload) throws AssertionError Asserts that a single payload was captured as part of the published payload stream whose payload is equal to the expected one.- Type Parameters:
E
- the generic payload type- Parameters:
payload
- the expected payload type- Returns:
this
for further assertions- Throws:
AssertionError
- if no or more events were captured or the captured payload does not equal the expected one
-
expectSingleEvent
public CommandHandlingTestFixture<I,C, expectSingleEventR>.Expect (Consumer<CommandHandlingTestFixture.EventAsserter> assertion) Asserts that a single event was captured as part of the published event stream which using the given event asserting consumer.- Parameters:
assertion
- consumer for further event assertion- Returns:
this
for further assertions- Throws:
AssertionError
- if no or more events were captured or if thrown by the event assertion consumer
-
expectSingleEventType
public CommandHandlingTestFixture<I,C, expectSingleEventTypeR>.Expect (Class<?> type) throws AssertionError Asserts that a single event was captured as part of the published event stream which Class.isAssignableFrom(Class) is assignable} to the given event type.- Parameters:
type
- the expected event type- Returns:
this
for further assertions- Throws:
AssertionError
- if no or more events were captured or the captured event is not assignable to the expected type
-
expectSingleEventSatisfying
public <E> CommandHandlingTestFixture<I,C, expectSingleEventSatisfyingR>.Expect (Consumer<E> assertion) throws AssertionError Asserts that a single event was captured as part of the published event stream which matches the custom assertion provided asConsumer
.- Type Parameters:
E
- the generic payload type- Parameters:
assertion
- the custom assertion- Returns:
this
for further assertions- Throws:
AssertionError
- if no or more events were captured or if thrown by the custom assertion
-
expectNumEvents
Asserts that number of events captured as part of the published event stream matches the given number.- Parameters:
num
- the number of expected events, may be zero- Returns:
this
for further assertions- Throws:
AssertionError
- if the number of published events differs
-
expectNoEvents
Asserts that no event was captured as part of the published event stream.- Returns:
this
for further assertions- Throws:
AssertionError
- if any event was published
-
skipEvents
@StatefulAssertion public CommandHandlingTestFixture<I,C, skipEventsR>.Expect (int num) throws AssertionError Skips the given number of next events for upcoming assertions.- Parameters:
num
- the number of events to skip- Returns:
this
for further assertions- Throws:
AssertionError
- if less events were captured than the requested number to skip
-
expectAnyEvent
Asserts that any event's payload in the remaining set of captured events is equal to the given payload.- Type Parameters:
E
- the generic payload type- Parameters:
payload
- the expected payload- Returns:
this
for further assertions- Throws:
AssertionError
- if no events were captured or none of them does equal the expected one
-
expectAnyEvent
public CommandHandlingTestFixture<I,C, expectAnyEventR>.Expect (Consumer<CommandHandlingTestFixture.EventAsserter> assertion) throws AssertionError Asserts that any of the remaining events in the set of captured events asserts successfully using the given event asserting consumer.- Parameters:
assertion
- consumer for further event assertion- Returns:
this
for further assertions- Throws:
AssertionError
- if no or more events were captured or if thrown by the event assertion consumer
-
expectNoEvent
public CommandHandlingTestFixture<I,C, expectNoEventR>.Expect (Consumer<CommandHandlingTestFixture.EventAsserter> assertion) throws AssertionError Asserts that none of the remaining events in the captured event stream satisfies the given assertion criteria. This is the inverse ofexpectAnyEvent(Consumer)
.This method looks through all remaining events from the current iterator position and verifies that none of them passes the provided assertion. If any event passes the assertion, an AssertionError is thrown.
- Parameters:
assertion
- consumer specifying the event assertion criteria that should not be satisfied- Returns:
this
for further assertions- Throws:
AssertionError
- if any remaining event satisfies the assertion criteria
-
expectAnyEventType
public CommandHandlingTestFixture<I,C, expectAnyEventTypeR>.Expect (Class<?> type) throws AssertionError Asserts that any event in the remaining set of captured events Class.isAssignableFrom(Class) is assignable} to the given event type.- Parameters:
type
- the expected event type- Returns:
this
for further assertions- Throws:
AssertionError
- if no events were captured or none of them is assignable to the expected type
-
expectAnyEventSatisfying
public <E> CommandHandlingTestFixture<I,C, expectAnyEventSatisfyingR>.Expect (Consumer<E> assertion) throws AssertionError Verifies that any event in the remaining set of captured events asserts using the given custom assertionConsumer
.- Type Parameters:
E
- the generic payload type- Parameters:
assertion
- custom assertion- Returns:
this
for further assertions- Throws:
AssertionError
- if no events were captured or none of them was successfully asserted by the custom assertion
-
expectNoEventOfType
public CommandHandlingTestFixture<I,C, expectNoEventOfTypeR>.Expect (Class<?> type) throws AssertionError Asserts that none of the remaining events in the captured event stream is assignable to the given type.- Parameters:
type
- the event type that should not be present in the remaining events- Returns:
this
for further assertions- Throws:
AssertionError
- if any remaining event of the given type is found
-