Package org.axonframework.test.matchers
Class Matchers
java.lang.Object
org.axonframework.test.matchers.Matchers
Utility class containing static methods to obtain instances of (List) Matchers.
- Since:
- 1.1
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> org.hamcrest.Matcher<T> Matches againstnullorvoid.static <T> org.hamcrest.Matcher<T> deepEquals(T expected) Constructs a deep equalsMatcher.static <T> org.hamcrest.Matcher<T> deepEquals(T expected, FieldFilter filter) Constructs a deep equalsMatcher.static <T> EqualFieldsMatcher<T> equalTo(T expected) Deprecated.static <T> EqualFieldsMatcher<T> equalTo(T expected, FieldFilter filter) Deprecated.Please use thedeepEquals(Object, FieldFilter)instead.static <T> org.hamcrest.Matcher<T> exactClassOf(Class<T> expected) Returns a Matcher that matches with exact class type defined by the givenexpected.static <T> org.hamcrest.Matcher<List<T>> exactSequenceOf(org.hamcrest.Matcher<T>... matchers) Matches a List of Events if each of the givenmatchersmatches against the event at the respective index in the list.static <T> org.hamcrest.Matcher<List<T>> listWithAllOf(org.hamcrest.Matcher<T>... matchers) Matches a List where all the given matchers must match with at least one of the items in that list.static <T> org.hamcrest.Matcher<List<T>> listWithAnyOf(org.hamcrest.Matcher<T>... matchers) Matches a List of Events where at least one of the givenmatchersmatches any of the Events in that list.static <T> org.hamcrest.Matcher<T> Returns a Matcher that matches with values defined by the givenpredicate.static org.hamcrest.Matcher<Message<?>> messageWithPayload(org.hamcrest.Matcher<?> payloadMatcher) Matches a single Message if the givenpayloadMatchermatches that message's payload.static org.hamcrest.Matcher<List<CommandMessage<?>>> Matches an empty List of Commands.static org.hamcrest.Matcher<List<EventMessage<?>>> noEvents()Matches an empty List of Events.static <T> org.hamcrest.Matcher<T> nothing()Matches againstnullorvoid.payloadsMatching(org.hamcrest.Matcher<? extends List<?>> matcher) Matches a list of Messages if a list containing their respective payloads matches the givenmatcher.static <T> org.hamcrest.Matcher<T> Returns a Matcher that matches with values defined by the givenpredicate.static <T> org.hamcrest.Matcher<List<T>> sequenceOf(org.hamcrest.Matcher<T>... matchers) Matches a list of Events if each of thematchersmatch against an Event that comes after the Event that the previous matcher matched against.
-
Method Details
-
payloadsMatching
public static org.hamcrest.Matcher<List<Message<?>>> payloadsMatching(org.hamcrest.Matcher<? extends List<?>> matcher) Matches a list of Messages if a list containing their respective payloads matches the givenmatcher.- Parameters:
matcher- The mather to match against the Message payloads- Returns:
- a Matcher that matches against the Message payloads
-
messageWithPayload
public static org.hamcrest.Matcher<Message<?>> messageWithPayload(org.hamcrest.Matcher<?> payloadMatcher) Matches a single Message if the givenpayloadMatchermatches that message's payload.- Parameters:
payloadMatcher- The matcher to match against the Message's payload- Returns:
- a Matcher that evaluates a Message's payload.
-
listWithAllOf
@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> listWithAllOf(org.hamcrest.Matcher<T>... matchers) Matches a List where all the given matchers must match with at least one of the items in that list.- Parameters:
matchers- the matchers that should match against one of the items in the List.- Returns:
- a matcher that matches a number of matchers against a list
-
listWithAnyOf
@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> listWithAnyOf(org.hamcrest.Matcher<T>... matchers) Matches a List of Events where at least one of the givenmatchersmatches any of the Events in that list.- Parameters:
matchers- the matchers that should match against one of the items in the List of Events.- Returns:
- a matcher that matches a number of event-matchers against a list of events
-
sequenceOf
@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> sequenceOf(org.hamcrest.Matcher<T>... matchers) Matches a list of Events if each of thematchersmatch against an Event that comes after the Event that the previous matcher matched against. This means that the givenmatchersmust match in order, but there may be "gaps" of unmatched events in between. To match the exact sequence of events (i.e. without gaps), useexactSequenceOf(org.hamcrest.Matcher[]).- Parameters:
matchers- the matchers to match against the list of events- Returns:
- a matcher that matches a number of event-matchers against a list of events
-
exactSequenceOf
@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> exactSequenceOf(org.hamcrest.Matcher<T>... matchers) Matches a List of Events if each of the givenmatchersmatches against the event at the respective index in the list. This means the first matcher must match the first event, the second matcher the second event, and so on. Any excess Events are ignored. If there are excess Matchers, they will be evaluated againstnull. To make sure the number of Events matches the number of Matchers, you can append an extraandNoMore()matcher. To allow "gaps" of unmatched Events, usesequenceOf(org.hamcrest.Matcher[])instead.- Parameters:
matchers- the matchers to match against the list of events- Returns:
- a matcher that matches a number of event-matchers against a list of events
-
matches
Returns a Matcher that matches with values defined by the givenpredicate.This method is a synonym for
predicate(Predicate)to allow for better readability- Type Parameters:
T- The type of value matched against- Parameters:
predicate- The predicate defining matching values- Returns:
- A Matcher that matches against values defined by the predicate
-
predicate
Returns a Matcher that matches with values defined by the givenpredicate.This method is a synonym for
matches(Predicate)to allow for better readability- Type Parameters:
T- The type of value matched against- Parameters:
predicate- The predicate defining matching values- Returns:
- A Matcher that matches against values defined by the predicate
-
noEvents
Matches an empty List of Events.- Returns:
- a matcher that matches an empty list of events
-
noCommands
Matches an empty List of Commands.- Returns:
- a matcher that matches an empty list of Commands
-
exactClassOf
Returns a Matcher that matches with exact class type defined by the givenexpected.- Type Parameters:
T- The object type to match the givenexpectedclass with.- Parameters:
expected- The expected class- Returns:
- a matcher that matches based on the class
-
equalTo
Deprecated.Please use thedeepEquals(Object)instead. Using this method will lead to unwanted exceptions when ran on JDK 17 and up, due to adjustments in reflective access.Matches against each event of the same runtime type that has all field values equal to the fields in the expected event. All fields are compared, except for the aggregate identifier and sequence number, as they are generally not set on the expected event.- Type Parameters:
T- The type of event to match against- Parameters:
expected- The event with the expected field values- Returns:
- a matcher that matches based on the equality of field values
-
equalTo
Deprecated.Please use thedeepEquals(Object, FieldFilter)instead. Using this method will lead to unwanted exceptions when ran on JDK 17 and up, due to adjustments in reflective access.Matches against each event of the same runtime type that has all field values equal to the fields in the expected event. All fields are compared, except for the aggregate identifier and sequence number, as they are generally not set on the expected event.- Type Parameters:
T- The type of event to match against- Parameters:
expected- The event with the expected field valuesfilter- The filter describing the Fields to include in the comparison- Returns:
- a matcher that matches based on the equality of field values
-
deepEquals
public static <T> org.hamcrest.Matcher<T> deepEquals(T expected) Constructs a deep equalsMatcher. ThisMatcherwill first perform a regular equals check based on the givenexpectedandactual(provided during theMatcher.matches(Object)invocation). If this fails and given type does not overrideObject.equals(Object), thisMatcherwill match the fields of the givenexpectedandactual.- Type Parameters:
T- The type of object to match against.- Parameters:
expected- The object to match against.- Returns:
- A matcher matching on
Object.equals(Object)firstly, followed by field value equality if equals isn't implemented.
-
deepEquals
Constructs a deep equalsMatcher. ThisMatcherwill first perform a regular equals check based on the givenexpectedandactual(provided during theMatcher.matches(Object)invocation). If this fails and given type does not overrideObject.equals(Object), thisMatcherwill match the fields of the givenexpectedandactual. Fields can be in- or excluded for this last step through thefilter.- Type Parameters:
T- The type of object to match against.- Parameters:
expected- The object to match against.filter- The filter describing the Fields to include in the comparison.- Returns:
- A matcher matching on
Object.equals(Object)firstly, followed by field value equality if equals isn't implemented.
-
andNoMore
public static <T> org.hamcrest.Matcher<T> andNoMore()Matches againstnullorvoid. Can be used to make sure no trailing events remain when using an Exact Sequence Matcher (exactSequenceOf(org.hamcrest.Matcher[])).- Returns:
- a matcher that matches against "nothing".
-
nothing
public static <T> org.hamcrest.Matcher<T> nothing()Matches againstnullorvoid. Can be used to make sure no trailing events remain when using an Exact Sequence Matcher (exactSequenceOf(org.hamcrest.Matcher[])).- Returns:
- a matcher that matches against "nothing".
-
deepEquals(Object)instead.