Spring Integration

Class PayloadMatcher

  extended by org.hamcrest.BaseMatcher<T>
      extended by org.springframework.integration.test.matcher.PayloadMatcher
All Implemented Interfaces:
org.hamcrest.Matcher<Message>, org.hamcrest.SelfDescribing

public class PayloadMatcher
extends org.hamcrest.BaseMatcher<T>

Is the payload of a Message equal to a given value or is matching a given matcher?

A Junit example using Assert.assertThat(Object, Matcher) could look like this to test a payload value:

 ANY_PAYLOAD = new BigDecimal("1.123");
 Message<BigDecimal message = MessageBuilder.withPayload(ANY_PAYLOAD).build();
 assertThat(message, hasPayload(ANY_PAYLOjAD));

An example using Assert.assertThat(Object, Matcher) delegating to another Matcher.

 ANY_PAYLOAD = new BigDecimal("1.123");
 assertThat(message, PayloadMatcher.hasPayload(is(BigDecimal.class)));
 assertThat(message, PayloadMatcher.hasPayload(notNullValue()));
 assertThat(message, not((PayloadMatcher.hasPayload(is(String.class))))); *

Alex Peters, Iwein Fuld

Method Summary
 void describeTo(org.hamcrest.Description description)
<T> org.hamcrest.Matcher<Message>
hasPayload(org.hamcrest.Matcher<? super T> payloadMatcher)
<T> org.hamcrest.Matcher<Message>
hasPayload(T payload)
 boolean matches(java.lang.Object item)
          Method made final to prevent accidental override.
 boolean matchesSafely(Message message)
          Subclasses should implement this.
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Method Detail


public boolean matchesSafely(Message message)
Subclasses should implement this. The item will already have been checked for the specific type and will never be null.


public void describeTo(org.hamcrest.Description description)


public static <T> org.hamcrest.Matcher<Message> hasPayload(T payload)


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


public final boolean matches(java.lang.Object item)
Method made final to prevent accidental override. If you need to override this, there's no point on extending TypeSafeMatcher. Instead, extend the BaseMatcher.

Spring Integration