Add non-parametrized message support to PayloadMatcher.

- add testcase (which used to cause compiler failure)
- remove <?> from PayloadMatcher to fix error
- add casts to FileInboundCAWRDTests to deal with backwards compatibility breakage

In some cases backwards compatibility is broken, see INT-1790 for details.
This commit is contained in:
Iwein Fuld
2011-02-08 14:32:54 +01:00
parent 57192121fb
commit 3955c9d6fb
3 changed files with 16 additions and 9 deletions

View File

@@ -70,7 +70,7 @@ public class FileInboundChannelAdapterWithRecursiveDirectoryTests {
File childFile = new File(folder, "baz");
assertTrue(childFile.createNewFile());
List<Message<?>> received = Arrays.asList(files.receive(), files.receive());
List<Message> received = Arrays.asList((Message) files.receive(), files.receive());
//verify
assertThat(received, hasItems(hasPayload(siblingFile), hasPayload(childFile)));
}

View File

@@ -53,14 +53,14 @@ import org.springframework.integration.Message;
* @author Iwein Fuld
*
*/
public class PayloadMatcher extends TypeSafeMatcher<Message<?>> {
public class PayloadMatcher extends TypeSafeMatcher<Message> {
private final Matcher<?> matcher;
private final Matcher matcher;
/**
* @param matcher
* Create a PayloadMatcher that matches the payload of messages against the given matcher
*/
PayloadMatcher(Matcher<?> matcher) {
PayloadMatcher(Matcher matcher) {
super();
this.matcher = matcher;
}
@@ -69,7 +69,7 @@ public class PayloadMatcher extends TypeSafeMatcher<Message<?>> {
* {@inheritDoc}
*/
@Override
public boolean matchesSafely(Message<?> message) {
public boolean matchesSafely(Message message) {
return matcher.matches(message.getPayload());
}
@@ -83,12 +83,12 @@ public class PayloadMatcher extends TypeSafeMatcher<Message<?>> {
}
@Factory
public static <T> Matcher<Message<?>> hasPayload(T payload) {
public static <T> Matcher<Message> hasPayload(T payload) {
return new PayloadMatcher(IsEqual.equalTo(payload));
}
@Factory
public static <T> Matcher<Message<?>> hasPayload(Matcher<T> payloadMatcher) {
public static <T> Matcher<Message> hasPayload(Matcher<? super T> payloadMatcher) {
return new PayloadMatcher(payloadMatcher);
}
}

View File

@@ -36,7 +36,7 @@ public class PayloadMatcherTests {
static final BigDecimal ANY_PAYLOAD = new BigDecimal("1.123");
Message<BigDecimal> message =MessageBuilder.withPayload(ANY_PAYLOAD).build();;
Message<BigDecimal> message = MessageBuilder.withPayload(ANY_PAYLOAD).build();
@Test
public void hasPayload_withEqualValue_matches() throws Exception {
@@ -69,4 +69,11 @@ public class PayloadMatcherTests {
assertTrue(ae.getMessage().contains("Expected: a Message with payload: "));
}
}
@Test
public void shouldMatchNonParametrizedMessage() throws Exception {
Message message = this.message;
assertThat(message, hasPayload(new BigDecimal("1.123")));
}
}