2222import static org .mockito .ArgumentMatchers .any ;
2323import static org .mockito .ArgumentMatchers .anyBoolean ;
2424import static org .mockito .ArgumentMatchers .anyInt ;
25+ import static org .mockito .ArgumentMatchers .anyList ;
2526import static org .mockito .ArgumentMatchers .anyLong ;
2627import static org .mockito .ArgumentMatchers .anyString ;
2728import static org .mockito .ArgumentMatchers .argThat ;
@@ -117,7 +118,7 @@ void stringRepresentation() {
117118 assertThat (ccf .toString ()).contains (", addresses=[h3:1236, h4:1237]" )
118119 .doesNotContain ("host" )
119120 .doesNotContain ("port" );
120- ccf .setAddressResolver (() -> {
121+ ccf .setAddressResolver (() -> {
121122 throw new IOException ("test" );
122123 });
123124 ccf .setPort (0 );
@@ -710,7 +711,7 @@ public void testCheckoutLimitWithPublisherConfirmsLogicalAlreadyCloses() throws
710711 willAnswer (invoc -> {
711712 open .set (false ); // so the logical close detects a closed delegate
712713 return null ;
713- }).given (mockChannel ).basicPublish (any (), any (), anyBoolean (), any (), any ());
714+ }).given (mockChannel ).basicPublish (any (), any (), anyBoolean (), any (), any ());
714715
715716 CachingConnectionFactory ccf = new CachingConnectionFactory (mockConnectionFactory );
716717 ccf .setExecutor (mock (ExecutorService .class ));
@@ -722,7 +723,7 @@ public void testCheckoutLimitWithPublisherConfirmsLogicalAlreadyCloses() throws
722723 rabbitTemplate .convertAndSend ("foo" , "bar" );
723724 open .set (true );
724725 rabbitTemplate .convertAndSend ("foo" , "bar" );
725- verify (mockChannel , times (2 )).basicPublish (any (), any (), anyBoolean (), any (), any ());
726+ verify (mockChannel , times (2 )).basicPublish (any (), any (), anyBoolean (), any (), any ());
726727 }
727728
728729 @ Test
@@ -1300,7 +1301,6 @@ public void onClose(Connection connection) {
13001301 verify (mockConnections .get (3 )).close (30000 );
13011302 }
13021303
1303-
13041304 @ Test
13051305 public void testWithConnectionFactoryCachedConnectionAndChannels () throws Exception {
13061306 com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com .rabbitmq .client .ConnectionFactory .class );
@@ -1644,6 +1644,8 @@ private void verifyChannelIs(Channel mockChannel, Channel channel) {
16441644 @ Test
16451645 public void setAddressesEmpty () throws Exception {
16461646 ConnectionFactory mock = mock (com .rabbitmq .client .ConnectionFactory .class );
1647+ given (mock .newConnection (any (ExecutorService .class ), anyString ()))
1648+ .willReturn (mock (com .rabbitmq .client .Connection .class ));
16471649 CachingConnectionFactory ccf = new CachingConnectionFactory (mock );
16481650 ccf .setExecutor (mock (ExecutorService .class ));
16491651 ccf .setHost ("abc" );
@@ -1663,6 +1665,8 @@ public void setAddressesEmpty() throws Exception {
16631665 @ Test
16641666 public void setAddressesOneHost () throws Exception {
16651667 ConnectionFactory mock = mock (com .rabbitmq .client .ConnectionFactory .class );
1668+ given (mock .newConnection (any (), anyList (), anyString ()))
1669+ .willReturn (mock (com .rabbitmq .client .Connection .class ));
16661670 CachingConnectionFactory ccf = new CachingConnectionFactory (mock );
16671671 ccf .setAddresses ("mq1" );
16681672 ccf .createConnection ();
@@ -1674,16 +1678,18 @@ public void setAddressesOneHost() throws Exception {
16741678
16751679 @ Test
16761680 public void setAddressesTwoHosts () throws Exception {
1677- ConnectionFactory mock = mock (com . rabbitmq . client . ConnectionFactory . class );
1681+ ConnectionFactory mock = mock ();
16781682 willReturn (true ).given (mock ).isAutomaticRecoveryEnabled ();
1683+ willReturn (mock (com .rabbitmq .client .Connection .class )).given (mock ).newConnection (any (), anyList (), anyString ());
16791684 CachingConnectionFactory ccf = new CachingConnectionFactory (mock );
16801685 ccf .setAddresses ("mq1,mq2" );
16811686 ccf .createConnection ();
16821687 verify (mock ).isAutomaticRecoveryEnabled ();
16831688 verify (mock ).setAutomaticRecoveryEnabled (false );
16841689 verify (mock ).newConnection (
16851690 isNull (),
1686- argThat ((ArgumentMatcher <List <Address >>) a -> a .size () == 2 && a .contains (new Address ("mq1" )) && a .contains (new Address ("mq2" ))),
1691+ argThat ((ArgumentMatcher <List <Address >>) a -> a .size () == 2
1692+ && a .contains (new Address ("mq1" )) && a .contains (new Address ("mq2" ))),
16871693 anyString ());
16881694 verifyNoMoreInteractions (mock );
16891695 }
@@ -1692,7 +1698,9 @@ public void setAddressesTwoHosts() throws Exception {
16921698 public void setUri () throws Exception {
16931699 URI uri = new URI ("amqp://localhost:1234/%2f" );
16941700
1695- ConnectionFactory mock = mock (com .rabbitmq .client .ConnectionFactory .class );
1701+ ConnectionFactory mock = mock ();
1702+ given (mock .newConnection (any (ExecutorService .class ), anyString ()))
1703+ .willReturn (mock (com .rabbitmq .client .Connection .class ));
16961704 CachingConnectionFactory ccf = new CachingConnectionFactory (mock );
16971705 ccf .setExecutor (mock (ExecutorService .class ));
16981706
@@ -1854,12 +1862,12 @@ public void testFirstConnectionDoesntWait() throws IOException, TimeoutException
18541862 @ SuppressWarnings ("unchecked" )
18551863 @ Test
18561864 public void testShuffleRandom () throws IOException , TimeoutException {
1857- com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com . rabbitmq . client . ConnectionFactory . class );
1858- com .rabbitmq .client .Connection mockConnection = mock (com . rabbitmq . client . Connection . class );
1865+ com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock ();
1866+ com .rabbitmq .client .Connection mockConnection = mock ();
18591867 Channel mockChannel = mock (Channel .class );
18601868
1861- given (mockConnectionFactory .newConnection (( ExecutorService ) isNull (), any ( List . class ), anyString ()))
1862- .willReturn (mockConnection );
1869+ given (mockConnectionFactory .newConnection (any (), anyList ( ), anyString ()))
1870+ .willReturn (mockConnection );
18631871 given (mockConnection .createChannel ()).willReturn (mockChannel );
18641872 given (mockChannel .isOpen ()).willReturn (true );
18651873 given (mockConnection .isOpen ()).willReturn (true );
@@ -1873,11 +1881,11 @@ public void testShuffleRandom() throws IOException, TimeoutException {
18731881 ArgumentCaptor <List <Address >> captor = ArgumentCaptor .forClass (List .class );
18741882 verify (mockConnectionFactory , times (100 )).newConnection (isNull (), captor .capture (), anyString ());
18751883 List <String > firstAddress = captor .getAllValues ()
1876- .stream ()
1877- .map (addresses -> addresses .get (0 ).getHost ())
1878- .distinct ()
1879- .sorted ()
1880- .collect (Collectors .toList ());
1884+ .stream ()
1885+ .map (addresses -> addresses .get (0 ).getHost ())
1886+ .distinct ()
1887+ .sorted ()
1888+ .collect (Collectors .toList ());
18811889 assertThat (firstAddress ).containsExactly ("host1" , "host2" , "host3" );
18821890 }
18831891
@@ -1888,8 +1896,8 @@ public void testShuffleInOrder() throws IOException, TimeoutException {
18881896 com .rabbitmq .client .Connection mockConnection = mock (com .rabbitmq .client .Connection .class );
18891897 Channel mockChannel = mock (Channel .class );
18901898
1891- given (mockConnectionFactory .newConnection (( ExecutorService ) isNull (), any ( List . class ), anyString ()))
1892- .willReturn (mockConnection );
1899+ given (mockConnectionFactory .newConnection (isNull (), anyList ( ), anyString ()))
1900+ .willReturn (mockConnection );
18931901 given (mockConnection .createChannel ()).willReturn (mockChannel );
18941902 given (mockChannel .isOpen ()).willReturn (true );
18951903 given (mockConnection .isOpen ()).willReturn (true );
@@ -1903,17 +1911,17 @@ public void testShuffleInOrder() throws IOException, TimeoutException {
19031911 ArgumentCaptor <List <Address >> captor = ArgumentCaptor .forClass (List .class );
19041912 verify (mockConnectionFactory , times (3 )).newConnection (isNull (), captor .capture (), anyString ());
19051913 List <String > connectAddresses = captor .getAllValues ()
1906- .stream ()
1907- .map (addresses -> addresses .get (0 ).getHost ())
1908- .collect (Collectors .toList ());
1914+ .stream ()
1915+ .map (addresses -> addresses .get (0 ).getHost ())
1916+ .collect (Collectors .toList ());
19091917 assertThat (connectAddresses ).containsExactly ("host1" , "host2" , "host3" );
19101918 }
19111919
19121920 @ Test
19131921 void testResolver () throws Exception {
1914- com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com . rabbitmq . client . ConnectionFactory . class );
1915- com .rabbitmq .client .Connection mockConnection = mock (com . rabbitmq . client . Connection . class );
1916- Channel mockChannel = mock (Channel . class );
1922+ com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock ();
1923+ com .rabbitmq .client .Connection mockConnection = mock ();
1924+ Channel mockChannel = mock ();
19171925
19181926 AddressResolver resolver = () -> Collections .singletonList (Address .parseAddress ("foo:5672" ));
19191927 given (mockConnectionFactory .newConnection (any (ExecutorService .class ), eq (resolver ), anyString ()))
@@ -1934,7 +1942,7 @@ void testResolver() throws Exception {
19341942
19351943 @ Test
19361944 void nullShutdownCause () {
1937- com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com . rabbitmq . client . ConnectionFactory . class );
1945+ com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock ();
19381946 AbstractConnectionFactory cf = createConnectionFactory (mockConnectionFactory );
19391947 AtomicBoolean connShutDown = new AtomicBoolean ();
19401948 cf .addConnectionListener (new ConnectionListener () {
0 commit comments