public abstract class Matchers extends Object
Modifier and Type | Method and Description |
---|---|
static <T> org.hamcrest.Matcher<T> |
andNoMore()
Matches against
null or void . |
static <T> org.hamcrest.Matcher<T> |
deepEquals(T expected)
Constructs a deep equals
Matcher . |
static <T> org.hamcrest.Matcher<T> |
deepEquals(T expected,
FieldFilter filter)
Constructs a deep equals
Matcher . |
static <T> EqualFieldsMatcher<T> |
equalTo(T expected)
Deprecated.
Please use the
deepEquals(Object) instead. Using this method will lead to unwanted
exceptions when ran on JDK 17 and up, due to adjustments in reflective access. |
static <T> EqualFieldsMatcher<T> |
equalTo(T expected,
FieldFilter filter)
Deprecated.
Please use the
deepEquals(Object, FieldFilter) instead. Using this method will lead to
unwanted exceptions when ran on JDK 17 and up, due to adjustments in reflective access. |
static <T> org.hamcrest.Matcher<T> |
exactClassOf(Class<T> expected)
Returns a Matcher that matches with exact class type defined by the given
expected . |
static <T> org.hamcrest.Matcher<List<T>> |
exactSequenceOf(org.hamcrest.Matcher<T>... matchers)
Matches a List of Events if each of the given
matchers matches 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 given
matchers matches any of the Events in that
list. |
static <T> org.hamcrest.Matcher<T> |
matches(Predicate<T> predicate)
Returns a Matcher that matches with values defined by the given
predicate . |
static org.hamcrest.Matcher<Message<?>> |
messageWithPayload(org.hamcrest.Matcher<?> payloadMatcher)
Matches a single Message if the given
payloadMatcher matches that message's payload. |
static org.hamcrest.Matcher<List<CommandMessage<?>>> |
noCommands()
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 against
null or void . |
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 given
matcher . |
static <T> org.hamcrest.Matcher<T> |
predicate(Predicate<T> predicate)
Returns a Matcher that matches with values defined by the given
predicate . |
static <T> org.hamcrest.Matcher<List<T>> |
sequenceOf(org.hamcrest.Matcher<T>... matchers)
Matches a list of Events if each of the
matchers match against an Event that comes after the Event
that the previous matcher matched against. |
public static org.hamcrest.Matcher<List<Message<?>>> payloadsMatching(org.hamcrest.Matcher<? extends List<?>> matcher)
matcher
.matcher
- The mather to match against the Message payloadspublic static org.hamcrest.Matcher<Message<?>> messageWithPayload(org.hamcrest.Matcher<?> payloadMatcher)
payloadMatcher
matches that message's payload.payloadMatcher
- The matcher to match against the Message's payload@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> listWithAllOf(org.hamcrest.Matcher<T>... matchers)
matchers
- the matchers that should match against one of the items in the List.@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> listWithAnyOf(org.hamcrest.Matcher<T>... matchers)
matchers
matches any of the Events in that
list.matchers
- the matchers that should match against one of the items in the List of Events.@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> sequenceOf(org.hamcrest.Matcher<T>... matchers)
matchers
match against an Event that comes after the Event
that the previous matcher matched against. This means that the given matchers
must match in order,
but there may be "gaps" of unmatched events in between.
To match the exact sequence of events (i.e. without gaps), use exactSequenceOf(org.hamcrest.Matcher[])
.matchers
- the matchers to match against the list of events@SafeVarargs public static <T> org.hamcrest.Matcher<List<T>> exactSequenceOf(org.hamcrest.Matcher<T>... matchers)
matchers
matches 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 against null
.
To
make sure the number of Events matches the number of Matchers, you can append an extra andNoMore()
matcher.
To allow "gaps" of unmatched Events, use sequenceOf(org.hamcrest.Matcher[])
instead.matchers
- the matchers to match against the list of eventspublic static <T> org.hamcrest.Matcher<T> matches(Predicate<T> predicate)
predicate
.
This method is a synonym for predicate(Predicate)
to allow for better readability
T
- The type of value matched againstpredicate
- The predicate defining matching valuespublic static <T> org.hamcrest.Matcher<T> predicate(Predicate<T> predicate)
predicate
.
This method is a synonym for matches(Predicate)
to allow for better readability
T
- The type of value matched againstpredicate
- The predicate defining matching valuespublic static org.hamcrest.Matcher<List<EventMessage<?>>> noEvents()
public static org.hamcrest.Matcher<List<CommandMessage<?>>> noCommands()
public static <T> org.hamcrest.Matcher<T> exactClassOf(Class<T> expected)
expected
.T
- The object type to match the given expected
class with.expected
- The expected class@Deprecated public static <T> EqualFieldsMatcher<T> equalTo(T expected)
deepEquals(Object)
instead. Using this method will lead to unwanted
exceptions when ran on JDK 17 and up, due to adjustments in reflective access.T
- The type of event to match againstexpected
- The event with the expected field values@Deprecated public static <T> EqualFieldsMatcher<T> equalTo(T expected, FieldFilter filter)
deepEquals(Object, FieldFilter)
instead. Using this method will lead to
unwanted exceptions when ran on JDK 17 and up, due to adjustments in reflective access.T
- The type of event to match againstexpected
- The event with the expected field valuesfilter
- The filter describing the Fields to include in the comparisonpublic static <T> org.hamcrest.Matcher<T> deepEquals(T expected)
Matcher
. This Matcher
will first perform a regular equals check based on
the given expected
and actual
(provided during the Matcher.matches(Object)
invocation).
If this fails and given type does not override Object.equals(Object)
, this Matcher
will
match the fields of the given expected
and actual
.T
- The type of object to match against.expected
- The object to match against.Object.equals(Object)
firstly, followed by field value equality if equals
isn't implemented.public static <T> org.hamcrest.Matcher<T> deepEquals(T expected, FieldFilter filter)
Matcher
. This Matcher
will first perform a regular equals check based on
the given expected
and actual
(provided during the Matcher.matches(Object)
invocation).
If this fails and given type does not override Object.equals(Object)
, this Matcher
will
match the fields of the given expected
and actual
. Fields can be in- or excluded for this last
step through the filter
.T
- The type of object to match against.expected
- The object to match against.filter
- The filter describing the Fields to include in the comparison.Object.equals(Object)
firstly, followed by field value equality if equals
isn't implemented.public static <T> org.hamcrest.Matcher<T> andNoMore()
null
or void
. Can be used to make sure no trailing events remain when
using an Exact Sequence Matcher (exactSequenceOf(org.hamcrest.Matcher[])
).public static <T> org.hamcrest.Matcher<T> nothing()
null
or void
. Can be used to make sure no trailing events remain when
using an Exact Sequence Matcher (exactSequenceOf(org.hamcrest.Matcher[])
).Copyright © 2010–2023. All rights reserved.