11/*
2- * Copyright 2002-2020 the original author or authors.
2+ * Copyright 2002-2021 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717package org .springframework .integration .handler ;
1818
1919import static org .assertj .core .api .Assertions .assertThat ;
20+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
2021import static org .mockito .Mockito .mock ;
2122
2223import java .lang .reflect .Method ;
3233
3334import org .apache .commons .logging .Log ;
3435import org .apache .commons .logging .LogFactory ;
35- import org .junit .Test ;
36+ import org .junit .jupiter . api . Test ;
3637
3738import org .springframework .beans .factory .BeanFactory ;
3839import org .springframework .integration .support .MessageBuilder ;
@@ -70,16 +71,10 @@ public void multiThreadsUUIDToStringConversion() throws Exception {
7071 ExecutorService exec = Executors .newFixedThreadPool (100 );
7172 processor .processMessage (new GenericMessage <>("foo" ));
7273 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 ());
8075 }
8176 exec .shutdown ();
82- assertThat (exec .awaitTermination (10 , TimeUnit .SECONDS )).isTrue ();
77+ assertThat (exec .awaitTermination (20 , TimeUnit .SECONDS )).isTrue ();
8378 assertThat (concurrencyFailures ).isEqualTo (0 );
8479 }
8580
@@ -92,15 +87,16 @@ public void optionalHeader() throws Exception {
9287 assertThat (result ).isNull ();
9388 }
9489
95- @ Test ( expected = MessageHandlingException . class )
90+ @ Test
9691 public void requiredHeaderNotProvided () throws Exception {
9792 Method method = TestService .class .getMethod ("requiredHeader" , Integer .class );
9893 MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
9994 processor .setBeanFactory (mock (BeanFactory .class ));
100- processor .processMessage (new GenericMessage <>("foo" ));
95+ assertThatExceptionOfType (MessageHandlingException .class )
96+ .isThrownBy (() -> processor .processMessage (new GenericMessage <>("foo" )));
10197 }
10298
103- @ Test ( expected = MessageHandlingException . class )
99+ @ Test
104100 public void requiredHeaderNotProvidedOnSecondMessage () throws Exception {
105101 Method method = TestService .class .getMethod ("requiredHeader" , Integer .class );
106102 MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
@@ -110,7 +106,8 @@ public void requiredHeaderNotProvidedOnSecondMessage() throws Exception {
110106 GenericMessage <String > messageWithoutHeader = new GenericMessage <>("foo" );
111107
112108 processor .processMessage (messageWithHeader );
113- processor .processMessage (messageWithoutHeader );
109+ assertThatExceptionOfType (MessageHandlingException .class )
110+ .isThrownBy (() -> processor .processMessage (messageWithoutHeader ));
114111 }
115112
116113 @ Test
@@ -124,14 +121,16 @@ public void fromMessageWithRequiredHeaderProvided() throws Exception {
124121 assertThat (result ).isEqualTo (123 );
125122 }
126123
127- @ Test ( expected = MessageHandlingException . class )
124+ @ Test
128125 public void fromMessageWithOptionalAndRequiredHeaderAndOnlyOptionalHeaderProvided () throws Exception {
129126 Method method = TestService .class .getMethod ("optionalAndRequiredHeader" , String .class , Integer .class );
130127 MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (testService , method );
131128 processor .setBeanFactory (mock (BeanFactory .class ));
132129 Message <String > message = MessageBuilder .withPayload ("foo" )
133130 .setHeader ("prop" , "bar" ).build ();
134- processor .processMessage (message );
131+
132+ assertThatExceptionOfType (MessageHandlingException .class )
133+ .isThrownBy (() -> processor .processMessage (message ));
135134 }
136135
137136 @ Test
@@ -342,13 +341,11 @@ public void fromMessageToPayloadArgsHeaderArgs() throws Exception {
342341 assertThat (result ).isEqualTo ("olegmonday" );
343342 }
344343
345- @ Test ( expected = MessagingException . class )
344+ @ Test
346345 public void fromMessageInvalidMethodWithMultipleMappingAnnotations () throws Exception {
347346 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 ));
352349 }
353350
354351 @ Test
@@ -468,7 +465,7 @@ public Object[] multipleAnnotatedArguments(@Header("day") String argA,
468465 @ Payload Employee payloadArg ,
469466 @ Payload ("fname" ) String value ,
470467 @ Headers Map <?, ?> headers ) {
471- return new Object [] { argA , argB , payloadArg , value , headers };
468+ return new Object []{ argA , argB , payloadArg , value , headers };
472469 }
473470
474471 public String irrelevantAnnotation (@ BogusAnnotation String value ) {
@@ -479,7 +476,7 @@ public String headerNameWithHyphen(@Header("foo-bar") String foobar) {
479476 return foobar .toUpperCase ();
480477 }
481478
482- Set <String > ids = Collections .synchronizedSet (new HashSet <String >());
479+ Set <String > ids = Collections .synchronizedSet (new HashSet <>());
483480
484481 public String headerId (String payload , @ Header ("id" ) String id ) {
485482 logger .debug (id );
0 commit comments