1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .integration .handler ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
20
21
import static org .mockito .Mockito .mock ;
21
22
22
23
import java .lang .reflect .Method ;
32
33
33
34
import org .apache .commons .logging .Log ;
34
35
import org .apache .commons .logging .LogFactory ;
35
- import org .junit .Test ;
36
+ import org .junit .jupiter . api . Test ;
36
37
37
38
import org .springframework .beans .factory .BeanFactory ;
38
39
import org .springframework .integration .support .MessageBuilder ;
@@ -70,16 +71,10 @@ public void multiThreadsUUIDToStringConversion() throws Exception {
70
71
ExecutorService exec = Executors .newFixedThreadPool (100 );
71
72
processor .processMessage (new GenericMessage <>("foo" ));
72
73
for (int i = 0 ; i < 100 ; i ++) {
73
- exec .execute (new Runnable () {
74
-
75
- public void run () {
76
- Object result = processor .processMessage (new GenericMessage <>("foo" ));
77
- assertThat (result ).isNotNull ();
78
- }
79
- });
74
+ exec .execute (() -> assertThat (processor .processMessage (new GenericMessage <>("foo" ))).isNotNull ());
80
75
}
81
76
exec .shutdown ();
82
- assertThat (exec .awaitTermination (10 , TimeUnit .SECONDS )).isTrue ();
77
+ assertThat (exec .awaitTermination (20 , TimeUnit .SECONDS )).isTrue ();
83
78
assertThat (concurrencyFailures ).isEqualTo (0 );
84
79
}
85
80
@@ -92,15 +87,16 @@ public void optionalHeader() throws Exception {
92
87
assertThat (result ).isNull ();
93
88
}
94
89
95
- @ Test ( expected = MessageHandlingException . class )
90
+ @ Test
96
91
public void requiredHeaderNotProvided () throws Exception {
97
92
Method method = TestService .class .getMethod ("requiredHeader" , Integer .class );
98
93
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
99
94
processor .setBeanFactory (mock (BeanFactory .class ));
100
- processor .processMessage (new GenericMessage <>("foo" ));
95
+ assertThatExceptionOfType (MessageHandlingException .class )
96
+ .isThrownBy (() -> processor .processMessage (new GenericMessage <>("foo" )));
101
97
}
102
98
103
- @ Test ( expected = MessageHandlingException . class )
99
+ @ Test
104
100
public void requiredHeaderNotProvidedOnSecondMessage () throws Exception {
105
101
Method method = TestService .class .getMethod ("requiredHeader" , Integer .class );
106
102
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
@@ -110,7 +106,8 @@ public void requiredHeaderNotProvidedOnSecondMessage() throws Exception {
110
106
GenericMessage <String > messageWithoutHeader = new GenericMessage <>("foo" );
111
107
112
108
processor .processMessage (messageWithHeader );
113
- processor .processMessage (messageWithoutHeader );
109
+ assertThatExceptionOfType (MessageHandlingException .class )
110
+ .isThrownBy (() -> processor .processMessage (messageWithoutHeader ));
114
111
}
115
112
116
113
@ Test
@@ -124,14 +121,16 @@ public void fromMessageWithRequiredHeaderProvided() throws Exception {
124
121
assertThat (result ).isEqualTo (123 );
125
122
}
126
123
127
- @ Test ( expected = MessageHandlingException . class )
124
+ @ Test
128
125
public void fromMessageWithOptionalAndRequiredHeaderAndOnlyOptionalHeaderProvided () throws Exception {
129
126
Method method = TestService .class .getMethod ("optionalAndRequiredHeader" , String .class , Integer .class );
130
127
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
131
128
processor .setBeanFactory (mock (BeanFactory .class ));
132
129
Message <String > message = MessageBuilder .withPayload ("foo" )
133
130
.setHeader ("prop" , "bar" ).build ();
134
- processor .processMessage (message );
131
+
132
+ assertThatExceptionOfType (MessageHandlingException .class )
133
+ .isThrownBy (() -> processor .processMessage (message ));
135
134
}
136
135
137
136
@ Test
@@ -342,13 +341,11 @@ public void fromMessageToPayloadArgsHeaderArgs() throws Exception {
342
341
assertThat (result ).isEqualTo ("olegmonday" );
343
342
}
344
343
345
- @ Test ( expected = MessagingException . class )
344
+ @ Test
346
345
public void fromMessageInvalidMethodWithMultipleMappingAnnotations () throws Exception {
347
346
Method method = MultipleMappingAnnotationTestBean .class .getMethod ("test" , String .class );
348
- MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
349
- processor .setBeanFactory (mock (BeanFactory .class ));
350
- Message <?> message = MessageBuilder .withPayload ("payload" ).setHeader ("foo" , "bar" ).build ();
351
- processor .processMessage (message );
347
+ assertThatExceptionOfType (MessagingException .class )
348
+ .isThrownBy (() -> new MethodInvokingMessageProcessor (testService , method ));
352
349
}
353
350
354
351
@ Test
@@ -468,7 +465,7 @@ public Object[] multipleAnnotatedArguments(@Header("day") String argA,
468
465
@ Payload Employee payloadArg ,
469
466
@ Payload ("fname" ) String value ,
470
467
@ Headers Map <?, ?> headers ) {
471
- return new Object [] { argA , argB , payloadArg , value , headers };
468
+ return new Object []{ argA , argB , payloadArg , value , headers };
472
469
}
473
470
474
471
public String irrelevantAnnotation (@ BogusAnnotation String value ) {
@@ -479,7 +476,7 @@ public String headerNameWithHyphen(@Header("foo-bar") String foobar) {
479
476
return foobar .toUpperCase ();
480
477
}
481
478
482
- Set <String > ids = Collections .synchronizedSet (new HashSet <String >());
479
+ Set <String > ids = Collections .synchronizedSet (new HashSet <>());
483
480
484
481
public String headerId (String payload , @ Header ("id" ) String id ) {
485
482
logger .debug (id );
0 commit comments