11/*
2- * Copyright 2002-2019 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 .amqp .channel ;
1818
1919import 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 ;
2121import static org .mockito .ArgumentMatchers .any ;
2222import static org .mockito .ArgumentMatchers .anyBoolean ;
2323import static org .mockito .ArgumentMatchers .anyString ;
3030import java .util .List ;
3131
3232import org .apache .commons .logging .Log ;
33- import org .junit .Test ;
33+ import org .junit .jupiter . api . Test ;
3434
3535import org .springframework .amqp .core .AmqpTemplate ;
3636import org .springframework .amqp .core .Message ;
5656 */
5757public class DispatcherHasNoSubscribersTests {
5858
59- @ SuppressWarnings ("unchecked" )
6059 @ Test
6160 public void testPtP () throws Exception {
6261 final Channel channel = mock (Channel .class );
@@ -79,14 +78,10 @@ public void testPtP() throws Exception {
7978 amqpChannel .afterPropertiesSet ();
8079
8180 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'." );
9085 }
9186
9287 @ Test
@@ -99,24 +94,23 @@ public void testPubSub() {
9994 SimpleMessageListenerContainer container = new SimpleMessageListenerContainer ();
10095 container .setConnectionFactory (connectionFactory );
10196 AmqpTemplate amqpTemplate = mock (AmqpTemplate .class );
102- PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel ( "noSubscribersChannel" ,
103- container , amqpTemplate );
97+ PublishSubscribeAmqpChannel amqpChannel =
98+ new PublishSubscribeAmqpChannel ( "noSubscribersChannel" , container , amqpTemplate );
10499 amqpChannel .setBeanName ("noSubscribersChannel" );
105100 amqpChannel .setBeanFactory (mock (BeanFactory .class ));
106101 amqpChannel .afterPropertiesSet ();
107102
108103 List <String > logList = insertMockLoggerInListener (amqpChannel );
109104 MessageListener listener = (MessageListener ) container .getMessageListener ();
110- listener .onMessage (new Message ("Hello world!" .getBytes (), null ));
105+ listener .onMessage (new Message ("Hello world!" .getBytes ()));
111106 verifyLogReceived (logList );
112107 }
113108
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 );
118112 Log logger = mock (Log .class );
119- final ArrayList <String > logList = new ArrayList <String >();
113+ final ArrayList <String > logList = new ArrayList <>();
120114 doAnswer (invocation -> {
121115 String message = invocation .getArgument (0 );
122116 if (message .startsWith ("Dispatcher has no subscribers" )) {
@@ -131,7 +125,7 @@ private List<String> insertMockLoggerInListener(
131125 return logList ;
132126 }
133127
134- private void verifyLogReceived (final List <String > logList ) {
128+ private static void verifyLogReceived (final List <String > logList ) {
135129 assertThat (logList .size () > 0 ).as ("Failed to get expected exception" ).isTrue ();
136130 boolean expectedExceptionFound = false ;
137131 while (logList .size () > 0 ) {
0 commit comments