1
1
/*
2
- * Copyright 2002-2019 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 .amqp .channel ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
- import static org .assertj .core .api .Assertions .fail ;
20
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
21
21
import static org .mockito .ArgumentMatchers .any ;
22
22
import static org .mockito .ArgumentMatchers .anyBoolean ;
23
23
import static org .mockito .ArgumentMatchers .anyString ;
30
30
import java .util .List ;
31
31
32
32
import org .apache .commons .logging .Log ;
33
- import org .junit .Test ;
33
+ import org .junit .jupiter . api . Test ;
34
34
35
35
import org .springframework .amqp .core .AmqpTemplate ;
36
36
import org .springframework .amqp .core .Message ;
56
56
*/
57
57
public class DispatcherHasNoSubscribersTests {
58
58
59
- @ SuppressWarnings ("unchecked" )
60
59
@ Test
61
60
public void testPtP () throws Exception {
62
61
final Channel channel = mock (Channel .class );
@@ -79,14 +78,10 @@ public void testPtP() throws Exception {
79
78
amqpChannel .afterPropertiesSet ();
80
79
81
80
MessageListener listener = (MessageListener ) container .getMessageListener ();
82
- try {
83
- listener .onMessage (new Message ("Hello world!" .getBytes (), null ));
84
- fail ("Exception expected" );
85
- }
86
- catch (MessageDeliveryException e ) {
87
- assertThat (e .getMessage ())
88
- .contains ("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'." );
89
- }
81
+
82
+ assertThatExceptionOfType (MessageDeliveryException .class )
83
+ .isThrownBy (() -> listener .onMessage (new Message ("Hello world!" .getBytes ())))
84
+ .withMessageContaining ("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'." );
90
85
}
91
86
92
87
@ Test
@@ -99,24 +94,23 @@ public void testPubSub() {
99
94
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
100
95
container .setConnectionFactory (connectionFactory );
101
96
AmqpTemplate amqpTemplate = mock (AmqpTemplate .class );
102
- PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel ( "noSubscribersChannel" ,
103
- container , amqpTemplate );
97
+ PublishSubscribeAmqpChannel amqpChannel =
98
+ new PublishSubscribeAmqpChannel ( "noSubscribersChannel" , container , amqpTemplate );
104
99
amqpChannel .setBeanName ("noSubscribersChannel" );
105
100
amqpChannel .setBeanFactory (mock (BeanFactory .class ));
106
101
amqpChannel .afterPropertiesSet ();
107
102
108
103
List <String > logList = insertMockLoggerInListener (amqpChannel );
109
104
MessageListener listener = (MessageListener ) container .getMessageListener ();
110
- listener .onMessage (new Message ("Hello world!" .getBytes (), null ));
105
+ listener .onMessage (new Message ("Hello world!" .getBytes ()));
111
106
verifyLogReceived (logList );
112
107
}
113
108
114
- private List <String > insertMockLoggerInListener (
115
- PublishSubscribeAmqpChannel channel ) {
116
- SimpleMessageListenerContainer container = TestUtils .getPropertyValue (
117
- channel , "container" , SimpleMessageListenerContainer .class );
109
+ private static List <String > insertMockLoggerInListener (PublishSubscribeAmqpChannel channel ) {
110
+ SimpleMessageListenerContainer container =
111
+ TestUtils .getPropertyValue (channel , "container" , SimpleMessageListenerContainer .class );
118
112
Log logger = mock (Log .class );
119
- final ArrayList <String > logList = new ArrayList <String >();
113
+ final ArrayList <String > logList = new ArrayList <>();
120
114
doAnswer (invocation -> {
121
115
String message = invocation .getArgument (0 );
122
116
if (message .startsWith ("Dispatcher has no subscribers" )) {
@@ -131,7 +125,7 @@ private List<String> insertMockLoggerInListener(
131
125
return logList ;
132
126
}
133
127
134
- private void verifyLogReceived (final List <String > logList ) {
128
+ private static void verifyLogReceived (final List <String > logList ) {
135
129
assertThat (logList .size () > 0 ).as ("Failed to get expected exception" ).isTrue ();
136
130
boolean expectedExceptionFound = false ;
137
131
while (logList .size () > 0 ) {
0 commit comments