Class MockitoMessageMatchers
java.lang.Object
org.springframework.integration.test.matcher.MockitoMessageMatchers
public final class MockitoMessageMatchers extends Object
Mockito matcher factory for
Message
matcher creation.
This class contains expressive factory methods for the most common Mockito
matchers needed when matching Message
s. If you need a different
matching strategy, any Hamcrest matcher can be used in Mockito through
ArgumentMatchers.argThat(org.mockito.ArgumentMatcher)
.
Example usage:
With Mockito.verify(Object)
:
@Mock
MessageHandler handler;
...
handler.handleMessage(message);
verify(handler).handleMessage(messageWithPayload(SOME_PAYLOAD));
verify(handler).handleMessage(messageWithPayload(is(SOME_CLASS)));
With Mockito.when(Object)
:
...
when(channel.send(messageWithPayload(SOME_PAYLOAD))).thenReturn(true);
assertThat(channel.send(message), is(true));
- Author:
- Alex Peters, Iwein Fuld, Artem Bilan
-
Method Summary
Modifier and Type Method Description static Message<?>
messageWithHeaderEntries(Map<String,?> entries)
static Message<?>
messageWithHeaderEntry(String key, Object value)
static <T> Message<?>
messageWithHeaderEntry(String key, org.hamcrest.Matcher<T> valueMatcher)
static Message<?>
messageWithHeaderKey(String key)
static <T> Message<?>
messageWithPayload(org.hamcrest.Matcher<? super T> payloadMatcher)
static <T> Message<?>
messageWithPayload(T payload)