Class PayloadMatcher<T>

java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeMatcher<org.springframework.messaging.Message<?>>
org.springframework.integration.test.matcher.PayloadMatcher<T>
All Implemented Interfaces:
org.hamcrest.Matcher<org.springframework.messaging.Message<?>>, org.hamcrest.SelfDescribing

public final class PayloadMatcher<T>
extends org.hamcrest.TypeSafeMatcher<org.springframework.messaging.Message<?>>
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_PAYLOAD));
 
 

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

 
 ANY_PAYLOAD = new BigDecimal("1.123");
 Message<BigDecimal> message = MessageBuilder.withPayload(ANY_PAYLOAD).build();
 assertThat(message, PayloadMatcher.hasPayload(is(BigDecimal.class)));
 assertThat(message, PayloadMatcher.hasPayload(notNullValue()));
 assertThat(message, not((PayloadMatcher.hasPayload(is(String.class))))); *
 
 
  • Method Summary

    Modifier and Type Method Description
    void describeTo​(org.hamcrest.Description description)  
    static <P> PayloadMatcher<P> hasPayload​(org.hamcrest.Matcher<P> payloadMatcher)  
    static <P> PayloadMatcher<P> hasPayload​(P payload)  
    boolean matchesSafely​(org.springframework.messaging.Message<?> message)  

    Methods inherited from class org.hamcrest.TypeSafeMatcher

    describeMismatch, describeMismatchSafely, matches

    Methods inherited from class org.hamcrest.BaseMatcher

    _dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • matchesSafely

      public boolean matchesSafely​(org.springframework.messaging.Message<?> message)
      Specified by:
      matchesSafely in class org.hamcrest.TypeSafeMatcher<org.springframework.messaging.Message<?>>
    • describeTo

      public void describeTo​(org.hamcrest.Description description)
    • hasPayload

      public static <P> PayloadMatcher<P> hasPayload​(P payload)
    • hasPayload

      public static <P> PayloadMatcher<P> hasPayload​(org.hamcrest.Matcher<P> payloadMatcher)