Class CommandHandlingTestFixture.Expect
- Enclosing class:
CommandHandlingTestFixture<C extends Command>
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 @interfaceMarker annotation for assertion methods withinCommandHandlingTestFixture.Expectwhich proceed through the captured event stream, if invoked. -
Method Summary
Modifier and TypeMethodDescriptionexpectAnyEvent(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.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 theCommandHandlercould 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.<T extends Throwable>
CommandHandlingTestFixture<C>.ExpectexpectException(Class<T> t) Asserts that theCommandHandlerexecuted exceptionally by throwing an exception of the given class.<T extends Throwable>
CommandHandlingTestFixture<C>.ExpectexpectExceptionSatisfying(Consumer<T> assertion) Asserts that theCommandHandlerexecuted exceptionally and allows for further custom assertions using the providedConsumer.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.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) Asserts that theCommandHandlerreturned the expected result.expectResultSatisfying(Consumer<R> assertion) Asserts that theCommandHandler's returned result satisfies the custom assertions using the providedConsumer.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.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) <I,R> CommandHandlingTestFixture<C>.Expect expectStateExtracting(Function<I, R> extractor, R expected) expectStateSatisfying(Consumer<I> assertion) Asserts that theCommandHandlerexecuted non exceptionally.Asserts that theCommandHandlerexecuted exceptionally, irrespective of the exception type.skipEvents(int num) Skips the given number of next events for upcoming assertions.
-
Method Details
-
expectSuccessfulExecution
Asserts that theCommandHandlerexecuted non exceptionally.- Returns:
thisfor further assertions- Throws:
AssertionError- if theCommandHandlerterminated exceptionally
-
expectUnsuccessfulExecution
Asserts that theCommandHandlerexecuted exceptionally, irrespective of the exception type.- Returns:
thisfor further assertions- Throws:
AssertionError- if theCommandHandlerterminated non exceptionally
-
expectResult
Asserts that theCommandHandlerreturned the expected result.- Type Parameters:
R- the generic result type- Parameters:
expected- the expected result (may benull)- Returns:
thisfor further assertions- Throws:
AssertionError- if theCommandHandlerreturned a result non-equal to the expected one
-
expectResultSatisfying
public <R> CommandHandlingTestFixture<C>.Expect expectResultSatisfying(Consumer<R> assertion) throws AssertionError Asserts that theCommandHandler's returned result satisfies the custom assertions using the providedConsumer.- Type Parameters:
R- the generic result type- Parameters:
assertion- a consumer for custom assertions of the captured result- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
expectException
public <T extends Throwable> CommandHandlingTestFixture<C>.Expect expectException(Class<T> t) throws AssertionError Asserts that theCommandHandlerexecuted exceptionally by throwing an exception of the given class.- Type Parameters:
T- the generic exception type- Parameters:
t- the expected exception class- Returns:
thisfor further assertions- Throws:
AssertionError- if theCommandHandlerexecuted non exceptionally or an exception was thrown that is not assignable to the requested type
-
expectExceptionSatisfying
public <T extends Throwable> CommandHandlingTestFixture<C>.Expect expectExceptionSatisfying(Consumer<T> assertion) throws AssertionError Asserts that theCommandHandlerexecuted 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:
thisfor further assertions- Throws:
AssertionError- if theCommandHandlerexecuted non exceptionally or if thrown by the given consumer
-
expectCommandSubjectConditionViolated
public CommandHandlingTestFixture<C>.Expect expectCommandSubjectConditionViolated() throws AssertionErrorAsserts that theCommandHandlercould 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:
thisfor further assertions- Throws:
AssertionError- if noCommand.SubjectConditionwas violated
-
expectCommandSubjectConditionViolated
public CommandHandlingTestFixture<C>.Expect expectCommandSubjectConditionViolated(Command.SubjectCondition expected) throws AssertionError Asserts that theCommandHandlercould 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:
thisfor further assertions- Throws:
AssertionError- if no or any other than the specifiedCommand.SubjectConditionwas violated
-
expectState
Asserts that the (potentially altered) state resulting from the @link CommandHandler} execution is equal to the given state.- Type Parameters:
I- the generic state type- Parameters:
state- the expected state- Returns:
thisfor further assertions- Throws:
AssertionError- if the captured state isnullor not equal to the expected state
-
expectStateExtracting
public <I,R> CommandHandlingTestFixture<C>.Expect expectStateExtracting(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:
I- the generic state typeR- the result type of the extractor function- Parameters:
extractor- extractor function applied to the state before comparisonexpected- the extracted state expected, may benullif needed- Returns:
thisfor further assertions- Throws:
AssertionError- if the captured state isnullor the extracted state is not as expected
-
expectStateSatisfying
public <I> CommandHandlingTestFixture<C>.Expect expectStateSatisfying(Consumer<I> assertion) throws AssertionError Asserts the (potentially altered) state resulting from the @link CommandHandler} execution using the givenConsumer.- Type Parameters:
I- the generic state type- Parameters:
assertion- the consumer used for custom state assertions- Returns:
thisfor further assertions- Throws:
AssertionError- if thrown by the given consumer
-
expectEvents
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectEvents(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:
thisfor further assertions- Throws:
AssertionError- if less captured events remain than expected or any of the expected events is not equal
-
expectEventTypes
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectEventTypes(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:
thisfor 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<C>.Expect expectEventsSatisfying(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:
thisfor further assertions- Throws:
AssertionError- if thrown by the consumer
-
expectEventsInAnyOrder
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectEventsInAnyOrder(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:
thisfor further assertions- Throws:
AssertionError- if less captured events remain than expected or any of the expected events is not equal
-
expectEventTypesInAnyOrder
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectEventTypesInAnyOrder(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:
thisfor 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<C>.Expect expectNextEvent(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:
thisfor further assertions- Throws:
AssertionError- if no captured events remain or the next payload does not equal the expected one
-
expectNextEvent
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectNextEvent(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:
thisfor further assertions- Throws:
AssertionError- if no captured events remain or if thrown by the event assertion consumer
-
expectNextEventType
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect expectNextEventType(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:
thisfor 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<C>.Expect expectNextEventSatisfying(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:
thisfor 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:
thisfor further assertions- Throws:
AssertionError- if there are any remaining events
-
expectSingleEvent
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:
thisfor further assertions- Throws:
AssertionError- if no or more events were captured or the captured payload does not equal the expected one
-
expectSingleEvent
public CommandHandlingTestFixture<C>.Expect expectSingleEvent(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:
thisfor further assertions- Throws:
AssertionError- if no or more events were captured or if thrown by the event assertion consumer
-
expectSingleEventType
public CommandHandlingTestFixture<C>.Expect expectSingleEventType(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:
thisfor 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<C>.Expect expectSingleEventSatisfying(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:
thisfor 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:
thisfor 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:
thisfor further assertions- Throws:
AssertionError- if any event was published
-
skipEvents
@StatefulAssertion public CommandHandlingTestFixture<C>.Expect skipEvents(int num) throws AssertionError Skips the given number of next events for upcoming assertions.- Parameters:
num- the number of events to skip- Returns:
thisfor 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:
thisfor further assertions- Throws:
AssertionError- if no events were captured or none of them does equal the expected one
-
expectAnyEvent
public CommandHandlingTestFixture<C>.Expect expectAnyEvent(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:
thisfor further assertions- Throws:
AssertionError- if no or more events were captured or if thrown by the event assertion consumer
-
expectNoEvent
public CommandHandlingTestFixture<C>.Expect expectNoEvent(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:
thisfor further assertions- Throws:
AssertionError- if any remaining event satisfies the assertion criteria
-
expectAnyEventType
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:
thisfor further assertions- Throws:
AssertionError- if no events were captured or none of them is assignable to the expected type
-
expectAnyEventSatisfying
public <E> CommandHandlingTestFixture<C>.Expect expectAnyEventSatisfying(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:
thisfor further assertions- Throws:
AssertionError- if no events were captured or none of them was successfully asserted by the custom assertion
-
expectNoEventOfType
public CommandHandlingTestFixture<C>.Expect expectNoEventOfType(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:
thisfor further assertions- Throws:
AssertionError- if any remaining event of the given type is found
-