|
26 | 26 | import org.springframework.messaging.support.GenericMessage;
|
27 | 27 |
|
28 | 28 | import static org.assertj.core.api.Assertions.assertThat;
|
29 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 29 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
30 | 30 |
|
31 | 31 | /**
|
32 | 32 | * @author Mark Fisher
|
@@ -60,8 +60,8 @@ public void filterThrowsException() {
|
60 | 60 | filter.setThrowExceptionOnRejection(true);
|
61 | 61 | QueueChannel output = new QueueChannel();
|
62 | 62 | filter.setOutputChannel(output);
|
63 |
| - assertThatThrownBy(() -> filter.handleMessage(new GenericMessage<String>("test"))) |
64 |
| - .isInstanceOf(MessageRejectedException.class); |
| 63 | + assertThatExceptionOfType(MessageRejectedException.class) |
| 64 | + .isThrownBy(() -> filter.handleMessage(new GenericMessage<String>("test"))); |
65 | 65 | }
|
66 | 66 |
|
67 | 67 | @Test
|
@@ -102,8 +102,8 @@ public void filterThrowsExceptionWithChannels() {
|
102 | 102 | EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
|
103 | 103 | endpoint.start();
|
104 | 104 | Message<?> message = new GenericMessage<String>("test");
|
105 |
| - assertThatThrownBy(() -> assertThat(inputChannel.send(message)).isTrue()) |
106 |
| - .isInstanceOf(MessageRejectedException.class); |
| 105 | + assertThatExceptionOfType(MessageRejectedException.class) |
| 106 | + .isThrownBy(() -> assertThat(inputChannel.send(message)).isTrue()); |
107 | 107 | }
|
108 | 108 |
|
109 | 109 | @Test
|
@@ -136,21 +136,20 @@ public void filterDiscardsMessageAndThrowsException() {
|
136 | 136 | EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
|
137 | 137 | endpoint.start();
|
138 | 138 | Message<?> message = new GenericMessage<String>("test");
|
139 |
| - assertThatThrownBy(() -> { |
140 |
| - try { |
141 |
| - assertThat(inputChannel.send(message)).isTrue(); |
142 |
| - } |
143 |
| - catch (Exception e) { |
144 |
| - throw e; |
145 |
| - } |
146 |
| - finally { |
147 |
| - Message<?> reply = discardChannel.receive(0); |
148 |
| - assertThat(reply).isNotNull(); |
149 |
| - assertThat(reply).isEqualTo(message); |
150 |
| - assertThat(outputChannel.receive(0)).isNull(); |
151 |
| - } |
152 |
| - |
153 |
| - }).isInstanceOf(MessageRejectedException.class); |
| 139 | + Exception caughtException = null; |
| 140 | + try { |
| 141 | + assertThat(inputChannel.send(message)).isTrue(); |
| 142 | + } |
| 143 | + catch (Exception e) { |
| 144 | + caughtException = e; |
| 145 | + } |
| 146 | + finally { |
| 147 | + Message<?> reply = discardChannel.receive(0); |
| 148 | + assertThat(reply).isNotNull(); |
| 149 | + assertThat(reply).isEqualTo(message); |
| 150 | + assertThat(outputChannel.receive(0)).isNull(); |
| 151 | + } |
| 152 | + assertThat(caughtException).isInstanceOf(MessageRejectedException.class); |
154 | 153 |
|
155 | 154 | }
|
156 | 155 |
|
|
0 commit comments