Spring Integration

org.springframework.integration.test.matcher
Class MockitoMessageMatchers

java.lang.Object
  extended by org.springframework.integration.test.matcher.MockitoMessageMatchers

public class MockitoMessageMatchers
extends java.lang.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 Matchers.argThat(Matcher).

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

Constructor Summary
MockitoMessageMatchers()
           
 
Method Summary
static Message<?> messageWithHeaderEntries(java.util.Map<java.lang.String,?> entries)
           
static
<T> Message<?>
messageWithHeaderEntry(java.lang.String key, org.hamcrest.Matcher<T> valueMatcher)
           
static Message<?> messageWithHeaderEntry(java.lang.String key, java.lang.Object value)
           
static Message<?> messageWithHeaderKey(java.lang.String key)
           
static
<T> Message<T>
messageWithPayload(org.hamcrest.Matcher<T> payloadMatcher)
           
static
<T> Message<T>
messageWithPayload(T payload)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockitoMessageMatchers

public MockitoMessageMatchers()
Method Detail

messageWithPayload

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

messageWithPayload

public static <T> Message<T> messageWithPayload(T payload)

messageWithHeaderEntry

public static Message<?> messageWithHeaderEntry(java.lang.String key,
                                                java.lang.Object value)

messageWithHeaderKey

public static Message<?> messageWithHeaderKey(java.lang.String key)

messageWithHeaderEntry

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

messageWithHeaderEntries

public static Message<?> messageWithHeaderEntries(java.util.Map<java.lang.String,?> entries)

Spring Integration