diff --git a/build.gradle b/build.gradle index 932de9a3..dd5e22eb 100644 --- a/build.gradle +++ b/build.gradle @@ -88,11 +88,11 @@ subprojects { subproject -> junitVersion = '4.12' log4jVersion = '2.7' logbackVersion = '1.1.2' - mockitoVersion = '1.10.19' + mockitoVersion = '2.5.4' rabbitmqVersion = project.hasProperty('rabbitmqVersion') ? project.rabbitmqVersion : '4.0.0' rabbitmqHttpClientVersion = '1.1.0.RELEASE' - springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.M4' + springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.BUILD-SNAPSHOT' springRetryVersion = '1.2.0.RC1' } diff --git a/spring-amqp/src/test/java/org/springframework/amqp/support/MessagePostProcessorUtilsTests.java b/spring-amqp/src/test/java/org/springframework/amqp/support/MessagePostProcessorUtilsTests.java index 2954aa03..cd86cb25 100644 --- a/spring-amqp/src/test/java/org/springframework/amqp/support/MessagePostProcessorUtilsTests.java +++ b/spring-amqp/src/test/java/org/springframework/amqp/support/MessagePostProcessorUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.amqp.support; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -23,7 +24,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; -import org.hamcrest.Matchers; import org.junit.Test; import org.springframework.amqp.AmqpException; @@ -52,19 +52,19 @@ public class MessagePostProcessorUtilsTests { Collection sorted = MessagePostProcessorUtils.sort(Arrays.asList(pps)); Iterator iterator = sorted.iterator(); MessagePostProcessor mpp = iterator.next(); - assertThat(mpp, Matchers.instanceOf(POMPP.class)); + assertThat(mpp, instanceOf(POMPP.class)); assertEquals(2, ((POMPP) mpp).getOrder()); mpp = iterator.next(); - assertThat(mpp, Matchers.instanceOf(POMPP.class)); + assertThat(mpp, instanceOf(POMPP.class)); assertEquals(6, ((POMPP) mpp).getOrder()); mpp = iterator.next(); - assertThat(mpp, Matchers.instanceOf(OMPP.class)); + assertThat(mpp, instanceOf(OMPP.class)); assertEquals(1, ((OMPP) mpp).getOrder()); mpp = iterator.next(); - assertThat(mpp, Matchers.instanceOf(OMPP.class)); + assertThat(mpp, instanceOf(OMPP.class)); assertEquals(3, ((OMPP) mpp).getOrder()); mpp = iterator.next(); - assertThat(mpp, Matchers.instanceOf(MPP.class)); + assertThat(mpp, instanceOf(MPP.class)); } class MPP implements MessagePostProcessor { diff --git a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/ContentTypeDelegatingMessageConverterTests.java b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/ContentTypeDelegatingMessageConverterTests.java index 55bc817d..c97cad12 100644 --- a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/ContentTypeDelegatingMessageConverterTests.java +++ b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/ContentTypeDelegatingMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.amqp.support.converter; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -23,7 +24,6 @@ import static org.junit.Assert.fail; import java.io.Serializable; -import org.hamcrest.Matchers; import org.junit.Test; import org.springframework.amqp.core.Message; @@ -63,7 +63,7 @@ public class ContentTypeDelegatingMessageConverterTests { } catch (Exception e) { assertThat(e, instanceOf(MessageConversionException.class)); - assertThat(e.getMessage(), Matchers.containsString("No delegate converter")); + assertThat(e.getMessage(), containsString("No delegate converter")); } } diff --git a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTest.java b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTests.java similarity index 97% rename from spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTest.java rename to spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTests.java index bfc51aa5..26b7c37b 100644 --- a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTest.java +++ b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.amqp.core.MessageProperties; @@ -41,7 +41,7 @@ import org.springframework.amqp.core.MessageProperties; * */ @RunWith(MockitoJUnitRunner.class) -public class DefaultClassMapperTest { +public class DefaultClassMapperTests { @Spy DefaultClassMapper classMapper = new DefaultClassMapper(); diff --git a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapperTests.java b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapperTests.java index 5d3e59e0..4ef6a114 100644 --- a/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapperTests.java +++ b/spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.amqp.core.MessageProperties; diff --git a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyAndCaptureTest.java b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyAndCaptureTest.java index 86ddfd13..d5401d83 100644 --- a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyAndCaptureTest.java +++ b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyAndCaptureTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyTest.java b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyTest.java index e793d753..b832902b 100644 --- a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyTest.java +++ b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/ExampleRabbitListenerSpyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.amqp.rabbit.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/mockito/AnswerTests.java b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/mockito/AnswerTests.java index 0f72387e..21e09963 100644 --- a/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/mockito/AnswerTests.java +++ b/spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/mockito/AnswerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package org.springframework.amqp.rabbit.test.mockito; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactory.java index d66af0e4..f9dbf206 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactory.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -286,7 +286,8 @@ public abstract class AbstractConnectionFactory implements ConnectionFactory, Di public void setExecutor(Executor executor) { boolean isExecutorService = executor instanceof ExecutorService; boolean isThreadPoolTaskExecutor = executor instanceof ThreadPoolTaskExecutor; - Assert.isTrue(isExecutorService || isThreadPoolTaskExecutor); + Assert.isTrue(isExecutorService || isThreadPoolTaskExecutor, + "'executor' must be an 'ExecutorService' or a 'ThreadPoolTaskExecutor'"); if (isExecutorService) { this.executorService = (ExecutorService) executor; } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java index 86123a5e..ceb39878 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; -import org.hamcrest.Matchers; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -415,7 +414,7 @@ public class EnableRabbitIntegrationTests { foo.setBar("bar"); this.jsonRabbitTemplate.convertAndSend("differentTypes", foo); assertTrue(this.service.latch.await(10, TimeUnit.SECONDS)); - assertThat(this.service.foos.get(0), Matchers.instanceOf(Foo2.class)); + assertThat(this.service.foos.get(0), instanceOf(Foo2.class)); assertEquals("bar", ((Foo2) this.service.foos.get(0)).getBar()); } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/RabbitListenerAnnotationBeanPostProcessorTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/RabbitListenerAnnotationBeanPostProcessorTests.java index 570313c5..97f63008 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/RabbitListenerAnnotationBeanPostProcessorTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/RabbitListenerAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,9 @@ package org.springframework.amqp.rabbit.annotation; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; @@ -27,7 +30,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.Iterator; -import org.hamcrest.Matchers; import org.junit.Test; import org.springframework.amqp.core.Queue; @@ -185,10 +187,10 @@ public class RabbitListenerAnnotationBeanPostProcessorTests { new AnnotationConfigApplicationContext(Config.class, InvalidValueInAnnotationTestBean.class).close(); } catch (BeanCreationException e) { - assertThat(e.getCause(), Matchers.instanceOf(IllegalArgumentException.class)); - assertThat(e.getMessage(), Matchers.allOf( - Matchers.containsString("@RabbitListener can't resolve"), - Matchers.containsString("as either a String or a Queue") + assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); + assertThat(e.getMessage(), allOf( + containsString("@RabbitListener can't resolve"), + containsString("as either a String or a Queue") )); } } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactoryTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactoryTests.java index e7a968bd..1775b710 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactoryTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/AbstractConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 the original author or authors. + * Copyright 2010-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ package org.springframework.amqp.rabbit.connection; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java index 2d7d6976..9f12c630 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.willReturn; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java index 2347ab53..8d1222de 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,10 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.AdditionalMatchers.aryEq; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; @@ -83,7 +83,9 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest @Override protected AbstractConnectionFactory createConnectionFactory(ConnectionFactory connectionFactory) { - return new CachingConnectionFactory(connectionFactory); + CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); + return ccf; } @Test @@ -98,6 +100,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockConnection.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); Connection con = ccf.createConnection(); Channel channel = con.createChannel(false); @@ -136,6 +139,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel2.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(2); Connection con = ccf.createConnection(); @@ -194,6 +198,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel3.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); Connection con = ccf.createConnection(); @@ -246,6 +251,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel1.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); ccf.setChannelCheckoutTimeout(10); @@ -288,6 +294,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockConnection.isOpen()).thenReturn(true); final CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(1); ccf.setConnectionLimit(1); @@ -358,6 +365,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel4.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(2); ccf.setChannelCheckoutTimeout(10); ccf.setCacheMode(mode); @@ -430,6 +438,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel1.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); ccf.setChannelCheckoutTimeout(10000); @@ -480,6 +489,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel1.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); ccf.setChannelCheckoutTimeout(10); @@ -533,6 +543,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel1.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); ccf.setChannelCheckoutTimeout(10); @@ -582,6 +593,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel2.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); Connection con = ccf.createConnection(); @@ -629,6 +641,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel2.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(1); Connection con = ccf.createConnection(); @@ -693,6 +706,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel3.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(2); Connection con = ccf.createConnection(); @@ -885,6 +899,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest }).when(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.afterPropertiesSet(); @@ -1084,6 +1099,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest }).when(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(2); ccf.setChannelCacheSize(2); @@ -1302,6 +1318,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest }).when(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(5); ccf.afterPropertiesSet(); @@ -1357,6 +1374,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest public void setAddressesEmpty() throws Exception { ConnectionFactory mock = mock(com.rabbitmq.client.ConnectionFactory.class); CachingConnectionFactory ccf = new CachingConnectionFactory(mock); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setHost("abc"); ccf.setAddresses(""); ccf.createConnection(); @@ -1372,7 +1390,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest ccf.setAddresses("mq1"); ccf.createConnection(); verify(mock) - .newConnection(isNull(ExecutorService.class), aryEq(new Address[] { new Address("mq1") }), anyString()); + .newConnection(isNull(), aryEq(new Address[] { new Address("mq1") }), anyString()); verifyNoMoreInteractions(mock); } @@ -1382,7 +1400,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest CachingConnectionFactory ccf = new CachingConnectionFactory(mock); ccf.setAddresses("mq1,mq2"); ccf.createConnection(); - verify(mock).newConnection(isNull(ExecutorService.class), + verify(mock).newConnection(isNull(), aryEq(new Address[] { new Address("mq1"), new Address("mq2") }), anyString()); verifyNoMoreInteractions(mock); } @@ -1393,6 +1411,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest ConnectionFactory mock = mock(com.rabbitmq.client.ConnectionFactory.class); CachingConnectionFactory ccf = new CachingConnectionFactory(mock); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setUri(uri); ccf.createConnection(); @@ -1415,6 +1434,7 @@ public class CachingConnectionFactoryTests extends AbstractConnectionFactoryTest when(mockChannel.isOpen()).thenReturn(true).thenReturn(false); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); Connection con = ccf.createConnection(); Channel channel = con.createChannel(false); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/ClientRecoveryCompatibilityTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/ClientRecoveryCompatibilityTests.java index 451a47e7..26436c19 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/ClientRecoveryCompatibilityTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/ClientRecoveryCompatibilityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -56,6 +56,7 @@ public class ClientRecoveryCompatibilityTests { when(rabbitConn.createChannel()).thenReturn(channel1).thenReturn(channel2); CachingConnectionFactory ccf = new CachingConnectionFactory(cf); + ccf.setExecutor(mock(ExecutorService.class)); Connection conn1 = ccf.createConnection(); Channel channel = conn1.createChannel(false); verifyChannelIs(channel1, channel); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/LocalizedQueueConnectionFactoryTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/LocalizedQueueConnectionFactoryTests.java index 41b6669a..f3c102bb 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/LocalizedQueueConnectionFactoryTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/LocalizedQueueConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -45,7 +45,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; import org.mockito.internal.stubbing.answers.CallsRealMethods; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; @@ -70,7 +69,6 @@ public class LocalizedQueueConnectionFactoryTests { private final Map consumerTags = new HashMap(); - @SuppressWarnings("unchecked") @Test public void testFailOver() throws Exception { ConnectionFactory defaultConnectionFactory = mockCF("localhost:1234", null); @@ -119,7 +117,7 @@ public class LocalizedQueueConnectionFactoryTests { assertNotNull(channel); verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), - Matchers.any(Consumer.class)); + any(Consumer.class)); verify(logger, atLeast(1)).info(captor.capture()); assertTrue(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@foo at: localhost:1235")); @@ -132,7 +130,7 @@ public class LocalizedQueueConnectionFactoryTests { assertNotNull(channel); verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), - Matchers.any(Consumer.class)); + any(Consumer.class)); container.stop(); verify(logger, atLeast(1)).info(captor.capture()); assertTrue(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@bar at: localhost:1236")); @@ -176,7 +174,6 @@ public class LocalizedQueueConnectionFactoryTests { } } - @SuppressWarnings("unchecked") private ConnectionFactory mockCF(final String address, final CountDownLatch latch) throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); @@ -187,7 +184,7 @@ public class LocalizedQueueConnectionFactoryTests { when(channel.isOpen()).thenReturn(true, false); doAnswer(invocation -> { String tag = UUID.randomUUID().toString(); - consumers.put(address, invocation.getArgumentAt(6, Consumer.class)); + consumers.put(address, invocation.getArgument(6)); consumerTags.put(address, tag); if (latch != null) { latch.countDown(); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SingleConnectionFactoryTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SingleConnectionFactoryTests.java index 4dbc71fe..354a67dc 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SingleConnectionFactoryTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SingleConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,9 @@ package org.springframework.amqp.rabbit.connection; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -37,12 +37,15 @@ import com.rabbitmq.client.ConnectionFactory; /** * @author Dave Syer + * @author Gary Russell */ public class SingleConnectionFactoryTests extends AbstractConnectionFactoryTests { @Override protected AbstractConnectionFactory createConnectionFactory(ConnectionFactory connectionFactory) { - return new SingleConnectionFactory(connectionFactory); + SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); + scf.setExecutor(mock(ExecutorService.class)); + return scf; } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplateTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplateTests.java index 1c947be7..5307f6ab 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplateTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminDeclarationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminDeclarationTests.java index 87d28640..5bc6b89e 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminDeclarationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminDeclarationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -162,7 +162,7 @@ public class RabbitAdminDeclarationTests { when(channel.queueDeclare("foo", true, false, false, null)).thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); final AtomicReference listener = new AtomicReference(); doAnswer(invocation -> { - listener.set(invocation.getArgumentAt(0, ConnectionListener.class)); + listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); @@ -198,7 +198,7 @@ public class RabbitAdminDeclarationTests { when(channel.queueDeclare("foo", true, false, false, null)).thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); final AtomicReference listener = new AtomicReference(); doAnswer(invocation -> { - listener.set(invocation.getArgumentAt(0, ConnectionListener.class)); + listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); @@ -236,7 +236,7 @@ public class RabbitAdminDeclarationTests { when(channel.queueDeclare("foo", true, false, false, null)).thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); final AtomicReference listener = new AtomicReference(); doAnswer(invocation -> { - listener.set(invocation.getArgumentAt(0, ConnectionListener.class)); + listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); @@ -262,7 +262,6 @@ public class RabbitAdminDeclarationTests { verify(channel, never()).queueBind(eq("foo"), eq("bar"), eq("foo"), any(Map.class)); } - @SuppressWarnings("unchecked") @Test public void testJavaConfig() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); @@ -273,7 +272,7 @@ public class RabbitAdminDeclarationTests { Config.listener2.onCreate(Config.conn2); verify(Config.channel2, never()) - .queueDeclare(eq("foo"), anyBoolean(), anyBoolean(), anyBoolean(), isNull(Map.class)); + .queueDeclare(eq("foo"), anyBoolean(), anyBoolean(), anyBoolean(), isNull()); verify(Config.channel2, never()) .exchangeDeclare(eq("bar"), eq("direct"), anyBoolean(), anyBoolean(), anyBoolean(), anyMap()); @@ -337,7 +336,7 @@ public class RabbitAdminDeclarationTests { when(channel1.queueDeclare("foo", true, false, false, null)) .thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); doAnswer(invocation -> { - listener1 = invocation.getArgumentAt(0, ConnectionListener.class); + listener1 = invocation.getArgument(0); return null; }).when(connectionFactory).addConnectionListener(any(ConnectionListener.class)); return connectionFactory; @@ -351,7 +350,7 @@ public class RabbitAdminDeclarationTests { when(channel2.queueDeclare("foo", true, false, false, null)) .thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); doAnswer(invocation -> { - listener2 = invocation.getArgumentAt(0, ConnectionListener.class); + listener2 = invocation.getArgument(0); return null; }).when(connectionFactory).addConnectionListener(any(ConnectionListener.class)); return connectionFactory; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminTests.java index 811109eb..a87382b0 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.amqp.rabbit.core; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.sameInstance; @@ -26,8 +27,8 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -49,7 +50,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; import org.apache.commons.logging.Log; -import org.hamcrest.Matchers; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -201,13 +201,13 @@ public class RabbitAdminTests { verify(logger, times(7)).info(log.capture()); List logs = log.getAllValues(); Collections.sort(logs); - assertThat(logs.get(0), Matchers.containsString("(testex.ad) durable:true, auto-delete:true")); - assertThat(logs.get(1), Matchers.containsString("(testex.all) durable:false, auto-delete:true")); - assertThat(logs.get(2), Matchers.containsString("(testex.nonDur) durable:false, auto-delete:false")); - assertThat(logs.get(3), Matchers.containsString("(testq.ad) durable:true, auto-delete:true, exclusive:false")); - assertThat(logs.get(4), Matchers.containsString("(testq.all) durable:false, auto-delete:true, exclusive:true")); - assertThat(logs.get(5), Matchers.containsString("(testq.excl) durable:true, auto-delete:false, exclusive:true")); - assertThat(logs.get(6), Matchers.containsString("(testq.nonDur) durable:false, auto-delete:false, exclusive:false")); + assertThat(logs.get(0), containsString("(testex.ad) durable:true, auto-delete:true")); + assertThat(logs.get(1), containsString("(testex.all) durable:false, auto-delete:true")); + assertThat(logs.get(2), containsString("(testex.nonDur) durable:false, auto-delete:false")); + assertThat(logs.get(3), containsString("(testq.ad) durable:true, auto-delete:true, exclusive:false")); + assertThat(logs.get(4), containsString("(testq.all) durable:false, auto-delete:true, exclusive:true")); + assertThat(logs.get(5), containsString("(testq.excl) durable:true, auto-delete:false, exclusive:true")); + assertThat(logs.get(6), containsString("(testq.nonDur) durable:false, auto-delete:false, exclusive:false")); } finally { cleanQueuesAndExchanges(rabbitAdmin); @@ -276,6 +276,7 @@ public class RabbitAdminTests { TimeoutException toBeThrown = new TimeoutException("test"); doThrow(toBeThrown).when(rabbitConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(rabbitConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); RabbitAdmin admin = new RabbitAdmin(ccf); List events = new ArrayList(); admin.setApplicationEventPublisher(new EventPublisher(events)); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitMessagingTemplateTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitMessagingTemplateTests.java index f236e6eb..53cf7725 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitMessagingTemplateTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitMessagingTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateHeaderTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateHeaderTests.java index 9505e832..df87ee6b 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateHeaderTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateHeaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -74,7 +74,9 @@ public class RabbitTemplateHeaderTests { when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); - final RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(connectionFactory); String replyAddress = "new.replyTo"; template.setReplyAddress(replyAddress); template.expectedQueueNames(); @@ -87,7 +89,7 @@ public class RabbitTemplateHeaderTests { final AtomicReference replyTo = new AtomicReference(); final AtomicReference correlationId = new AtomicReference(); doAnswer(invocation -> { - BasicProperties basicProps = invocation.getArgumentAt(3, BasicProperties.class); + BasicProperties basicProps = invocation.getArgument(3); replyTo.set(basicProps.getReplyTo()); if (standardHeader) { correlationId.set(basicProps.getCorrelationId()); @@ -127,7 +129,9 @@ public class RabbitTemplateHeaderTests { when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); - final RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(connectionFactory); String replyAddress = "new.replyTo"; template.setReplyAddress(replyAddress); template.setReplyTimeout(60000); @@ -140,7 +144,7 @@ public class RabbitTemplateHeaderTests { final AtomicReference replyTo = new AtomicReference(); final AtomicReference correlationId = new AtomicReference(); doAnswer(invocation -> { - BasicProperties basicProps = invocation.getArgumentAt(3, BasicProperties.class); + BasicProperties basicProps = invocation.getArgument(3); replyTo.set(basicProps.getReplyTo()); correlationId.set(basicProps.getCorrelationId()); MessageProperties springProps = new DefaultMessagePropertiesConverter() @@ -171,7 +175,9 @@ public class RabbitTemplateHeaderTests { when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); - final RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory scf = new SingleConnectionFactory(mockConnectionFactory); + scf.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(scf); String replyTo2 = "replyTo2"; template.setReplyAddress(replyTo2); template.expectedQueueNames(); @@ -186,7 +192,7 @@ public class RabbitTemplateHeaderTests { final List nestedCorrelation = new ArrayList(); final String replyAddress3 = "replyTo3"; doAnswer(invocation -> { - BasicProperties basicProps = invocation.getArgumentAt(3, BasicProperties.class); + BasicProperties basicProps = invocation.getArgument(3); nestedReplyTo.add(basicProps.getReplyTo()); nestedCorrelation.add(basicProps.getCorrelationId()); MessageProperties springProps = new DefaultMessagePropertiesConverter() @@ -226,7 +232,9 @@ public class RabbitTemplateHeaderTests { when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); - final RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setCorrelationKey(CORRELATION_HEADER); String replyAddress = "new.replyTo"; template.setReplyAddress(replyAddress); @@ -240,7 +248,7 @@ public class RabbitTemplateHeaderTests { final AtomicReference replyTo = new AtomicReference(); final AtomicReference correlationId = new AtomicReference(); doAnswer(invocation -> { - BasicProperties basicProps = invocation.getArgumentAt(3, BasicProperties.class); + BasicProperties basicProps = invocation.getArgument(3); replyTo.set(basicProps.getReplyTo()); correlationId.set((String) basicProps.getHeaders().get(CORRELATION_HEADER)); @@ -273,7 +281,9 @@ public class RabbitTemplateHeaderTests { when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); - final RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setCorrelationKey(CORRELATION_HEADER); String replyTo2 = "replyTo2"; template.setReplyAddress(replyTo2); @@ -289,7 +299,7 @@ public class RabbitTemplateHeaderTests { final List nestedCorrelation = new ArrayList(); final String replyTo3 = "replyTo3"; doAnswer(invocation -> { - BasicProperties basicProps = invocation.getArgumentAt(3, BasicProperties.class); + BasicProperties basicProps = invocation.getArgument(3); nestedReplyTo.add(basicProps.getReplyTo()); nestedCorrelation.add(basicProps.getCorrelationId()); MessageProperties springProps = new DefaultMessagePropertiesConverter() diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java index 0a5b1632..3425b653 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,9 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -66,7 +66,6 @@ import org.junit.Test; import org.junit.rules.TestName; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; import org.mockito.Mockito; import org.springframework.amqp.AmqpException; @@ -620,7 +619,7 @@ public class RabbitTemplateIntegrationTests { final AtomicBoolean execConfiguredOk = new AtomicBoolean(); doAnswer(invocation -> { - String log = invocation.getArgumentAt(0, String.class); + String log = invocation.getArgument(0); if (log.startsWith("Message received") && Thread.currentThread().getName().startsWith(execName)) { execConfiguredOk.set(true); } @@ -1308,7 +1307,7 @@ public class RabbitTemplateIntegrationTests { assertThat(e.getCause().getCause(), instanceOf(ShutdownSignalException.class)); assertThat(e.getCause().getCause().getMessage(), containsString("404")); } - verify(logger, never()).error(org.mockito.Matchers.any()); + verify(logger, never()).error(any()); ArgumentCaptor logs = ArgumentCaptor.forClass(Object.class); verify(logger, atLeast(2)).debug(logs.capture()); boolean queue = false; @@ -1333,7 +1332,7 @@ public class RabbitTemplateIntegrationTests { message.getMessageProperties().setHeader("cfKey", "foo"); return message; }); - verify(channel1).basicPublish(anyString(), anyString(), Matchers.anyBoolean(), any(BasicProperties.class), + verify(channel1).basicPublish(anyString(), anyString(), anyBoolean(), any(BasicProperties.class), any(byte[].class)); Connection connection2 = mock(Connection.class); @@ -1344,7 +1343,7 @@ public class RabbitTemplateIntegrationTests { message.getMessageProperties().setHeader("cfKey", "bar"); return message; }); - verify(channel1).basicPublish(anyString(), anyString(), Matchers.anyBoolean(), any(BasicProperties.class), + verify(channel1).basicPublish(anyString(), anyString(), anyBoolean(), any(BasicProperties.class), any(byte[].class)); } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests.java index 40470808..9ca9abf9 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -293,6 +293,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { doReturn(new PublisherCallbackChannelImpl(mockChannel)).when(mockConnection).createChannel(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -326,6 +327,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { when(mockConnection.createChannel()).thenReturn(channel1).thenReturn(channel2); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); ccf.setChannelCacheSize(3); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -388,10 +390,11 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { when(mockConnection.isOpen()).thenReturn(true); doReturn(new PublisherCallbackChannelImpl(mockChannel)).when(mockConnection).createChannel(); - final AtomicInteger count = new AtomicInteger(); + final AtomicLong count = new AtomicLong(); doAnswer(invocation -> count.incrementAndGet()).when(mockChannel).getNextPublishSeqNo(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -428,10 +431,11 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { PublisherCallbackChannelImpl callbackChannel = new PublisherCallbackChannelImpl(mockChannel); when(mockConnection.createChannel()).thenReturn(callbackChannel); - final AtomicInteger count = new AtomicInteger(); + final AtomicLong count = new AtomicLong(); doAnswer(invocation -> count.incrementAndGet()).when(mockChannel).getNextPublishSeqNo(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -466,10 +470,11 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { PublisherCallbackChannelImpl callbackChannel = new PublisherCallbackChannelImpl(mockChannel); when(mockConnection.createChannel()).thenReturn(callbackChannel); - final AtomicInteger count = new AtomicInteger(); + final AtomicLong count = new AtomicLong(); doAnswer(invocation -> count.incrementAndGet()).when(mockChannel).getNextPublishSeqNo(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template1 = new RabbitTemplate(ccf); @@ -527,6 +532,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { when(mockConnection.createChannel()).thenReturn(channel); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); ccf.setChannelCacheSize(3); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -650,6 +656,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { doReturn(mockChannel).when(mockConnection).createChannel(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -710,6 +717,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { when(mockConnection.createChannel()).thenReturn(mockChannel1, mockChannel2); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setPublisherConfirms(true); final RabbitTemplate template = new RabbitTemplate(ccf); @@ -739,7 +747,7 @@ public class RabbitTemplatePublisherCallbacksIntegrationTests { Listener listener = mock(Listener.class); doAnswer(invocation -> { - boolean ack = invocation.getArgumentAt(1, Boolean.class); + boolean ack = invocation.getArgument(1); if (!ack) { nacks.incrementAndGet(); } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java index 7d8ab759..e84458a4 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; @@ -115,7 +118,9 @@ public class RabbitTemplateTests { when(mockChannel.isOpen()).thenReturn(true); - final RabbitTemplate template = new RabbitTemplate(new CachingConnectionFactory(mockConnectionFactory)); + CachingConnectionFactory connectionFactory = new CachingConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + final RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setChannelTransacted(true); txTemplate.execute(status -> { @@ -128,7 +133,7 @@ public class RabbitTemplateTests { }); verify(mockConnectionFactory, Mockito.times(1)).newConnection(any(ExecutorService.class), anyString()); // ensure we used the same channel - verify(mockConnection, Mockito.times(1)).createChannel(); + verify(mockConnection, times(1)).createChannel(); } @Test @@ -163,7 +168,6 @@ public class RabbitTemplateTests { assertSame(input, message); } - @SuppressWarnings("unchecked") @Test // AMQP-249 public void dontHangConsumerThread() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -178,11 +182,13 @@ public class RabbitTemplateTests { final AtomicReference consumer = new AtomicReference(); doAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); return null; - }).when(mockChannel).basicConsume(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), - Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap(), any(Consumer.class)); - RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + }).when(mockChannel).basicConsume(anyString(), anyBoolean(), anyString(), + anyBoolean(), anyBoolean(), isNull(), any(Consumer.class)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setReplyTimeout(1); Message input = new Message("Hello, world!".getBytes(), new MessageProperties()); template.doSendAndReceiveWithTemporary("foo", "bar", input, null); @@ -200,7 +206,9 @@ public class RabbitTemplateTests { throw new AuthenticationFailureException("foo"); }).when(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); - RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setRetryTemplate(new RetryTemplate()); try { template.convertAndSend("foo", "bar", "baz"); @@ -220,7 +228,9 @@ public class RabbitTemplateTests { throw new AuthenticationFailureException("foo"); }).when(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); - RabbitTemplate template = new RabbitTemplate(new SingleConnectionFactory(mockConnectionFactory)); + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); + connectionFactory.setExecutor(mock(ExecutorService.class)); + RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setRetryTemplate(new RetryTemplate()); final AtomicBoolean recoverInvoked = new AtomicBoolean(); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumerTests.java index 61d30d06..f7ab6323 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,13 @@ package org.springframework.amqp.rabbit.listener; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -119,7 +119,6 @@ public class BlockingQueueConsumerTests { testRequeueOrNotDefaultNo(new MessageRejectedWhileStoppingException(), true); } - @SuppressWarnings("unchecked") @Test public void testPrefetchIsSetOnFailedPassiveDeclaration() throws IOException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); @@ -131,7 +130,7 @@ public class BlockingQueueConsumerTests { when(channel.isOpen()).thenReturn(true); when(channel.queueDeclarePassive(Mockito.anyString())) .then(invocation -> { - String arg = invocation.getArgumentAt(0, String.class); + String arg = invocation.getArgument(0); if ("good".equals(arg)) { return Mockito.any(AMQP.Queue.DeclareOk.class); } @@ -154,7 +153,6 @@ public class BlockingQueueConsumerTests { verify(channel).basicQos(20); } - @SuppressWarnings("unchecked") @Test public void testRecoverAfterDeletedQueueAndLostConnection() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerTests.java index cf22e19a..98338568 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,12 +23,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -355,7 +355,6 @@ public class DirectMessageListenerContainerTests { assertFalse(container.isActive()); } - @SuppressWarnings("unchecked") @Test public void testRecoverBrokerLoss() throws Exception { ConnectionFactory mockCF = mock(ConnectionFactory.class); @@ -391,7 +390,6 @@ public class DirectMessageListenerContainerTests { container.stop(); } - @SuppressWarnings("unchecked") @Test public void testCancelConsumerBeforeConsumeOk() throws Exception { ConnectionFactory mockCF = mock(ConnectionFactory.class); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ErrorHandlerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ErrorHandlerTests.java index 3704dd13..40dd772e 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ErrorHandlerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ErrorHandlerTests.java @@ -17,9 +17,9 @@ package org.springframework.amqp.rabbit.listener; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.willDoNothing; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ExternalTxManagerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ExternalTxManagerTests.java index 1778deb6..c7fc9d21 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ExternalTxManagerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ExternalTxManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ package org.springframework.amqp.rabbit.listener; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -79,7 +79,6 @@ public abstract class ExternalTxManagerTests { * Verifies that an up-stack RabbitTemplate uses the listener's * channel (MessageListener). */ - @SuppressWarnings("unchecked") @Test public void testMessageListener() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -88,6 +87,7 @@ public abstract class ExternalTxManagerTests { given(onlyChannel.isOpen()).willReturn(true); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -113,7 +113,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) @@ -245,7 +245,6 @@ public abstract class ExternalTxManagerTests { /** * Verifies that the channel is rolled back after an exception. */ - @SuppressWarnings("unchecked") @Test public void testMessageListenerRollback() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -254,6 +253,7 @@ public abstract class ExternalTxManagerTests { given(channel.isOpen()).willReturn(true); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -266,7 +266,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(channel) @@ -312,7 +312,6 @@ public abstract class ExternalTxManagerTests { * Verifies that an up-stack RabbitTemplate does not use the listener's * channel when it has its own connection factory. */ - @SuppressWarnings("unchecked") @Test public void testMessageListenerTemplateUsesDifferentConnectionFactory() throws Exception { ConnectionFactory listenerConnectionFactory = mock(ConnectionFactory.class); @@ -326,8 +325,11 @@ public abstract class ExternalTxManagerTests { final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory( listenerConnectionFactory); + ExecutorService mockExec = mock(ExecutorService.class); + cachingConnectionFactory.setExecutor(mockExec); final CachingConnectionFactory cachingTemplateConnectionFactory = new CachingConnectionFactory( templateConnectionFactory); + cachingTemplateConnectionFactory.setExecutor(mockExec); given(listenerConnectionFactory.newConnection(any(ExecutorService.class), anyString())) .willReturn(listenerConnection); @@ -358,7 +360,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(listenerChannel) @@ -421,7 +423,6 @@ public abstract class ExternalTxManagerTests { * Verifies that an up-stack RabbitTemplate uses the listener's * channel (ChannelAwareMessageListener). */ - @SuppressWarnings("unchecked") @Test public void testChannelAwareMessageListener() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -430,6 +431,7 @@ public abstract class ExternalTxManagerTests { given(onlyChannel.isOpen()).willReturn(true); final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory(mockConnectionFactory); + singleConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -455,7 +457,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) @@ -514,7 +516,6 @@ public abstract class ExternalTxManagerTests { * channel (ChannelAwareMessageListener). exposeListenerChannel=false * is ignored (ChannelAwareMessageListener). */ - @SuppressWarnings("unchecked") @Test public void testChannelAwareMessageListenerDontExpose() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -523,6 +524,7 @@ public abstract class ExternalTxManagerTests { given(onlyChannel.isOpen()).willReturn(true); final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory(mockConnectionFactory); + singleConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -548,7 +550,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) @@ -608,7 +610,6 @@ public abstract class ExternalTxManagerTests { * Previously, the wrong channel was bound. See AMQP-260. * @throws Exception */ - @SuppressWarnings("unchecked") @Test public void testMessageListenerWithRabbitTxManager() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -617,6 +618,7 @@ public abstract class ExternalTxManagerTests { given(onlyChannel.isOpen()).willReturn(true); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -642,7 +644,7 @@ public abstract class ExternalTxManagerTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/LocallyTransactedTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/LocallyTransactedTests.java index 6b51da09..4f4c832d 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/LocallyTransactedTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/LocallyTransactedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ package org.springframework.amqp.rabbit.listener; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -69,7 +69,6 @@ public abstract class LocallyTransactedTests { * Verifies that an up-stack transactional RabbitTemplate uses the listener's * channel (MessageListener). */ - @SuppressWarnings("unchecked") @Test public void testMessageListener() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -78,6 +77,7 @@ public abstract class LocallyTransactedTests { given(onlyChannel.isOpen()).willReturn(true); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -103,7 +103,7 @@ public abstract class LocallyTransactedTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) @@ -201,7 +201,6 @@ public abstract class LocallyTransactedTests { /** * Verifies that the channel is rolled back after an exception. */ - @SuppressWarnings("unchecked") @Test public void testMessageListenerRollback() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -210,6 +209,7 @@ public abstract class LocallyTransactedTests { given(channel.isOpen()).willReturn(true); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -222,7 +222,7 @@ public abstract class LocallyTransactedTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(channel) @@ -267,13 +267,13 @@ public abstract class LocallyTransactedTests { * Verifies that an up-stack non-transactional RabbitTemplate does not use the * listener's channel (MessageListener). */ - @SuppressWarnings("unchecked") @Test public void testSeparateTx() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); Connection mockConnection = mock(Connection.class); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory); + cachingConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -309,7 +309,7 @@ public abstract class LocallyTransactedTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(channel1).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), @@ -368,7 +368,6 @@ public abstract class LocallyTransactedTests { * Verifies that an up-stack RabbitTemplate uses the listener's * channel (ChannelAwareMessageListener). */ - @SuppressWarnings("unchecked") @Test public void testChannelAwareMessageListener() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -377,6 +376,7 @@ public abstract class LocallyTransactedTests { given(onlyChannel.isOpen()).willReturn(true); final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory(mockConnectionFactory); + singleConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -402,7 +402,7 @@ public abstract class LocallyTransactedTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(onlyChannel) @@ -462,7 +462,6 @@ public abstract class LocallyTransactedTests { * up-stack RabbitTemplate uses the additional channel. * created when exposeListenerChannel is false (ChannelAwareMessageListener). */ - @SuppressWarnings("unchecked") @Test public void testChannelAwareMessageListenerDontExpose() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); @@ -473,6 +472,7 @@ public abstract class LocallyTransactedTests { given(secondChannel.isOpen()).willReturn(true); final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory(mockConnectionFactory); + singleConnectionFactory.setExecutor(mock(ExecutorService.class)); given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); given(mockConnection.isOpen()).willReturn(true); @@ -495,7 +495,7 @@ public abstract class LocallyTransactedTests { final CountDownLatch consumerLatch = new CountDownLatch(1); willAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumerLatch.countDown(); return "consumerTag"; }).given(firstChannel) diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerErrorHandlerIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerErrorHandlerIntegrationTests.java index 725b2ac4..b9fb05c9 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerErrorHandlerIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerErrorHandlerIntegrationTests.java @@ -22,8 +22,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MethodRabbitListenerEndpointTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MethodRabbitListenerEndpointTests.java index e293bf9a..fbfae267 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MethodRabbitListenerEndpointTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MethodRabbitListenerEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.AdditionalMatchers.aryEq; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerIntegration2Tests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerIntegration2Tests.java index 42337a11..70b57199 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerIntegration2Tests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerIntegration2Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerTests.java index 67795299..fa89b020 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -168,7 +168,6 @@ public class SimpleMessageListenerContainerTests { /* * txSize = 2; 4 messages; should get 2 acks (#2 and #4) */ - @SuppressWarnings("unchecked") @Test public void testTxSizeAcks() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); @@ -178,7 +177,7 @@ public class SimpleMessageListenerContainerTests { when(connection.createChannel(false)).thenReturn(channel); final AtomicReference consumer = new AtomicReference(); doAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumer.get().handleConsumeOk("1"); return "1"; }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class)); @@ -218,7 +217,6 @@ public class SimpleMessageListenerContainerTests { * txSize = 2; 3 messages; should get 2 acks (#2 and #3) * after timeout. */ - @SuppressWarnings("unchecked") @Test public void testTxSizeAcksWIthShortSet() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); @@ -229,7 +227,7 @@ public class SimpleMessageListenerContainerTests { final AtomicReference consumer = new AtomicReference(); final String consumerTag = "1"; doAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumer.get().handleConsumeOk(consumerTag); return consumerTag; }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class)); @@ -277,9 +275,9 @@ public class SimpleMessageListenerContainerTests { final AtomicReference consumer = new AtomicReference(); final AtomicReference> args = new AtomicReference>(); doAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumer.get().handleConsumeOk("foo"); - args.set(invocation.getArgumentAt(5, Map.class)); + args.set(invocation.getArgument(5)); return "foo"; }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), any(Map.class), any(Consumer.class)); @@ -345,7 +343,6 @@ public class SimpleMessageListenerContainerTests { container.stop(); } - @SuppressWarnings("unchecked") @Test public void testAddQueuesAndStartInCycle() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); @@ -356,7 +353,7 @@ public class SimpleMessageListenerContainerTests { when(connection.createChannel(false)).thenReturn(channel1); final AtomicInteger count = new AtomicInteger(); doAnswer(invocation -> { - Consumer cons = invocation.getArgumentAt(6, Consumer.class); + Consumer cons = invocation.getArgument(6); String consumerTag = "consFoo" + count.incrementAndGet(); cons.handleConsumeOk(consumerTag); return consumerTag; @@ -375,11 +372,10 @@ public class SimpleMessageListenerContainerTests { container.stop(); } - @SuppressWarnings("unchecked") protected void setupMockConsume(Channel channel, final List consumers, final AtomicInteger consumerTag, final CountDownLatch latch) throws IOException { doAnswer(invocation -> { - Consumer cons = invocation.getArgumentAt(6, Consumer.class); + Consumer cons = invocation.getArgument(6); consumers.add(cons); String actualTag = String.valueOf(consumerTag.getAndIncrement()); cons.handleConsumeOk(actualTag); @@ -391,13 +387,12 @@ public class SimpleMessageListenerContainerTests { protected void setUpMockCancel(Channel channel, final List consumers) throws IOException { final Executor exec = Executors.newCachedThreadPool(); doAnswer(invocation -> { - final String consTag = invocation.getArgumentAt(0, String.class); + final String consTag = invocation.getArgument(0); exec.execute(() -> consumers.get(Integer.parseInt(consTag)).handleCancelOk(consTag)); return null; }).when(channel).basicCancel(anyString()); } - @SuppressWarnings("unchecked") @Test public void testWithConnectionPerListenerThread() throws Exception { com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock(com.rabbitmq.client.ConnectionFactory.class); @@ -418,6 +413,7 @@ public class SimpleMessageListenerContainerTests { when(mockConnection2.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); + ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(ccf); @@ -446,7 +442,6 @@ public class SimpleMessageListenerContainerTests { assertEquals("1", ccf.getCacheProperties().get("openConnections")); } - @SuppressWarnings("unchecked") @Test public void testConsumerCancel() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); @@ -456,7 +451,7 @@ public class SimpleMessageListenerContainerTests { when(connection.createChannel(false)).thenReturn(channel); final AtomicReference consumer = new AtomicReference(); doAnswer(invocation -> { - consumer.set(invocation.getArgumentAt(6, Consumer.class)); + consumer.set(invocation.getArgument(6)); consumer.get().handleConsumeOk("foo"); return "foo"; }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class)); @@ -472,7 +467,8 @@ public class SimpleMessageListenerContainerTests { doReturn(false).when(logger).isDebugEnabled(); final CountDownLatch latch = new CountDownLatch(1); doAnswer(invocation -> { - if (invocation.getArgumentAt(0, String.class).startsWith("Consumer raised exception")) { + String message = invocation.getArgument(0); + if (message.startsWith("Consumer raised exception")) { latch.countDown(); } return invocation.callRealMethod(); @@ -517,7 +513,7 @@ public class SimpleMessageListenerContainerTests { if (channel != null && channel.getTargetChannel() == mockChannel) { Consumer rabbitConsumer = TestUtils.getPropertyValue(consumer, "consumer", Consumer.class); if (cancel) { - rabbitConsumer.handleCancelOk(invocation.getArgumentAt(0, String.class)); + rabbitConsumer.handleCancelOk(invocation.getArgument(0)); } else { rabbitConsumer.handleConsumeOk("foo"); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/log4j2/AmqpAppenderTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/log4j2/AmqpAppenderTests.java index 0812ce53..ac579a35 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/log4j2/AmqpAppenderTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/log4j2/AmqpAppenderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/logback/AmqpAppenderTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/logback/AmqpAppenderTests.java index 61e8e99c..0ccc4832 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/logback/AmqpAppenderTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/logback/AmqpAppenderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package org.springframework.amqp.rabbit.logback; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/MissingIdRetryTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/MissingIdRetryTests.java index 0140c661..19621d73 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/MissingIdRetryTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/MissingIdRetryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.amqp.rabbit.retry; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.never; diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/RepublishMessageRecovererTest.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/RepublishMessageRecovererTest.java index e669e4f4..366fd42c 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/RepublishMessageRecovererTest.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/retry/RepublishMessageRecovererTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.Message; diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 6c674b62..740f39d5 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -75,7 +75,7 @@ + value="org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.ArgumentMatchers.*, org.mockito.AdditionalMatchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.amqp.rabbit.test.RabbitMatchers.*" />