@@ -134,7 +134,7 @@ public void testFailOnFirstUseWithMissingBroker() {
134
134
rabbitAdmin .setApplicationContext (applicationContext );
135
135
rabbitAdmin .setAutoStartup (true );
136
136
rabbitAdmin .afterPropertiesSet ();
137
- assertThatIllegalArgumentException ().isThrownBy (() -> rabbitAdmin . declareQueue () );
137
+ assertThatIllegalArgumentException ().isThrownBy (rabbitAdmin :: declareQueue );
138
138
connectionFactory .destroy ();
139
139
}
140
140
@@ -153,8 +153,7 @@ public void testProperties() throws Exception {
153
153
channel .basicConsume (queueName , true , consumer );
154
154
await ("Message count > 0" ).until (() -> messageCount (rabbitAdmin , queueName ) == 0 );
155
155
Properties props = rabbitAdmin .getQueueProperties (queueName );
156
- assertThat (props .get (RabbitAdmin .QUEUE_CONSUMER_COUNT )).isNotNull ();
157
- assertThat (props .get (RabbitAdmin .QUEUE_CONSUMER_COUNT )).isEqualTo (1 );
156
+ assertThat (props ).containsEntry (RabbitAdmin .QUEUE_CONSUMER_COUNT , 1 );
158
157
channel .close ();
159
158
}
160
159
finally {
@@ -170,23 +169,23 @@ private int messageCount(RabbitAdmin rabbitAdmin, String queueName) {
170
169
}
171
170
172
171
@ Test
173
- public void testTemporaryLogs () throws Exception {
172
+ public void testTemporaryLogs () {
174
173
SingleConnectionFactory connectionFactory = new SingleConnectionFactory ();
175
174
connectionFactory .setHost ("localhost" );
176
175
RabbitAdmin rabbitAdmin = new RabbitAdmin (connectionFactory );
177
176
try {
178
- ApplicationContext ctx = mock (ApplicationContext . class );
179
- Map <String , Queue > queues = new HashMap <String , Queue >();
177
+ ApplicationContext ctx = mock ();
178
+ Map <String , Queue > queues = new HashMap <>();
180
179
queues .put ("nonDurQ" , new Queue ("testq.nonDur" , false , false , false ));
181
180
queues .put ("adQ" , new Queue ("testq.ad" , true , false , true ));
182
181
queues .put ("exclQ" , new Queue ("testq.excl" , true , true , false ));
183
182
queues .put ("allQ" , new Queue ("testq.all" , false , true , true ));
184
- given (ctx .getBeansOfType (Queue .class )).willReturn (queues );
185
- Map <String , Exchange > exchanges = new HashMap <String , Exchange >();
183
+ given (ctx .getBeansOfType (Queue .class , false , false )).willReturn (queues );
184
+ Map <String , Exchange > exchanges = new HashMap <>();
186
185
exchanges .put ("nonDurEx" , new DirectExchange ("testex.nonDur" , false , false ));
187
186
exchanges .put ("adEx" , new DirectExchange ("testex.ad" , true , true ));
188
187
exchanges .put ("allEx" , new DirectExchange ("testex.all" , false , true ));
189
- given (ctx .getBeansOfType (Exchange .class )).willReturn (exchanges );
188
+ given (ctx .getBeansOfType (Exchange .class , false , false )).willReturn (exchanges );
190
189
rabbitAdmin .setApplicationContext (ctx );
191
190
rabbitAdmin .afterPropertiesSet ();
192
191
Log logger = spy (TestUtils .getPropertyValue (rabbitAdmin , "logger" , Log .class ));
@@ -247,17 +246,17 @@ public void testMultiEntities() {
247
246
assertThat (admin .getQueueProperties (ctx .getBean (Config .class ).prototypeQueueName )).isNull ();
248
247
Declarables mixedDeclarables = ctx .getBean ("ds" , Declarables .class );
249
248
assertThat (mixedDeclarables .getDeclarablesByType (Queue .class ))
250
- .hasSize (1 )
251
- .extracting (Queue ::getName )
252
- .contains ("q4" );
249
+ .hasSize (1 )
250
+ .extracting (Queue ::getName )
251
+ .contains ("q4" );
253
252
assertThat (mixedDeclarables .getDeclarablesByType (Exchange .class ))
254
- .hasSize (1 )
255
- .extracting (Exchange ::getName )
256
- .contains ("e4" );
253
+ .hasSize (1 )
254
+ .extracting (Exchange ::getName )
255
+ .contains ("e4" );
257
256
assertThat (mixedDeclarables .getDeclarablesByType (Binding .class ))
258
- .hasSize (1 )
259
- .extracting (Binding ::getDestination )
260
- .contains ("q4" );
257
+ .hasSize (1 )
258
+ .extracting (Binding ::getDestination )
259
+ .contains ("q4" );
261
260
ctx .close ();
262
261
}
263
262
@@ -283,14 +282,13 @@ public void testAvoidHangAMQP_508() {
283
282
284
283
@ Test
285
284
public void testIgnoreDeclarationExceptionsTimeout () throws Exception {
286
- com .rabbitmq .client .ConnectionFactory rabbitConnectionFactory = mock (
287
- com .rabbitmq .client .ConnectionFactory .class );
285
+ com .rabbitmq .client .ConnectionFactory rabbitConnectionFactory = mock ();
288
286
TimeoutException toBeThrown = new TimeoutException ("test" );
289
287
willThrow (toBeThrown ).given (rabbitConnectionFactory ).newConnection (any (ExecutorService .class ), anyString ());
290
288
CachingConnectionFactory ccf = new CachingConnectionFactory (rabbitConnectionFactory );
291
289
ccf .setExecutor (mock (ExecutorService .class ));
292
290
RabbitAdmin admin = new RabbitAdmin (ccf );
293
- List <DeclarationExceptionEvent > events = new ArrayList <DeclarationExceptionEvent >();
291
+ List <DeclarationExceptionEvent > events = new ArrayList <>();
294
292
admin .setApplicationEventPublisher (new EventPublisher (events ));
295
293
admin .setIgnoreDeclarationExceptions (true );
296
294
admin .declareQueue (new AnonymousQueue ());
@@ -313,13 +311,13 @@ public void testIgnoreDeclarationExceptionsTimeout() throws Exception {
313
311
314
312
@ Test
315
313
public void testWithinInvoke () throws Exception {
316
- ConnectionFactory connectionFactory = mock (ConnectionFactory . class );
317
- Connection connection = mock (Connection . class );
314
+ ConnectionFactory connectionFactory = mock ();
315
+ Connection connection = mock ();
318
316
given (connectionFactory .createConnection ()).willReturn (connection );
319
- Channel channel1 = mock (Channel . class );
320
- Channel channel2 = mock (Channel . class );
317
+ Channel channel1 = mock ();
318
+ Channel channel2 = mock ();
321
319
given (connection .createChannel (false )).willReturn (channel1 , channel2 );
322
- DeclareOk declareOk = mock (DeclareOk . class );
320
+ DeclareOk declareOk = mock ();
323
321
given (channel1 .queueDeclare ()).willReturn (declareOk );
324
322
given (declareOk .getQueue ()).willReturn ("foo" );
325
323
RabbitTemplate template = new RabbitTemplate (connectionFactory );
@@ -339,14 +337,14 @@ public void testWithinInvoke() throws Exception {
339
337
340
338
@ Test
341
339
public void testRetry () throws Exception {
342
- com .rabbitmq .client .ConnectionFactory rabbitConnectionFactory = mock (com . rabbitmq . client . ConnectionFactory . class );
343
- com .rabbitmq .client .Connection connection = mock (com . rabbitmq . client . Connection . class );
340
+ com .rabbitmq .client .ConnectionFactory rabbitConnectionFactory = mock ();
341
+ com .rabbitmq .client .Connection connection = mock ();
344
342
given (rabbitConnectionFactory .newConnection ((ExecutorService ) isNull (), anyString ())).willReturn (connection );
345
- Channel channel = mock (Channel . class );
343
+ Channel channel = mock ();
346
344
given (connection .createChannel ()).willReturn (channel );
347
345
given (channel .isOpen ()).willReturn (true );
348
346
willThrow (new RuntimeException ()).given (channel )
349
- .queueDeclare (anyString (), anyBoolean (), anyBoolean (), anyBoolean (), any ());
347
+ .queueDeclare (anyString (), anyBoolean (), anyBoolean (), anyBoolean (), any ());
350
348
CachingConnectionFactory ccf = new CachingConnectionFactory (rabbitConnectionFactory );
351
349
RabbitAdmin admin = new RabbitAdmin (ccf );
352
350
RetryTemplate rtt = new RetryTemplate ();
@@ -359,13 +357,13 @@ public void testRetry() throws Exception {
359
357
ctx .getBeanFactory ().initializeBean (admin , "admin" );
360
358
ctx .refresh ();
361
359
assertThatThrownBy (() -> ccf .createConnection ())
362
- .isInstanceOf (UncategorizedAmqpException .class );
360
+ .isInstanceOf (UncategorizedAmqpException .class );
363
361
ctx .close ();
364
362
verify (channel , times (3 )).queueDeclare (anyString (), anyBoolean (), anyBoolean (), anyBoolean (), any ());
365
363
}
366
364
367
365
@ Test
368
- public void testLeaderLocator () throws Exception {
366
+ public void testLeaderLocator () {
369
367
CachingConnectionFactory cf = new CachingConnectionFactory (
370
368
RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
371
369
RabbitAdmin admin = new RabbitAdmin (cf );
0 commit comments