Skip to content

Commit f1033dc

Browse files
committed
Address PR comments
Signed-off-by: Jiandong Ma <[email protected]>
1 parent 89ac993 commit f1033dc

10 files changed

+92
-121
lines changed

spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessorTests.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
import org.springframework.messaging.support.GenericMessage;
4747

4848
import static org.assertj.core.api.Assertions.assertThat;
49-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
49+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
50+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
5051
import static org.assertj.core.api.Assertions.fail;
5152
import static org.mockito.Mockito.mock;
5253
import static org.mockito.Mockito.when;
@@ -502,8 +503,8 @@ public String method2(List<String> input) {
502503
}
503504

504505
MultipleAnnotationTestBean bean = new MultipleAnnotationTestBean();
505-
assertThatThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean))
506-
.isInstanceOf(IllegalArgumentException.class);
506+
assertThatIllegalArgumentException()
507+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
507508
}
508509

509510
@Test
@@ -548,8 +549,8 @@ public String lowerCase(String s) {
548549
}
549550

550551
MultiplePublicMethodTestBean bean = new MultiplePublicMethodTestBean();
551-
assertThatThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean))
552-
.isInstanceOf(IllegalArgumentException.class);
552+
assertThatIllegalArgumentException()
553+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
553554
}
554555

555556
@Test
@@ -565,8 +566,8 @@ String lowerCase(String s) {
565566
}
566567

567568
NoPublicMethodTestBean bean = new NoPublicMethodTestBean();
568-
assertThatThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean))
569-
.isInstanceOf(IllegalStateException.class);
569+
assertThatIllegalStateException()
570+
.isThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean));
570571
}
571572

572573
@Test

spring-integration-core/src/test/java/org/springframework/integration/channel/ChannelPurgerTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.springframework.messaging.support.GenericMessage;
2525

2626
import static org.assertj.core.api.Assertions.assertThat;
27-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
27+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2828

