11/*
2- * Copyright 2002-2021 the original author or authors.
2+ * Copyright 2002-2022 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.
@@ -371,24 +371,33 @@ public void testNoListenerAllowed2() {
371371 @ SuppressWarnings ("unchecked" )
372372 public void testRoutingConnectionFactory () throws Exception {
373373 org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory1 =
374- Mockito . mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
374+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
375375 org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory2 =
376- Mockito .mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
376+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
377+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory3 =
378+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
379+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory4 =
380+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
377381 Map <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory > factories =
378382 new HashMap <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory >(2 );
379383 factories .put ("foo" , connectionFactory1 );
380384 factories .put ("bar" , connectionFactory2 );
385+ factories .put ("baz" , connectionFactory3 );
386+ factories .put ("qux" , connectionFactory4 );
381387
382388
383389 AbstractRoutingConnectionFactory connectionFactory = new SimpleRoutingConnectionFactory ();
384390 connectionFactory .setTargetConnectionFactories (factories );
385391
386392 final RabbitTemplate template = new RabbitTemplate (connectionFactory );
387- Expression expression = new SpelExpressionParser ()
393+ Expression sendExpression = new SpelExpressionParser ()
388394 .parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
389395 ".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'foo' : 'bar'" );
390- template .setSendConnectionFactorySelectorExpression (expression );
391- template .setReceiveConnectionFactorySelectorExpression (expression );
396+ template .setSendConnectionFactorySelectorExpression (sendExpression );
397+ Expression receiveExpression = new SpelExpressionParser ()
398+ .parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
399+ ".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'baz' : 'qux'" );
400+ template .setReceiveConnectionFactorySelectorExpression (receiveExpression );
392401
393402 for (int i = 0 ; i < 3 ; i ++) {
394403 try {
@@ -411,8 +420,10 @@ public void testRoutingConnectionFactory() throws Exception {
411420 }
412421 }
413422
414- Mockito .verify (connectionFactory1 , Mockito .times (5 )).createConnection ();
415- Mockito .verify (connectionFactory2 , Mockito .times (4 )).createConnection ();
423+ Mockito .verify (connectionFactory1 , times (2 )).createConnection ();
424+ Mockito .verify (connectionFactory2 , times (1 )).createConnection ();
425+ Mockito .verify (connectionFactory3 , times (3 )).createConnection ();
426+ Mockito .verify (connectionFactory4 , times (3 )).createConnection ();
416427 }
417428
418429 @ Test
0 commit comments