Add MockMessageHandler to the Testing Framework
Fix PayloadMatcherTests for generics
Address PR comments and other improvements
* Revert `rawtypes` mode for the `PayloadMatcher`
* Make `HeaderMatcher` as `rawtypes` as well
* Make `MockMessageHandler` expect `rawtypes` for `Matcher`s.
This way we can just support `Matcher`s like `notNullValue(Message.class)`
* Rename `expect()` to `assertNext()`
* Rename `andReply()` to `thenReply()`
* Track replies are supplied in the `MockMessageHandler`
* Distinguish simple `MH` from the `MP` types in the
`MockIntegrationContext#instead()` do not let to replace simple `MH`
with fully configured `MockMessageHandler` or any other `MP` implementation.
Fail replace if types mismatch; wrap `MockMessageHandler` to simple `MH`
if it doesn't have replies when we are going to replace simple `MH`
* Wrap `MockMessageHandler` to the `Mockito.spy()` in the
`MockIntegration#mockMessageHandler()` to allow to `verify()` interaction
in the test-case
Remove wrapping `MockMH` to raw `MH` when no reply supported.
If `MockMH` isn't supplied with replies ti's safe to use it as is - no harm to target endpoint
which supposed to be last one in the flow
Some polishing and JavaDocs
More JavaDocs
Add docs for the `MockMessageHandler` and fix some JavaDocs
Make the `MockMessageHandler` with an API like:
```
MockIntegration.mockMessageHandler()
.handleNext(Consumer<Message<?>>)
.handleNext(Consumer<Message<?>>)
.handleNextAndReply(Function<Message<?>, Object>)
.handleNext(Consumer<Message<?>>)
.handleNextAndReply(Function<Message<?>, Object>)
.handleNextAndReply(Function<Message<?>, Object>);
```
Doc Polishing
This commit is contained in:
committed by
Gary Russell
parent
ea6cf0f4ef
commit
079ccb84e2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,51 +35,43 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
* @author Alex Peters
|
||||
* @author Iwein Fuld
|
||||
* @author Gunnar Hillert
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class PayloadMatcherTests {
|
||||
|
||||
static final BigDecimal ANY_PAYLOAD = new BigDecimal("1.123");
|
||||
private static final BigDecimal ANY_PAYLOAD = new BigDecimal("1.123");
|
||||
|
||||
Message<BigDecimal> message = MessageBuilder.withPayload(ANY_PAYLOAD).build();
|
||||
private final Message<BigDecimal> message = MessageBuilder.withPayload(ANY_PAYLOAD).build();
|
||||
|
||||
@Test
|
||||
public void hasPayload_withEqualValue_matches() throws Exception {
|
||||
assertThat(message, hasPayload(new BigDecimal("1.123")));
|
||||
assertThat(this.message, hasPayload(new BigDecimal("1.123")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPayload_withNotEqualValue_notMatching() throws Exception {
|
||||
assertThat(message, not(hasPayload(new BigDecimal("456"))));
|
||||
assertThat(this.message, not(hasPayload(new BigDecimal("456"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPayload_withMatcher_matches() throws Exception {
|
||||
assertThat(message,
|
||||
hasPayload(is(instanceOf(BigDecimal.class))));
|
||||
assertThat(message, hasPayload(notNullValue()));
|
||||
assertThat(this.message, hasPayload(is(instanceOf(BigDecimal.class))));
|
||||
assertThat(this.message, hasPayload(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPayload_withNotMatchingMatcher_notMatching()
|
||||
throws Exception {
|
||||
assertThat(message, not((hasPayload(is(instanceOf(String.class))))));
|
||||
public void hasPayload_withNotMatchingMatcher_notMatching() throws Exception {
|
||||
assertThat(this.message, not((hasPayload(is(instanceOf(String.class))))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readableException() throws Exception {
|
||||
try {
|
||||
assertThat(message, hasPayload("woot"));
|
||||
assertThat(this.message, hasPayload("woot"));
|
||||
}
|
||||
catch (AssertionError ae) {
|
||||
assertTrue(ae.getMessage().contains("Expected: a Message with payload: "));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void shouldMatchNonParametrizedMessage() throws Exception {
|
||||
Message message = this.message;
|
||||
assertThat(message, hasPayload(new BigDecimal("1.123")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user