2929
/**
3030
* @author Mark Fisher
@@ -142,15 +142,15 @@ public void testPurgeNoneWithSelectorAndMultipleChannels() {
142142
@Test
143143
public void testNullChannel() {
144144
QueueChannel channel = null;
145-
assertThatThrownBy(() -> new ChannelPurger(channel))
146-
.isInstanceOf(IllegalArgumentException.class);
145+
assertThatIllegalArgumentException()
146+
.isThrownBy(() -> new ChannelPurger(channel));
147147
}
148148

149149
@Test
150150
public void testEmptyChannelArray() {
151151
QueueChannel[] channels = new QueueChannel[0];
152-
assertThatThrownBy(() -> new ChannelPurger(channels))
153-
.isInstanceOf(IllegalArgumentException.class);
152+
assertThatIllegalArgumentException()
153+
.isThrownBy(() -> new ChannelPurger(channels));
154154
}
155155

156156
}

spring-integration-core/src/test/java/org/springframework/integration/channel/DatatypeChannelTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.springframework.messaging.support.GenericMessage;
4646

4747
import static org.assertj.core.api.Assertions.assertThat;
48-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
48+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4949

5050
/**
5151
* @author Mark Fisher
@@ -65,8 +65,8 @@ public void supportedType() {
6565
@Test
6666
public void unsupportedTypeAndNoConversionService() {
6767
MessageChannel channel = createChannel(Integer.class);
68-
assertThatThrownBy(() -> channel.send(new GenericMessage<String>("123")))
69-
.isInstanceOf(MessageDeliveryException.class);
68+
assertThatExceptionOfType(MessageDeliveryException.class)
69+
.isThrownBy(() -> channel.send(new GenericMessage<String>("123")));
7070
}
7171

7272
@Test
@@ -86,8 +86,8 @@ public void unsupportedTypeAndConversionServiceDoesNotSupport() {
8686
DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
8787
converter.setConversionService(conversionService);
8888
channel.setMessageConverter(converter);
89-
assertThatThrownBy(() -> assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue())
90-
.isInstanceOf(MessageDeliveryException.class);
89+
assertThatExceptionOfType(MessageDeliveryException.class)
90+
.isThrownBy(() -> assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue());
9191
}
9292

9393
@Test
@@ -205,8 +205,8 @@ public void subclassOfAcceptedType() {
205205
@Test
206206
public void superclassOfAcceptedTypeNotAccepted() {
207207
MessageChannel channel = createChannel(RuntimeException.class);
208-
assertThatThrownBy(() -> channel.send(new ErrorMessage(new Exception("test"))))
209-
.isInstanceOf(MessageDeliveryException.class);
208+
assertThatExceptionOfType(MessageDeliveryException.class)
209+
.isThrownBy(() -> channel.send(new ErrorMessage(new Exception("test"))));
210210
}
211211

212212
@Test

spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.messaging.support.GenericMessage;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
30-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
30+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3131

3232
/**
3333
* @author Mark Fisher
@@ -52,8 +52,8 @@ public void testSingleSelectorRejects() {
5252
MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
5353
QueueChannel channel = new QueueChannel();
5454
channel.addInterceptor(interceptor);
55-
assertThatThrownBy(() -> channel.send(new GenericMessage<>("test1")))
56-
.isInstanceOf(MessageDeliveryException.class);
55+
assertThatExceptionOfType(MessageDeliveryException.class)
56+
.isThrownBy(() -> channel.send(new GenericMessage<>("test1")));
5757
}
5858

5959
@Test

spring-integration-core/src/test/java/org/springframework/integration/config/xml/MapToObjectTransformerParserTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
36-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
36+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3737

3838
/**
3939
* @author Oleg Zhurakousky
@@ -126,9 +126,9 @@ public void testMapToObjectTransformationWithConversionService() {
126126

127127
@Test
128128
public void testNonPrototypeFailure() {
129-
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("MapToObjectTransformerParserTests-context-fail.xml",
130-
MapToObjectTransformerParserTests.class).close())
131-
.isInstanceOf(BeanCreationException.class);
129+
assertThatExceptionOfType(BeanCreationException.class)
130+
.isThrownBy(() -> new ClassPathXmlApplicationContext("MapToObjectTransformerParserTests-context-fail.xml",
131+
MapToObjectTransformerParserTests.class));
132132
}
133133

134134
public static class Person {

spring-integration-core/src/test/java/org/springframework/integration/filter/MessageFilterTests.java

+19-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.messaging.support.GenericMessage;
2727

2828
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;
3030

3131
/**
3232
* @author Mark Fisher
@@ -60,8 +60,8 @@ public void filterThrowsException() {
6060
filter.setThrowExceptionOnRejection(true);
6161
QueueChannel output = new QueueChannel();
6262
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")));
6565
}
6666

6767
@Test
@@ -102,8 +102,8 @@ public void filterThrowsExceptionWithChannels() {
102102
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
103103
endpoint.start();
104104
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());
107107
}
108108

109109
@Test
@@ -136,21 +136,20 @@ public void filterDiscardsMessageAndThrowsException() {
136136
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
137137
endpoint.start();
138138
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);
154153

155154
}
156155

spring-integration-core/src/test/java/org/springframework/integration/filter/MethodInvokingSelectorTests.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.messaging.support.GenericMessage;
2626

2727
import static org.assertj.core.api.Assertions.assertThat;
28-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
28+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2929
import static org.mockito.Mockito.mock;
3030

3131
/**
@@ -88,19 +88,16 @@ public void noArgMethodWithMethodReference() throws Exception {
8888
public void voidReturningMethodWithMethodName() {
8989
MethodInvokingSelector selector = new MethodInvokingSelector(new TestBean(), "returnVoid");
9090
selector.setBeanFactory(mock(BeanFactory.class));
91-
assertThatThrownBy(() -> selector.accept(new GenericMessage<>("test")))
92-
.isInstanceOf(IllegalArgumentException.class);
91+
assertThatIllegalArgumentException()
92+
.isThrownBy(() -> selector.accept(new GenericMessage<>("test")));
9393
}
9494

9595
@Test
9696
public void voidReturningMethodWithMethodReference() throws Exception {
9797
TestBean testBean = new TestBean();
9898
Method method = testBean.getClass().getMethod("returnVoid", Message.class);
99-
assertThatThrownBy(() -> {
100-
MethodInvokingSelector selector = new MethodInvokingSelector(testBean, method);
101-
selector.setBeanFactory(mock(BeanFactory.class));
102-
selector.accept(new GenericMessage<>("test"));
103-
}).isInstanceOf(IllegalArgumentException.class);
99+
assertThatIllegalArgumentException()
100+
.isThrownBy(() -> new MethodInvokingSelector(testBean, method));
104101
}
105102

106103
@SuppressWarnings("unused")

spring-integration-core/src/test/java/org/springframework/integration/message/ExpressionEvaluatingMessageHandlerTests.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import org.springframework.messaging.MessagingException;
3131
import org.springframework.messaging.support.GenericMessage;
3232

33-
import static org.assertj.core.api.Assertions.assertThat;
34-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
33+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3534
import static org.mockito.Mockito.mock;
3635

3736
/**
@@ -84,16 +83,10 @@ public void expressionWithReturnValue() {
8483
ExpressionEvaluatingMessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
8584
handler.setBeanFactory(mock(BeanFactory.class));
8685
handler.afterPropertiesSet();
87-
assertThatThrownBy(() -> {
88-
try {
89-
handler.handleMessage(message);
90-
}
91-
catch (MessagingException e) {
92-
assertThat(message).isEqualTo(e.getFailedMessage());
93-
throw e;
94-
}
95-
}).isInstanceOf(MessagingException.class);
96-
86+
assertThatExceptionOfType(MessagingException.class)
87+
.isThrownBy(() -> handler.handleMessage(message))
88+
.extracting(MessagingException::getFailedMessage)
89+
.isEqualTo(message);
9790
}
9891

9992
}

spring-integration-core/src/test/java/org/springframework/integration/resource/ResourceInboundChannelAdapterParserTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.messaging.Message;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
37-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
37+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3838

3939
/**
4040
* @author Oleg Zhurakousky
@@ -85,8 +85,8 @@ public void testDefaultConfig() {
8585

8686
@Test
8787
public void testDefaultConfigNoLocationPattern() {
88-
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", getClass()).close())
89-
.isInstanceOf(BeanCreationException.class);
88+
assertThatExceptionOfType(BeanCreationException.class)
89+
.isThrownBy(() -> new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", getClass()));
9090
}
9191

9292
@Test

0 commit comments

Comments
 (0)