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 Messages. 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 Details

    • messageWithPayload

      public static <T> Message<?> messageWithPayload(org.hamcrest.Matcher<? super T> payloadMatcher)
    • messageWithPayload

      public static <T> Message<?> messageWithPayload(T payload)
    • messageWithHeaderEntry

      public static Message<?> messageWithHeaderEntry(String key, Object value)
    • messageWithHeaderKey

      public static Message<?> messageWithHeaderKey(String key)
    • messageWithHeaderEntry

      public static <T> Message<?> messageWithHeaderEntry(String key, org.hamcrest.Matcher<T> valueMatcher)
    • messageWithHeaderEntries

      public static Message<?> messageWithHeaderEntries(Map<String,?> entries)