From 54654546b9536f6c3202c7fc253ff853ca69fa15 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 9 Jan 2017 17:39:47 -0500 Subject: [PATCH] INT-4206: Upgrade to Mockito 2.5 JIRA: https://jira.spring.io/browse/INT-4206 * Fix unnecessary dependency resolution in BOM module * Fix `MessagingMethodInvokerHelper` to handle `$MockitoMock$` generated classed which isn't CGLib `Proxies` any more * Provide fixes for test classes according upgrade to Mockito `2.5` * Fix Ceckstyle do not allow static imports for deprecated Mockito classes --- build.gradle | 6 +- .../amqp/channel/ChannelTests.java | 4 +- .../DispatcherHasNoSubscribersTests.java | 15 +++-- .../config/AmqpInboundGatewayParserTests.java | 8 +-- ...AmqpOutboundChannelAdapterParserTests.java | 18 +++--- .../AmqpOutboundGatewayParserTests.java | 21 +++--- .../amqp/config/OutboundGatewayTests.java | 4 +- .../amqp/inbound/InboundEndpointTests.java | 15 ++--- .../amqp/outbound/AsyncAmqpGatewayTests.java | 10 +-- .../amqp/outbound/OutboundEndpointTests.java | 32 +++++----- .../util/MessagingMethodInvokerHelper.java | 3 +- .../CorrelatingMessageBarrierTests.java | 6 +- ...elatingMessageHandlerIntegrationTests.java | 6 +- .../CorrelatingMessageHandlerTests.java | 8 +-- ...nEvaluatingMessageGroupProcessorTests.java | 4 +- ...hodInvokingMessageGroupProcessorTests.java | 4 +- ...dDispatcherConfigurationScenarioTests.java | 21 +++--- .../integration/channel/P2pChannelTests.java | 6 +- .../reactive/ReactiveConsumerTests.java | 8 +-- .../integration/config/ChainParserTests.java | 6 +- ...PollingChannelAdapterFactoryBeanTests.java | 10 +-- .../xml/PublishingInterceptorParserTests.java | 19 +++--- .../BroadcastingDispatcherTests.java | 7 +- .../RoundRobinDispatcherConcurrentTests.java | 4 +- .../dispatcher/RoundRobinDispatcherTests.java | 4 +- .../endpoint/PollerAdviceTests.java | 4 +- ...ractReplyProducingMessageHandlerTests.java | 11 ++-- .../handler/AsyncHandlerTests.java | 11 ++-- .../handler/MessageHandlerChainTests.java | 5 +- .../SendTimeoutConfigurationTests.java | 4 +- .../advice/AdvisedMessageHandlerTests.java | 2 +- .../util/BeanFactoryTypeConverterTests.java | 4 +- .../file/CompositeFileListFilterTests.java | 4 +- .../file/FileReadingMessageSourceTests.java | 9 +-- .../RemoteFileOutboundGatewayTests.java | 12 ++-- .../FileTransferringMessageHandlerTests.java | 15 +++-- .../ftp/outbound/FtpOutboundTests.java | 44 ++++++------- .../http/HttpProxyScenarioTests.java | 13 ++-- .../inbound/MultipartAsRawByteArrayTests.java | 8 +-- ...tpRequestExecutingMessageHandlerTests.java | 2 +- .../CachingClientConnectionFactoryTests.java | 19 ++---- .../tcp/connection/ConnectionEventTests.java | 6 +- .../connection/ConnectionFactoryTests.java | 4 +- .../tcp/connection/TcpNioConnectionTests.java | 31 ++++----- ...nnelPublishingJmsMessageListenerTests.java | 7 +- .../jms/DefaultJmsHeaderMapperTests.java | 2 +- .../jms/JmsOutboundGatewayTests.java | 10 +-- .../jms/SubscribableJmsChannelTests.java | 8 +-- .../jms/config/JmsChannelHistoryTests.java | 4 +- .../mail/config/ImapIdleIntegrationTests.java | 4 +- .../config/MessageWithContentTypeTests.java | 16 ++--- .../mqtt/DownstreamExceptionTests.java | 12 ++-- .../integration/mqtt/MqttAdapterTests.java | 25 ++++---- .../integration/rmi/BackToBackTests.java | 4 +- .../config/RmiOutboundGatewayParserTests.java | 5 +- .../sftp/outbound/SftpOutboundTests.java | 14 ++-- .../sftp/session/SftpSessionFactoryTests.java | 2 +- .../stream/CharacterStreamSourceTests.java | 4 +- ...soleOutboundChannelAdapterParserTests.java | 4 +- .../SyslogReceivingChannelAdapterTests.java | 10 +-- .../src/test/resources/log4j.properties | 8 +++ .../test/matcher/MockitoMessageMatchers.java | 25 ++++---- .../matcher/MockitoMessageMatchersTests.java | 6 +- ...hReceivingMessageSourceWithRedisTests.java | 12 ++-- .../TwitterSearchOutboundGatewayTests.java | 28 ++++---- .../test/{java => resources}/log4j.properties | 0 .../twitter.receiver.properties | 0 .../twitter.sender.properties | 0 .../SimpleWebServiceInboundGatewayTests.java | 17 ++--- ...bServiceInboundGatewayJavaConfigTests.java | 6 +- .../ws/config/UriVariableTests.java | 6 +- .../WebServiceOutboundGatewayParserTests.java | 14 ++-- .../config/XmppHeaderEnricherParserTests.java | 4 +- .../ChatMessageListeningEndpointTests.java | 17 +++-- .../PresenceListeningEndpointTests.java | 8 +-- ...ChatMessageSendingMessageHandlerTests.java | 64 +++++++------------ src/checkstyle/checkstyle.xml | 2 +- 77 files changed, 392 insertions(+), 413 deletions(-) create mode 100644 spring-integration-syslog/src/test/resources/log4j.properties rename spring-integration-twitter/src/test/{java => resources}/log4j.properties (100%) rename spring-integration-twitter/src/test/{java => resources}/twitter.receiver.properties (100%) rename spring-integration-twitter/src/test/{java => resources}/twitter.sender.properties (100%) diff --git a/build.gradle b/build.gradle index 1c1a08aa07..2a54d7ba9f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { maven { url 'https://repo.spring.io/plugins-release' } } dependencies { - classpath 'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE' + classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RC2' classpath 'io.spring.gradle:spring-io-plugin:0.0.6.RELEASE' classpath 'io.spring.gradle:docbook-reference-plugin:0.3.1' classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.0' @@ -61,7 +61,7 @@ subprojects { subproject -> apply plugin: 'jacoco' apply plugin: 'checkstyle' - if (project.hasProperty('platformVersion')) { + if (project.hasProperty('platformVersion') && !(subproject.name ==~ /.*-bom/)) { apply plugin: 'spring-io' dependencyManagement { @@ -112,7 +112,7 @@ subprojects { subproject -> jythonVersion = '2.5.3' kryoShadedVersion = '3.0.3' log4jVersion = '1.2.17' - mockitoVersion = '1.10.19' + mockitoVersion = '2.5.4' mysqlVersion = '5.1.34' pahoMqttClientVersion = '1.0.2' postgresVersion = '9.1-901-1.jdbc4' diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java index dc69b70e1e..a65e13be22 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.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. @@ -24,7 +24,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import java.util.Collection; diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java index 59c18bebcd..9867639595 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.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. @@ -21,16 +21,16 @@ import static org.junit.Assert.assertNotNull; 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.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.commons.logging.Log; import org.junit.Test; @@ -54,6 +54,7 @@ import com.rabbitmq.client.Channel; /** * @author Gary Russell + * @author Artem Bilan * @since 2.1 * */ @@ -65,7 +66,7 @@ public class DispatcherHasNoSubscribersTests { final Channel channel = mock(Channel.class); DeclareOk declareOk = mock(DeclareOk.class); when(declareOk.getQueue()).thenReturn("noSubscribersChannel"); - when(channel.queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), any(Map.class))) + when(channel.queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), isNull())) .thenReturn(declareOk); Connection connection = mock(Connection.class); doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean()); @@ -128,7 +129,7 @@ public class DispatcherHasNoSubscribersTests { Log logger = mock(Log.class); final ArrayList logList = new ArrayList(); doAnswer(invocation -> { - String message = invocation.getArgumentAt(0, String.class); + String message = invocation.getArgument(0); if (message.startsWith("Dispatcher has no subscribers")) { logList.add(message); } diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java index fbeb0576b9..abda7fbe6b 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.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,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.isNull; import java.lang.reflect.Field; @@ -33,7 +34,6 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer; -import org.springframework.amqp.rabbit.support.CorrelationData; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.SimpleMessageConverter; import org.springframework.beans.factory.annotation.Autowired; @@ -120,7 +120,7 @@ public class AmqpInboundGatewayParserTests { assertEquals("bar", properties.getHeaders().get("bar")); return null; }).when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(Message.class), Mockito.any(CorrelationData.class)); + Mockito.any(Message.class), isNull()); ReflectionUtils.setField(amqpTemplateField, gateway, amqpTemplate); AbstractMessageListenerContainer mlc = @@ -140,7 +140,7 @@ public class AmqpInboundGatewayParserTests { listener.onMessage(amqpMessage, null); Mockito.verify(amqpTemplate, Mockito.times(1)).send(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(Message.class), Mockito.any(CorrelationData.class)); + Mockito.any(Message.class), isNull()); } @Test diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundChannelAdapterParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundChannelAdapterParserTests.java index fdac72fdad..490ca94aa8 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundChannelAdapterParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundChannelAdapterParserTests.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,7 +23,9 @@ 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.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -40,7 +42,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.internal.stubbing.answers.DoesNothing; @@ -156,8 +157,8 @@ public class AmqpOutboundChannelAdapterParserTests { .setHeader("foobar", "foobar") .build(); requestChannel.send(message); - Mockito.verify(amqpTemplate, Mockito.times(1)).send(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), Mockito.any(CorrelationData.class)); + Mockito.verify(amqpTemplate, Mockito.times(1)).send(anyString(), + isNull(), Mockito.any(org.springframework.amqp.core.Message.class), isNull()); shouldBePersistent.set(true); message = MessageBuilder.withPayload("hello") @@ -211,9 +212,8 @@ public class AmqpOutboundChannelAdapterParserTests { MessageChannel requestChannel = context.getBean("amqpOutboundChannelAdapterWithinChain", MessageChannel.class); Message message = MessageBuilder.withPayload("hello").build(); requestChannel.send(message); - Mockito.verify(amqpTemplate, Mockito.times(1)).send(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), - Mockito.any(CorrelationData.class)); + Mockito.verify(amqpTemplate, Mockito.times(1)).send(Mockito.any(String.class), + isNull(), Mockito.any(org.springframework.amqp.core.Message.class), isNull()); } @Test @@ -316,7 +316,7 @@ public class AmqpOutboundChannelAdapterParserTests { handler.afterPropertiesSet(); handler.start(); handler.stop(); - verify(logger, never()).error(Matchers.anyString(), any(RuntimeException.class)); + verify(logger, never()).error(anyString(), any(RuntimeException.class)); handler.setLazyConnect(false); handler.start(); verify(logger).error("Failed to eagerly establish the connection.", toBeThrown); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java index f62602d083..5607512b1b 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.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. @@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.isNull; import java.lang.reflect.Field; import java.util.List; @@ -34,7 +34,6 @@ import org.mockito.Mockito; import org.springframework.amqp.core.MessageDeliveryMode; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.rabbit.support.CorrelationData; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.ConfigurableApplicationContext; @@ -132,7 +131,7 @@ public class AmqpOutboundGatewayParserTests { return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties); }) .when(amqpTemplate).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), any(CorrelationData.class)); + Mockito.any(org.springframework.amqp.core.Message.class), isNull()); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); MessageChannel requestChannel = context.getBean("toRabbit1", MessageChannel.class); @@ -141,7 +140,7 @@ public class AmqpOutboundGatewayParserTests { Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), - any(CorrelationData.class)); + isNull()); // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); @@ -197,7 +196,7 @@ public class AmqpOutboundGatewayParserTests { return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties); }) .when(amqpTemplate).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), any(CorrelationData.class)); + Mockito.any(org.springframework.amqp.core.Message.class), isNull()); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); MessageChannel requestChannel = context.getBean("toRabbit2", MessageChannel.class); @@ -206,7 +205,7 @@ public class AmqpOutboundGatewayParserTests { Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), - any(CorrelationData.class)); + isNull()); // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); @@ -248,7 +247,7 @@ public class AmqpOutboundGatewayParserTests { return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties); }) .when(amqpTemplate).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), any(CorrelationData.class)); + Mockito.any(org.springframework.amqp.core.Message.class), isNull()); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); MessageChannel requestChannel = context.getBean("toRabbit3", MessageChannel.class); @@ -257,7 +256,7 @@ public class AmqpOutboundGatewayParserTests { Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), - any(CorrelationData.class)); + isNull()); // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); @@ -301,7 +300,7 @@ public class AmqpOutboundGatewayParserTests { return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties); }) .when(amqpTemplate).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), - Mockito.any(org.springframework.amqp.core.Message.class), any(CorrelationData.class)); + Mockito.any(org.springframework.amqp.core.Message.class), isNull()); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); @@ -311,7 +310,7 @@ public class AmqpOutboundGatewayParserTests { Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), - any(CorrelationData.class)); + isNull()); // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java index 066d92e6f8..9c0be44d53 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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,7 +19,7 @@ package org.springframework.integration.amqp.config; 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.mock; import static org.mockito.Mockito.spy; diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/InboundEndpointTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/InboundEndpointTests.java index d71fbfffd7..276f8de59e 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/InboundEndpointTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/InboundEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-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,9 +21,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; 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.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -43,7 +44,6 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; -import org.springframework.amqp.rabbit.support.CorrelationData; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.SimpleMessageConverter; @@ -175,7 +175,7 @@ public class InboundEndpointTests { Mockito.doAnswer(invocation -> { org.springframework.amqp.core.Message message = - invocation.getArgumentAt(2, org.springframework.amqp.core.Message.class); + invocation.getArgument(2); Map headers = message.getMessageProperties().getHeaders(); assertTrue(headers.containsKey(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))); assertNotEquals("foo", headers.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))); @@ -187,8 +187,7 @@ public class InboundEndpointTests { sendLatch.countDown(); return null; }).when(rabbitTemplate) - .send(anyString(), anyString(), any(org.springframework.amqp.core.Message.class), - any(CorrelationData.class)); + .send(anyString(), anyString(), any(org.springframework.amqp.core.Message.class), isNull()); AmqpInboundGateway gateway = new AmqpInboundGateway(container, rabbitTemplate); gateway.setMessageConverter(new Jackson2JsonMessageConverter()); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java index 04bf297083..711a4f30b0 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.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. @@ -21,11 +21,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.startsWith; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willReturn; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -39,7 +40,6 @@ import org.junit.AfterClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.mockito.Matchers; import org.springframework.amqp.core.AmqpReplyTimeoutException; import org.springframework.amqp.rabbit.AsyncRabbitTemplate; @@ -126,7 +126,7 @@ public class AsyncAmqpGatewayTests { invocation.callRealMethod(); replyTimeoutLatch.countDown(); return null; - }).given(logger).debug(Matchers.startsWith("Reply not required and async timeout for")); + }).given(logger).debug(startsWith("Reply not required and async timeout for")); new DirectFieldAccessor(gateway).setPropertyValue("logger", logger); QueueChannel outputChannel = new QueueChannel(); outputChannel.setBeanName("output"); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/OutboundEndpointTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/OutboundEndpointTests.java index f7da1d5967..9be0139427 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/OutboundEndpointTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/OutboundEndpointTests.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,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willDoNothing; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -63,10 +64,10 @@ public class OutboundEndpointTests { RabbitTemplate amqpTemplate = spy(new RabbitTemplate(connectionFactory)); AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate); willDoNothing() - .given(amqpTemplate).send(anyString(), anyString(), any(Message.class), any(CorrelationData.class)); - willAnswer(invocation -> invocation.getArgumentAt(2, Message.class)) + .given(amqpTemplate).send(anyString(), anyString(), any(Message.class), isNull()); + willAnswer(invocation -> invocation.getArgument(2)) .given(amqpTemplate) - .sendAndReceive(anyString(), anyString(), any(Message.class), any(CorrelationData.class)); + .sendAndReceive(anyString(), anyString(), any(Message.class), isNull()); endpoint.setExchangeName("foo"); endpoint.setRoutingKey("bar"); endpoint.setDelayExpressionString("42"); @@ -74,19 +75,19 @@ public class OutboundEndpointTests { endpoint.afterPropertiesSet(); endpoint.handleMessage(new GenericMessage<>("foo")); ArgumentCaptor captor = ArgumentCaptor.forClass(Message.class); - verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), any(CorrelationData.class)); + verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42)); endpoint.setExpectReply(true); endpoint.setOutputChannel(new NullChannel()); endpoint.handleMessage(new GenericMessage<>("foo")); - verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), any(CorrelationData.class)); + verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42)); endpoint.setDelay(23); endpoint.setRoutingKey("baz"); endpoint.afterPropertiesSet(); endpoint.handleMessage(new GenericMessage<>("foo")); - verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), any(CorrelationData.class)); + verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(23)); } @@ -98,7 +99,7 @@ public class OutboundEndpointTests { amqpTemplate.setTaskScheduler(mock(TaskScheduler.class)); AsyncAmqpOutboundGateway gateway = new AsyncAmqpOutboundGateway(amqpTemplate); willAnswer( - invocation -> amqpTemplate.new RabbitMessageFuture("foo", invocation.getArgumentAt(2, Message.class))) + invocation -> amqpTemplate.new RabbitMessageFuture("foo", invocation.getArgument(2))) .given(amqpTemplate).sendAndReceive(anyString(), anyString(), any(Message.class)); gateway.setExchangeName("foo"); gateway.setRoutingKey("bar"); @@ -120,10 +121,9 @@ public class OutboundEndpointTests { final AtomicReference amqpMessage = new AtomicReference(); willAnswer(invocation -> { - amqpMessage.set(invocation.getArgumentAt(2, Message.class)); + amqpMessage.set(invocation.getArgument(2)); return null; - }).given(amqpTemplate).send(anyString(), anyString(), any(Message.class), - any(CorrelationData.class)); + }).given(amqpTemplate).send(isNull(), isNull(), any(Message.class), isNull()); org.springframework.messaging.Message message = MessageBuilder.withPayload("foo") .setHeader(MessageHeaders.CONTENT_TYPE, "bar") .build(); @@ -144,10 +144,10 @@ public class OutboundEndpointTests { final AtomicReference amqpMessage = new AtomicReference(); willAnswer(invocation -> { - amqpMessage.set(invocation.getArgumentAt(2, Message.class)); + amqpMessage.set(invocation.getArgument(2)); return null; }).given(amqpTemplate) - .doSendAndReceiveWithTemporary(anyString(), anyString(), any(Message.class), any(CorrelationData.class)); + .doSendAndReceiveWithTemporary(isNull(), isNull(), any(Message.class), isNull()); org.springframework.messaging.Message message = MessageBuilder.withPayload("foo") .setHeader(MessageHeaders.CONTENT_TYPE, "bar") .setReplyChannel(new QueueChannel()) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java index 131fd3f90c..8b9cb01cba 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java @@ -578,7 +578,8 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } } } - else if (org.springframework.util.ClassUtils.isCglibProxyClass(targetClass)) { + else if (org.springframework.util.ClassUtils.isCglibProxyClass(targetClass) + || targetClass.getSimpleName().contains("$MockitoMock$")) { Class superClass = targetObject.getClass().getSuperclass(); if (!Object.class.equals(superClass)) { targetClass = superClass; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageBarrierTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageBarrierTests.java index 311623def0..1b2745fb20 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageBarrierTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageBarrierTests.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,7 +20,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,7 +34,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.integration.store.MessageGroup; import org.springframework.integration.support.MessageBuilder; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerIntegrationTests.java index 83fd57678c..0e1826df73 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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,8 +16,8 @@ package org.springframework.integration.aggregator; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerTests.java index ef02899814..d1bffab1c5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/CorrelatingMessageHandlerTests.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. @@ -19,8 +19,8 @@ package org.springframework.integration.aggregator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -36,7 +36,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.internal.stubbing.answers.ThrowsException; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.MessageGroupStore; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageGroupProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageGroupProcessorTests.java index f4d80d2783..b9637ed30d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageGroupProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingMessageGroupProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,7 +29,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.beans.factory.BeanFactory; import org.springframework.integration.store.MessageGroup; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessorTests.java index 1849cc4af5..93a5b82718 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessorTests.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. @@ -34,7 +34,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.aop.framework.ProxyFactory; import org.springframework.core.convert.converter.Converter; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/MixedDispatcherConfigurationScenarioTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/MixedDispatcherConfigurationScenarioTests.java index bd6fecdea0..3e9d3e0c4c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/MixedDispatcherConfigurationScenarioTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/MixedDispatcherConfigurationScenarioTests.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.integration.channel; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; @@ -38,7 +38,7 @@ import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -159,7 +159,7 @@ public class MixedDispatcherConfigurationScenarioTests { assertTrue("not all messages were accepted", failed.get()); verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message); verify(handlerB, times(0)).handleMessage(message); - verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add((Exception) anyObject()); + verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class)); } @Test @@ -178,10 +178,6 @@ public class MixedDispatcherConfigurationScenarioTests { throw e; }).when(handlerA).handleMessage(message); - doAnswer(invocation -> { - allDone.countDown(); - return null; - }).when(handlerB).handleMessage(message); Runnable messageSenderTask = () -> { try { @@ -204,7 +200,7 @@ public class MixedDispatcherConfigurationScenarioTests { assertTrue("not all messages were accepted", failed.get()); verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message); verify(handlerB, times(0)).handleMessage(message); - verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add((Exception) anyObject()); + verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class)); } @Test @@ -286,7 +282,7 @@ public class MixedDispatcherConfigurationScenarioTests { verify(handlerA, times(14)).handleMessage(message); verify(handlerB, times(13)).handleMessage(message); verify(handlerC, times(13)).handleMessage(message); - verify(exceptionRegistry, times(14)).add((Exception) anyObject()); + verify(exceptionRegistry, times(14)).add(any(Exception.class)); } @Test @@ -339,7 +335,7 @@ public class MixedDispatcherConfigurationScenarioTests { verify(handlerA, times(14)).handleMessage(message); verify(handlerB, times(13)).handleMessage(message); verify(handlerC, times(13)).handleMessage(message); - verify(exceptionRegistry, times(14)).add((Exception) anyObject()); + verify(exceptionRegistry, times(14)).add(any(Exception.class)); } @Test @@ -420,7 +416,7 @@ public class MixedDispatcherConfigurationScenarioTests { verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message); verify(handlerB, times(TOTAL_EXECUTIONS)).handleMessage(message); verify(handlerC, never()).handleMessage(message); - verify(exceptionRegistry, never()).add((Exception) anyObject()); + verify(exceptionRegistry, never()).add(any(Exception.class)); } @Test @@ -440,7 +436,6 @@ public class MixedDispatcherConfigurationScenarioTests { allDone.countDown(); return null; }).when(handlerB).handleMessage(message); - doAnswer(invocation -> null).when(handlerC).handleMessage(message); Runnable messageSenderTask = () -> { try { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java index 3b68231902..2d9a510a12 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.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. @@ -55,9 +55,9 @@ public class P2pChannelTests { private void verifySubscriptions(final AbstractSubscribableChannel channel) { final Log logger = mock(Log.class); when(logger.isInfoEnabled()).thenReturn(true); - final List logs = new ArrayList(); + final List logs = new ArrayList<>(); doAnswer(invocation -> { - logs.add(invocation.getArgumentAt(0, String.class)); + logs.add(invocation.getArgument(0)); return null; }).when(logger).info(Mockito.anyString()); ReflectionUtils.doWithFields(AbstractMessageChannel.class, field -> { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/ReactiveConsumerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/ReactiveConsumerTests.java index d10c39f6be..2fcea32dfd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/ReactiveConsumerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/ReactiveConsumerTests.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,7 +23,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -109,7 +109,7 @@ public class ReactiveConsumerTests { BlockingQueue> messages = new LinkedBlockingQueue<>(); willAnswer(i -> { - messages.put(i.getArgumentAt(0, Message.class)); + messages.put(i.getArgument(0)); return null; }) .given(testSubscriber) @@ -169,7 +169,7 @@ public class ReactiveConsumerTests { BlockingQueue> messages = new LinkedBlockingQueue<>(); willAnswer(i -> { - messages.put(i.getArgumentAt(0, Message.class)); + messages.put(i.getArgument(0)); return null; }) .given(testSubscriber) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChainParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ChainParserTests.java index 7ec4db90b8..0d2536d660 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChainParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChainParserTests.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,7 +24,7 @@ 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.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -309,7 +309,7 @@ public class ChainParserTests { final AtomicReference log = new AtomicReference(); when(logger.isWarnEnabled()).thenReturn(true); doAnswer(invocation -> { - log.set(invocation.getArgumentAt(0, String.class)); + log.set(invocation.getArgument(0)); return null; }).when(logger).warn(any()); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java index 5d23d62a8f..b518e86f06 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.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,8 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.willAnswer; -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.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -122,7 +122,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { }); when(txAdvice.invoke(any(MethodInvocation.class))).thenAnswer(invocation -> { count.incrementAndGet(); - return invocation.getArgumentAt(0, MethodInvocation.class).proceed(); + return ((MethodInvocation) invocation.getArgument(0)).proceed(); }); pollerMetadata.setAdviceChain(adviceChain); @@ -195,7 +195,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { TaskScheduler taskScheduler = mock(TaskScheduler.class); willAnswer(invocation -> { - Runnable task = invocation.getArgumentAt(0, Runnable.class); + Runnable task = invocation.getArgument(0); task.run(); return null; }) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PublishingInterceptorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PublishingInterceptorParserTests.java index 0300fbf5d4..07e9467ea8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PublishingInterceptorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PublishingInterceptorParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,7 +17,7 @@ package org.springframework.integration.config.xml; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -36,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Gunnar Hillert + * @author Artem Bilan * @since 2.0 */ @ContextConfiguration @@ -60,12 +61,12 @@ public class PublishingInterceptorParserTests { MessageHandler handler = Mockito.mock(MessageHandler.class); defaultChannel.subscribe(handler); doAnswer(invocation -> { - Message message = (Message) invocation.getArguments()[0]; + Message message = invocation.getArgument(0); assertEquals("hello", message.getPayload()); return null; - }).when(handler).handleMessage((Message) anyObject()); + }).when(handler).handleMessage(any(Message.class)); testBean.echoDefaultChannel("hello"); - verify(handler, times(1)).handleMessage((Message) anyObject()); + verify(handler, times(1)).handleMessage(any(Message.class)); } @Test @@ -73,13 +74,13 @@ public class PublishingInterceptorParserTests { MessageHandler handler = Mockito.mock(MessageHandler.class); echoChannel.subscribe(handler); doAnswer(invocation -> { - Message message = (Message) invocation.getArguments()[0]; + Message message = invocation.getArgument(0); assertEquals("bar", message.getHeaders().get("foo")); assertEquals("Echoing: hello", message.getPayload()); return null; - }).when(handler).handleMessage((Message) anyObject()); + }).when(handler).handleMessage(any(Message.class)); testBean.echo("hello"); - verify(handler, times(1)).handleMessage((Message) anyObject()); + verify(handler, times(1)).handleMessage(any(Message.class)); } /** @@ -104,6 +105,7 @@ public class PublishingInterceptorParserTests { public String echoDefaultChannel(String str) { return str; } + } @@ -112,6 +114,7 @@ public class PublishingInterceptorParserTests { public String echo(String str) { return str; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/BroadcastingDispatcherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/BroadcastingDispatcherTests.java index cf4baa8cea..6b4e1cc52c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/BroadcastingDispatcherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/BroadcastingDispatcherTests.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. @@ -276,7 +276,7 @@ public class BroadcastingDispatcherTests { private void defaultTaskExecutorMock() { Mockito.doAnswer(invocation -> { - (invocation.getArgumentAt(0, Runnable.class)).run(); + ((Runnable) invocation.getArgument(0)).run(); return null; }).when(taskExecutorMock).execute(Mockito.any(Runnable.class)); } @@ -288,7 +288,7 @@ public class BroadcastingDispatcherTests { final AtomicInteger count = new AtomicInteger(); Mockito.doAnswer(invocation -> { if (passes[count.getAndIncrement()]) { - (invocation.getArgumentAt(0, Runnable.class)).run(); + ((Runnable) invocation.getArgument(0)).run(); } return null; }).when(taskExecutorMock).execute(Mockito.any(Runnable.class)); @@ -307,6 +307,7 @@ public class BroadcastingDispatcherTests { public void handleMessage(Message message) { this.messageList.add(message); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherConcurrentTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherConcurrentTests.java index 6d02696e42..38296ae71e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherConcurrentTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherConcurrentTests.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 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.integration.MessageRejectedException; import org.springframework.messaging.Message; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherTests.java index bb8152e754..d697f6ac44 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/RoundRobinDispatcherTests.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,7 +29,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.beans.DirectFieldAccessor; import org.springframework.integration.support.MessageBuilder; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java index 842c9bd5b0..227c943fb3 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.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. @@ -23,7 +23,7 @@ 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.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandlerTests.java index 6408e40d5f..05511b5b7a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,32 +16,35 @@ package org.springframework.integration.handler; +import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import org.junit.Test; -import static org.hamcrest.CoreMatchers.containsString; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessagingException; -import org.springframework.integration.support.MessageBuilder; /** * @author Iwein Fuld * @author Gunnar Hillert */ -@RunWith(org.mockito.runners.MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class AbstractReplyProducingMessageHandlerTests { private AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { + @Override protected Object handleRequestMessage(Message requestMessage) { return requestMessage; } + }; private Message message = MessageBuilder.withPayload("test").build(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/AsyncHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/AsyncHandlerTests.java index 3fbeb27b2d..f309e9b6d1 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/AsyncHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/AsyncHandlerTests.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. @@ -25,8 +25,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.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.spy; @@ -111,8 +111,8 @@ public class AsyncHandlerTests { Log logger = spy(TestUtils.getPropertyValue(this.handler, "logger", Log.class)); new DirectFieldAccessor(this.handler).setPropertyValue("logger", logger); doAnswer(invocation -> { - failedCallbackMessage = invocation.getArgumentAt(0, String.class); - failedCallbackException = invocation.getArgumentAt(1, Exception.class); + failedCallbackMessage = invocation.getArgument(0); + failedCallbackException = invocation.getArgument(1); exceptionLatch.countDown(); return null; }).when(logger).error(anyString(), any(Throwable.class)); @@ -260,6 +260,7 @@ public class AsyncHandlerTests { private interface Foo { String exchange(String payload); + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MessageHandlerChainTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MessageHandlerChainTests.java index 335b676076..d1bb5dbe30 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MessageHandlerChainTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MessageHandlerChainTests.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,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -69,7 +69,6 @@ public class MessageHandlerChainTests { @Before public void setup() { Mockito.when(outputChannel.send(Mockito.any(Message.class))).thenReturn(true); - Mockito.when(outputChannel.send(Mockito.any(Message.class), Mockito.anyLong())).thenReturn(true); producer1 = new ProducingHandlerStub(handler1); producer2 = new ProducingHandlerStub(handler2); producer3 = new ProducingHandlerStub(handler3); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/SendTimeoutConfigurationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/SendTimeoutConfigurationTests.java index ba1abaf21a..bb885c41ce 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/SendTimeoutConfigurationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/SendTimeoutConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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. @@ -66,7 +66,7 @@ public class SendTimeoutConfigurationTests { private long getTimeout(String endpointName) { return TestUtils.getPropertyValue(context.getBean(endpointName), - "handler.messagingTemplate.sendTimeout", Long.class).longValue(); + "handler.messagingTemplate.sendTimeout", Long.class); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java index a01987665b..925dc30537 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java @@ -897,7 +897,7 @@ public class AdvisedMessageHandlerTests { when(logger.isWarnEnabled()).thenReturn(Boolean.TRUE); final AtomicReference logMessage = new AtomicReference(); doAnswer(invocation -> { - logMessage.set(invocation.getArgumentAt(0, String.class)); + logMessage.set(invocation.getArgument(0)); return null; }).when(logger).warn(Mockito.anyString()); DirectFieldAccessor accessor = new DirectFieldAccessor(advice); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java index e5f8b515cc..c9d8243e18 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.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,7 +24,7 @@ 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.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java index cd9ded3030..da3857d21a 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.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.integration.file; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java index 7094a2e792..2d9082bcfb 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.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. @@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -36,7 +36,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.messaging.Message; @@ -154,9 +154,6 @@ public class FileReadingMessageSourceTests { // record the comparator to reverse order the files when(comparator.compare(file1, file2)).thenReturn(1); when(comparator.compare(file1, file3)).thenReturn(1); - when(comparator.compare(file2, file3)).thenReturn(1); - when(comparator.compare(file2, file1)).thenReturn(-1); - when(comparator.compare(file3, file1)).thenReturn(-1); when(comparator.compare(file3, file2)).thenReturn(-1); when(inputDirectoryMock.listFiles()).thenReturn(new File[]{file2, file3, file1}); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java index 560771f528..4dc606d4b3 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.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. @@ -28,8 +28,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.mock; import static org.mockito.Mockito.times; @@ -309,7 +309,7 @@ public class RemoteFileOutboundGatewayTests { }).when(session).rename(anyString(), anyString()); final List madeDirs = new ArrayList(); doAnswer(invocation -> { - madeDirs.add(invocation.getArgumentAt(0, String.class)); + madeDirs.add(invocation.getArgument(0)); return null; }).when(session).mkdir(anyString()); when(sessionFactory.getSession()).thenReturn(session); @@ -909,7 +909,7 @@ public class RemoteFileOutboundGatewayTests { when(sessionFactory.getSession()).thenReturn(session); final AtomicReference written = new AtomicReference(); doAnswer(invocation -> { - written.set(invocation.getArgumentAt(1, String.class)); + written.set(invocation.getArgument(1)); return null; }).when(session).write(any(InputStream.class), anyString()); tempFolder.newFile("baz.txt"); @@ -943,7 +943,7 @@ public class RemoteFileOutboundGatewayTests { when(sessionFactory.getSession()).thenReturn(session); final AtomicReference written = new AtomicReference(); doAnswer(invocation -> { - written.set(invocation.getArgumentAt(1, String.class)); + written.set(invocation.getArgument(1)); return null; }).when(session).write(any(InputStream.class), anyString()); tempFolder.newFile("baz.txt"); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java index 84ff4ad642..ff03cbb365 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.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,8 +19,8 @@ package org.springframework.integration.file.remote.handler; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; -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.doThrow; import static org.mockito.Mockito.mock; @@ -64,7 +64,7 @@ public class FileTransferringMessageHandlerTests { when(sf.getSession()).thenReturn(session); doAnswer(invocation -> { - String path = invocation.getArgumentAt(1, String.class); + String path = invocation.getArgument(1); assertFalse(path.startsWith("/")); return null; }).when(session).rename(Mockito.anyString(), Mockito.anyString()); @@ -87,8 +87,8 @@ public class FileTransferringMessageHandlerTests { final AtomicReference finalPath = new AtomicReference(); when(sf.getSession()).thenReturn(session); doAnswer(invocation -> { - temporaryPath.set(invocation.getArgumentAt(0, String.class)); - finalPath.set(invocation.getArgumentAt(1, String.class)); + temporaryPath.set(invocation.getArgument(0)); + finalPath.set(invocation.getArgument(1)); return null; }).when(session).rename(Mockito.anyString(), Mockito.anyString()); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sf); @@ -110,7 +110,7 @@ public class FileTransferringMessageHandlerTests { when(sf.getSession()).thenReturn(session); doAnswer(invocation -> { - String path = invocation.getArgumentAt(1, String.class); + String path = invocation.getArgument(1); assertFalse(path.startsWith("/")); return null; }).when(session).rename(Mockito.anyString(), Mockito.anyString()); @@ -195,4 +195,5 @@ public class FileTransferringMessageHandlerTests { when(session.isOpen()).thenReturn(false); return session; } + } diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java index 39e6423b1a..7e60396ddb 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.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,7 +20,7 @@ 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.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -44,8 +44,6 @@ import org.apache.commons.net.ftp.FTPFile; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; @@ -73,6 +71,7 @@ import org.springframework.util.FileCopyUtils; public class FtpOutboundTests { private static FTPClient ftpClient; + private TestFtpSessionFactory sessionFactory; @Before @@ -159,9 +158,9 @@ public class FtpOutboundTests { Log logger = spy(TestUtils.getPropertyValue(handler, "remoteFileTemplate.logger", Log.class)); when(logger.isWarnEnabled()).thenReturn(true); - final AtomicReference logged = new AtomicReference(); + final AtomicReference logged = new AtomicReference<>(); doAnswer(invocation -> { - logged.set(invocation.getArgumentAt(0, String.class)); + logged.set(invocation.getArgument(0)); invocation.callRealMethod(); return null; }).when(logger).warn(Mockito.anyString()); @@ -228,27 +227,20 @@ public class FtpOutboundTests { when(ftpClient.login("kermit", "frog")).thenReturn(true); when(ftpClient.changeWorkingDirectory(Mockito.anyString())).thenReturn(true); when(ftpClient.printWorkingDirectory()).thenReturn("remote-target-dir"); - when(ftpClient.storeFile(Mockito.anyString(), any(InputStream.class))).thenAnswer(new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - String fileName = invocation.getArgumentAt(0, String.class); - InputStream fis = invocation.getArgumentAt(1, InputStream.class); - FileCopyUtils.copy(fis, new FileOutputStream(fileName)); - return true; - } + when(ftpClient.storeFile(Mockito.anyString(), any(InputStream.class))).thenAnswer(invocation -> { + String fileName = invocation.getArgument(0); + InputStream fis = invocation.getArgument(1); + FileCopyUtils.copy(fis, new FileOutputStream(fileName)); + return true; }); - when(ftpClient.rename(Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) - throws Throwable { - File file = new File(invocation.getArgumentAt(0, String.class)); - File renameToFile = new File(invocation.getArgumentAt(1, String.class)); - file.renameTo(renameToFile); - return true; - } + when(ftpClient.rename(Mockito.anyString(), Mockito.anyString())).thenAnswer(invocation -> { + File file = new File((String) invocation.getArgument(0)); + File renameToFile = new File((String) invocation.getArgument(1)); + file.renameTo(renameToFile); + return true; }); String[] files = new File("remote-test-dir").list(); - Collection ftpFiles = new ArrayList(); + Collection ftpFiles = new ArrayList<>(); for (String fileName : files) { FTPFile file = new FTPFile(); file.setName(fileName); @@ -258,13 +250,15 @@ public class FtpOutboundTests { when(ftpClient.retrieveFile(Mockito.eq("remote-test-dir/" + fileName), any(OutputStream.class))).thenReturn(true); } - when(ftpClient.listFiles("remote-test-dir/")).thenReturn(ftpFiles.toArray(new FTPFile[]{})); + when(ftpClient.listFiles("remote-test-dir/")) + .thenReturn(ftpFiles.toArray(new FTPFile[ftpFiles.size()])); return ftpClient; } catch (Exception e) { throw new RuntimeException("Failed to create mock client", e); } } + } } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java index b93bcf9cbb..1973aee237 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-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,6 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.isNull; import java.net.URI; import java.text.DateFormat; @@ -120,7 +121,7 @@ public class HttpProxyScenarioTests { final String contentDispositionValue = "attachment; filename=\"test.txt\""; Mockito.doAnswer(invocation -> { - URI uri = invocation.getArgumentAt(0, URI.class); + URI uri = invocation.getArgument(0); assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri); HttpEntity httpEntity = (HttpEntity) invocation.getArguments()[2]; HttpHeaders httpHeaders = httpEntity.getHeaders(); @@ -131,9 +132,9 @@ public class HttpProxyScenarioTests { MultiValueMap responseHeaders = new LinkedMultiValueMap(httpHeaders); responseHeaders.set("Connection", "close"); responseHeaders.set("Content-Disposition", contentDispositionValue); - return new ResponseEntity(responseHeaders, HttpStatus.OK); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); }).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class), - Mockito.any(HttpEntity.class), (Class) Mockito.any(Class.class)); + Mockito.any(HttpEntity.class), (Class) isNull()); PropertyAccessor dfa = new DirectFieldAccessor(this.handler); dfa.setPropertyValue("restTemplate", template); @@ -173,7 +174,7 @@ public class HttpProxyScenarioTests { RestTemplate template = Mockito.spy(new RestTemplate()); Mockito.doAnswer(invocation -> { - URI uri = invocation.getArgumentAt(0, URI.class); + URI uri = invocation.getArgument(0); assertEquals(new URI("http://testServer/testmp"), uri); HttpEntity httpEntity = (HttpEntity) invocation.getArguments()[2]; HttpHeaders httpHeaders = httpEntity.getHeaders(); @@ -190,7 +191,7 @@ public class HttpProxyScenarioTests { responseHeaders.set("Content-Type", "text/plain"); return new ResponseEntity(responseHeaders, HttpStatus.OK); }).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class), - Mockito.any(HttpEntity.class), (Class) Mockito.any(Class.class)); + Mockito.any(HttpEntity.class), (Class) isNull()); PropertyAccessor dfa = new DirectFieldAccessor(this.handlermp); dfa.setPropertyValue("restTemplate", template); diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java index 4da8053a04..1071d6dd7e 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.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,6 +20,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -32,7 +33,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -73,14 +73,14 @@ public class MultipartAsRawByteArrayTests { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { - byte[] buff = invocation.getArgumentAt(0, byte[].class); + byte[] buff = invocation.getArgument(0); buff[0] = 'f'; buff[1] = 'o'; buff[2] = 'o'; return done++ > 0 ? -1 : 3; } - }).when(sis).read(Matchers.any(byte[].class)); + }).when(sis).read(any(byte[].class)); when(request.getInputStream()).thenReturn(sis); when(request.getMethod()).thenReturn("POST"); when(request.getHeaderNames()).thenReturn(mock(Enumeration.class)); diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java index 0ca4705550..f6c7f29b97 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests.java index d54bd2d604..b7513cbd14 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests.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,9 +25,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.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.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -776,15 +776,10 @@ public class CachingClientConnectionFactoryTests { @Override public Void answer(InvocationOnMock invocation) throws Throwable { invocation.callRealMethod(); - String log = invocation.getArgumentAt(0, String.class); + String log = invocation.getArgument(0); if (log.startsWith("Response")) { - Executors.newSingleThreadScheduledExecutor().execute(new Runnable() { - - @Override - public void run() { - gate.handleMessage(new GenericMessage("bar")); - } - }); + Executors.newSingleThreadScheduledExecutor() + .execute(() -> gate.handleMessage(new GenericMessage<>("bar"))); // hold up the first thread until the second has added its pending reply latch.await(10, TimeUnit.SECONDS); } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionEventTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionEventTests.java index 96b395d447..3664f231af 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionEventTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionEventTests.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. @@ -27,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.doThrow; import static org.mockito.Mockito.mock; diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java index 61dd5c2fa9..13b913c5e3 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java @@ -24,8 +24,8 @@ import static org.junit.Assert.assertEquals; 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.contains; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java index a06184550e..b2df37605e 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.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,7 +23,8 @@ import static org.junit.Assert.assertNotNull; 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.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; @@ -67,7 +68,6 @@ import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -303,7 +303,7 @@ public class TcpNioConnectionTests { Socket socket = mock(Socket.class); Mockito.when(channel.socket()).thenReturn(socket); doAnswer(invocation -> { - ByteBuffer buffer = invocation.getArgumentAt(0, ByteBuffer.class); + ByteBuffer buffer = invocation.getArgument(0); buffer.position(1); return 1; }).when(channel).read(Mockito.any(ByteBuffer.class)); @@ -343,21 +343,18 @@ public class TcpNioConnectionTests { Socket socket = mock(Socket.class); Mockito.when(channel.socket()).thenReturn(socket); doAnswer(invocation -> { - ByteBuffer buffer = invocation.getArgumentAt(0, ByteBuffer.class); + ByteBuffer buffer = invocation.getArgument(0); buffer.position(1025); buffer.put((byte) '\r'); buffer.put((byte) '\n'); return 1027; }).when(channel).read(Mockito.any(ByteBuffer.class)); - final TcpNioConnection connection = new TcpNioConnection(channel, false, false, null, null); + final TcpNioConnection connection = new TcpNioConnection(channel, false, false, + null, null); connection.setTaskExecutor(exec); - connection.registerListener(new TcpListener() { - - @Override - public boolean onMessage(Message message) { - messageLatch.countDown(); - return false; - } + connection.registerListener(message -> { + messageLatch.countDown(); + return false; }); connection.setMapper(new TcpMessageMapper()); connection.setDeserializer(new ByteArrayCrLfSerializer()); @@ -501,7 +498,7 @@ public class TcpNioConnectionTests { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { - ByteBuffer buff = invocation.getArgumentAt(0, ByteBuffer.class); + ByteBuffer buff = invocation.getArgument(0); byte[] bytes = written.toByteArray(); buff.put(bytes); return bytes.length; @@ -516,7 +513,7 @@ public class TcpNioConnectionTests { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - ByteBuffer buff = invocation.getArgumentAt(0, ByteBuffer.class); + ByteBuffer buff = invocation.getArgument(0); byte[] bytes = new byte[buff.limit()]; buff.get(bytes); written.write(bytes); @@ -771,7 +768,7 @@ public class TcpNioConnectionTests { readerLatch.countDown(); return null; } - }).when(logger).trace(Matchers.contains("checking data avail")); + }).when(logger).trace(contains("checking data avail")); doAnswer(new Answer() { @@ -781,7 +778,7 @@ public class TcpNioConnectionTests { readerLatch.countDown(); return null; } - }).when(logger).trace(Matchers.contains("Nio assembler continuing")); + }).when(logger).trace(contains("Nio assembler continuing")); socket.getOutputStream().write("foo\r\n".getBytes()); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java index c3a3734bfd..3a4cd3bd7f 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.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,6 +19,8 @@ package org.springframework.integration.jms; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +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.spy; @@ -29,7 +31,6 @@ import javax.jms.Session; import org.apache.commons.logging.Log; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.internal.stubbing.answers.DoesNothing; import org.springframework.beans.DirectFieldAccessor; @@ -73,7 +74,7 @@ public class ChannelPublishingJmsMessageListenerTests { final QueueChannel requestChannel = new QueueChannel(); ChannelPublishingJmsMessageListener listener = new ChannelPublishingJmsMessageListener(); Log logger = spy(TestUtils.getPropertyValue(listener, "logger", Log.class)); - doAnswer(new DoesNothing()).when(logger).error(Matchers.anyString(), Matchers.any(Throwable.class)); + doAnswer(new DoesNothing()).when(logger).error(anyString(), any(Throwable.class)); new DirectFieldAccessor(listener).setPropertyValue("logger", logger); listener.setRequestChannel(requestChannel); QueueChannel errorChannel = new QueueChannel(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/DefaultJmsHeaderMapperTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/DefaultJmsHeaderMapperTests.java index 624b6e6d5b..d1434ebce0 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/DefaultJmsHeaderMapperTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/DefaultJmsHeaderMapperTests.java @@ -533,7 +533,7 @@ public class DefaultJmsHeaderMapperTests { Session session = Mockito.mock(Session.class); - Mockito.doAnswer(invocation -> new StubTextMessage(invocation.getArgumentAt(0, String.class))).when(session) + Mockito.doAnswer(invocation -> new StubTextMessage(invocation.getArgument(0))).when(session) .createTextMessage(Mockito.anyString()); javax.jms.Message request = converter.toMessage(new Foo(), session); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java index 04662304f7..38a19bbe80 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.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,9 +19,9 @@ package org.springframework.integration.jms; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -119,7 +119,7 @@ public class JmsOutboundGatewayTests extends LogAdjustingTestSupport { Session session = mock(Session.class); when(connection.createSession(false, 1)).thenReturn(session); MessageConsumer consumer = mock(MessageConsumer.class); - when(session.createConsumer(any(Destination.class), anyString())).thenReturn(consumer); + when(session.createConsumer(any(Destination.class), isNull())).thenReturn(consumer); when(session.createTemporaryQueue()).thenReturn(mock(TemporaryQueue.class)); final Message message = mock(Message.class); final AtomicInteger count = new AtomicInteger(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java index d65ff9a1f1..72c31a42b4 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.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,8 +23,8 @@ import static org.junit.Assert.assertNotNull; 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.mock; import static org.mockito.Mockito.when; @@ -318,7 +318,7 @@ public class SubscribableJmsChannelTests { Log logger = mock(Log.class); final ArrayList logList = new ArrayList(); doAnswer(invocation -> { - String message = invocation.getArgumentAt(0, String.class); + String message = invocation.getArgument(0); if (message.startsWith("Dispatcher has no subscribers")) { logList.add(message); } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java index acd9801cc0..692f9e6980 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.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. @@ -55,7 +55,7 @@ public class JmsChannelHistoryTests { doAnswer(invocation -> { @SuppressWarnings("unchecked") - Message msg = invocation.getArgumentAt(0, Message.class); + Message msg = invocation.getArgument(0); MessageHistory history = MessageHistory.read(msg); assertTrue(history.get(0).contains("jmsChannel")); return null; diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleIntegrationTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleIntegrationTests.java index 658e14de2c..d50d6e40df 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleIntegrationTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleIntegrationTests.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.integration.mail.config; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/MessageWithContentTypeTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/MessageWithContentTypeTests.java index 9d620a244e..5eae816bed 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/MessageWithContentTypeTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/MessageWithContentTypeTests.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. @@ -33,8 +33,6 @@ import javax.mail.internet.MimeMessage; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -82,13 +80,10 @@ public class MessageWithContentTypeTests { MimeMessage mMessage = new TestMimeMessage(); // MOCKS when(sender.createMimeMessage()).thenReturn(mMessage); - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - MimeMessage mimeMessage = invocation.getArgumentAt(0, MimeMessage.class); - assertEquals("text/html", mimeMessage.getDataHandler().getContentType()); - return null; - } + doAnswer(invocation -> { + MimeMessage mimeMessage = invocation.getArgument(0); + assertEquals("text/html", mimeMessage.getDataHandler().getContentType()); + return null; }).when(sender).send(Mockito.any(MimeMessage.class)); // handle message @@ -102,4 +97,5 @@ public class MessageWithContentTypeTests { super(Session.getDefaultInstance(new Properties())); } } + } diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/DownstreamExceptionTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/DownstreamExceptionTests.java index adf933663b..8412876f1b 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/DownstreamExceptionTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/DownstreamExceptionTests.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. @@ -19,9 +19,9 @@ package org.springframework.integration.mqtt; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -75,9 +75,9 @@ public class DownstreamExceptionTests { public void testNoErrorChannel() throws Exception { service.n = 0; Log logger = spy(TestUtils.getPropertyValue(noErrorChannel, "logger", Log.class)); - final CountDownLatch latch = new CountDownLatch(1); + final CountDownLatch latch = new CountDownLatch(1); doAnswer(invocation -> { - if ((invocation.getArgumentAt(0, String.class)).contains("Unhandled")) { + if (((String) invocation.getArgument(0)).contains("Unhandled")) { latch.countDown(); } return null; diff --git a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java index fbf89ee367..a8b31db709 100644 --- a/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.java +++ b/spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/MqttAdapterTests.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. @@ -22,8 +22,8 @@ import static org.junit.Assert.assertNotNull; 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.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -81,6 +81,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; /** * @author Gary Russell + * @author Artem Bilan * @since 4.0 * */ @@ -154,7 +155,7 @@ public class MqttAdapterTests { final MqttToken token = mock(MqttToken.class); final AtomicBoolean connectCalled = new AtomicBoolean(); doAnswer(invocation -> { - MqttConnectOptions options = invocation.getArgumentAt(0, MqttConnectOptions.class); + MqttConnectOptions options = invocation.getArgument(0); assertEquals(23, options.getConnectionTimeout()); assertEquals(45, options.getKeepAliveInterval()); assertEquals("pass", new String(options.getPassword())); @@ -173,7 +174,7 @@ public class MqttAdapterTests { final AtomicBoolean publishCalled = new AtomicBoolean(); doAnswer(invocation -> { assertEquals("mqtt-foo", invocation.getArguments()[0]); - MqttMessage message = invocation.getArgumentAt(1, MqttMessage.class); + MqttMessage message = invocation.getArgument(1); assertEquals("Hello, world!", new String(message.getPayload())); publishCalled.set(true); return deliveryToken; @@ -219,7 +220,7 @@ public class MqttAdapterTests { waitToFail.await(10, TimeUnit.SECONDS); throw reconnectException; } - MqttConnectOptions options = invocation.getArgumentAt(0, MqttConnectOptions.class); + MqttConnectOptions options = invocation.getArgument(0); assertEquals(23, options.getConnectionTimeout()); assertEquals(45, options.getKeepAliveInterval()); assertEquals("pass", new String(options.getPassword())); @@ -238,7 +239,7 @@ public class MqttAdapterTests { final AtomicReference callback = new AtomicReference(); doAnswer(invocation -> { - callback.set(invocation.getArgumentAt(0, MqttCallback.class)); + callback.set(invocation.getArgument(0)); return null; }).when(client).setCallback(any(MqttCallback.class)); @@ -255,7 +256,7 @@ public class MqttAdapterTests { ApplicationEventPublisher applicationEventPublisher = mock(ApplicationEventPublisher.class); final BlockingQueue events = new LinkedBlockingQueue(); doAnswer(invocation -> { - events.add(invocation.getArgumentAt(0, MqttIntegrationEvent.class)); + events.add(invocation.getArgument(0)); return null; }).when(applicationEventPublisher).publishEvent(any(MqttIntegrationEvent.class)); adapter.setApplicationEventPublisher(applicationEventPublisher); @@ -353,18 +354,18 @@ public class MqttAdapterTests { TestUtils.getPropertyValue(handler, "topicProcessor", MessageProcessor.class).processMessage(message)); assertEquals(1, TestUtils.getPropertyValue(handler, "converter.qosProcessor", MessageProcessor.class) - .processMessage(message)); + .processMessage(message)); assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(handler, "converter.retainedProcessor", MessageProcessor.class) - .processMessage(message)); + .processMessage(message)); handler = ctx.getBean("handlerWithNullExpressions", MqttPahoMessageHandler.class); assertEquals(1, TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class) - .fromMessage(message, null).getQos()); + .fromMessage(message, null).getQos()); assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class) - .fromMessage(message, null).isRetained()); + .fromMessage(message, null).isRetained()); ctx.close(); } diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java index 46e4d3643a..8a8c6a6344 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-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.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.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import org.junit.Test; diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java index 0c6db3b17b..bb39e9b8ed 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.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. @@ -21,7 +21,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -141,4 +141,5 @@ public class RmiOutboundGatewayParserTests { } } + } diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java index 7ecef2b59c..7d276b9f13 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.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,7 +21,7 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -210,7 +210,7 @@ public class SftpOutboundTests { handler.afterPropertiesSet(); final List madeDirs = new ArrayList(); doAnswer(invocation -> { - madeDirs.add(invocation.getArgumentAt(0, String.class)); + madeDirs.add(invocation.getArgument(0)); return null; }).when(session).mkdir(anyString()); handler.handleMessage(new GenericMessage("qux")); @@ -385,16 +385,16 @@ public class SftpOutboundTests { ChannelSftp channel = mock(ChannelSftp.class); doAnswer(invocation -> { - File file = new File(invocation.getArgumentAt(1, String.class)); + File file = new File((String) invocation.getArgument(1)); assertTrue(file.getName().endsWith(".writing")); - FileCopyUtils.copy(invocation.getArgumentAt(0, InputStream.class), new FileOutputStream(file)); + FileCopyUtils.copy((InputStream) invocation.getArgument(0), new FileOutputStream(file)); return null; }).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString()); doAnswer(invocation -> { - File file = new File(invocation.getArgumentAt(0, String.class)); + File file = new File((String) invocation.getArgument(0)); assertTrue(file.getName().endsWith(".writing")); - File renameToFile = new File(invocation.getArgumentAt(1, String.class)); + File renameToFile = new File((String) invocation.getArgument(1)); file.renameTo(renameToFile); return null; }).when(channel).rename(Mockito.anyString(), Mockito.anyString()); diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpSessionFactoryTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpSessionFactoryTests.java index 4a7a853bec..1187f4049f 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpSessionFactoryTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpSessionFactoryTests.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/spring-integration-stream/src/test/java/org/springframework/integration/stream/CharacterStreamSourceTests.java b/spring-integration-stream/src/test/java/org/springframework/integration/stream/CharacterStreamSourceTests.java index 0e38cb9ddc..7462763cdf 100644 --- a/spring-integration-stream/src/test/java/org/springframework/integration/stream/CharacterStreamSourceTests.java +++ b/spring-integration-stream/src/test/java/org/springframework/integration/stream/CharacterStreamSourceTests.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,7 +21,7 @@ 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.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java b/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java index d13d2d470c..5dcd50b777 100644 --- a/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java +++ b/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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.integration.stream.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterTests.java b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterTests.java index 12cbb94414..d425c5f2cc 100644 --- a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterTests.java +++ b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterTests.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,8 +19,8 @@ package org.springframework.integration.syslog.inbound; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; 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; @@ -109,7 +109,7 @@ public class SyslogReceivingChannelAdapterTests { doReturn(true).when(logger).isDebugEnabled(); final CountDownLatch sawLog = new CountDownLatch(1); doAnswer(invocation -> { - if ((invocation.getArgumentAt(0, String.class)).contains("Error on syslog socket")) { + if (((String) invocation.getArgument(0)).contains("Error on syslog socket")) { sawLog.countDown(); } invocation.callRealMethod(); @@ -184,7 +184,7 @@ public class SyslogReceivingChannelAdapterTests { doReturn(true).when(logger).isDebugEnabled(); final CountDownLatch sawLog = new CountDownLatch(1); doAnswer(invocation -> { - if ((invocation.getArgumentAt(0, String.class)).contains("Error on syslog socket")) { + if (((String) invocation.getArgument(0)).contains("Error on syslog socket")) { sawLog.countDown(); } invocation.callRealMethod(); diff --git a/spring-integration-syslog/src/test/resources/log4j.properties b/spring-integration-syslog/src/test/resources/log4j.properties new file mode 100644 index 0000000000..7eadf67086 --- /dev/null +++ b/spring-integration-syslog/src/test/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootCategory=WARN, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n + +log4j.category.org.springframework.integration=WARN +log4j.category.org.springframework.integration.syslog=WARN diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/MockitoMessageMatchers.java b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/MockitoMessageMatchers.java index 8e4c48e033..da832ddbba 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/MockitoMessageMatchers.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/MockitoMessageMatchers.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,14 +16,16 @@ package org.springframework.integration.test.matcher; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader; import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload; import java.util.Map; import org.hamcrest.Matcher; +import org.mockito.ArgumentMatcher; import org.mockito.Mockito; +import org.mockito.internal.hamcrest.HamcrestArgumentMatcher; import org.springframework.messaging.Message; @@ -33,7 +35,7 @@ import org.springframework.messaging.Message; * This class contains expressive factory methods for the most common Mockito * matchers needed when matching {@link Message}s. If you need a different * matching strategy, any Hamcrest matcher can be used in Mockito through - * {@link Mockito#argThat(Matcher)}. + * {@link Mockito#argThat(ArgumentMatcher)}. * * Example usage: *

@@ -64,6 +66,7 @@ import org.springframework.messaging.Message; * * @author Alex Peters * @author Iwein Fuld + * @author Artem Bilan * */ public class MockitoMessageMatchers { @@ -74,28 +77,28 @@ public class MockitoMessageMatchers { @SuppressWarnings("unchecked") public static Message messageWithPayload(Matcher payloadMatcher) { - return argThat(hasPayload(payloadMatcher)); + return argThat(new HamcrestArgumentMatcher<>(hasPayload(payloadMatcher))); } @SuppressWarnings("unchecked") public static Message messageWithPayload(T payload) { - return argThat(hasPayload(payload)); + return argThat(new HamcrestArgumentMatcher<>(hasPayload(payload))); } public static Message messageWithHeaderEntry(String key, Object value) { - return argThat(hasHeader(key, value)); + return argThat(new HamcrestArgumentMatcher<>(hasHeader(key, value))); } public static Message messageWithHeaderKey(String key) { - return argThat(HeaderMatcher.hasHeaderKey(key)); + return argThat(new HamcrestArgumentMatcher<>(HeaderMatcher.hasHeaderKey(key))); } - public static Message messageWithHeaderEntry(String key, - Matcher valueMatcher) { - return argThat(HeaderMatcher.hasHeader(key, valueMatcher)); + public static Message messageWithHeaderEntry(String key, Matcher valueMatcher) { + return argThat(new HamcrestArgumentMatcher<>(HeaderMatcher.hasHeader(key, valueMatcher))); } public static Message messageWithHeaderEntries(Map entries) { - return argThat(HeaderMatcher.hasAllHeaders(entries)); + return argThat(new HamcrestArgumentMatcher<>(HeaderMatcher.hasAllHeaders(entries))); } + } diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java index dc18ef7a56..d91f0ddd85 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java +++ b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.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. @@ -32,7 +32,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -45,7 +45,7 @@ import org.springframework.messaging.support.MessageBuilder; * @author Gunnar Hillert * */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.Silent.class) public class MockitoMessageMatchersTests { static final Date SOME_PAYLOAD = new Date(); diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java index 2d479a7a3c..4e687dd45f 100644 --- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java +++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-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.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.given; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -109,8 +109,8 @@ public class SearchReceivingMessageSourceWithRedisTests extends RedisAvailableTe this.twitterSearchAdapter.start(); assertNotNull(this.tweets.receive(10000)); - assertNotNull(this.tweets.receive(1000)); - assertNotNull(this.tweets.receive(1000)); + assertNotNull(this.tweets.receive(10000)); + assertNotNull(this.tweets.receive(10000)); /* We received 3 messages so far. When invoking receive() again the search * will return again the 3 test Tweets but as we already processed them @@ -129,8 +129,8 @@ public class SearchReceivingMessageSourceWithRedisTests extends RedisAvailableTe this.twitterSearchAdapter.start(); - assertNotNull(this.tweets.receive(1000)); - assertNotNull(this.tweets.receive(1000)); + assertNotNull(this.tweets.receive(10000)); + assertNotNull(this.tweets.receive(10000)); assertNull(this.tweets.receive(0)); diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/TwitterSearchOutboundGatewayTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/TwitterSearchOutboundGatewayTests.java index 0bdd9fc886..64af482d0e 100644 --- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/TwitterSearchOutboundGatewayTests.java +++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/TwitterSearchOutboundGatewayTests.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. @@ -19,6 +19,7 @@ package org.springframework.integration.twitter.outbound; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,7 +30,6 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -79,11 +79,11 @@ public class TwitterSearchOutboundGatewayTests { SearchMetadata searchMetadata = mock(SearchMetadata.class); final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertEquals("foo", searchParameters.getQuery()); assertEquals(Integer.valueOf(20), searchParameters.getCount()); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage("foo")); Message reply = this.outputChannel.receive(0); assertNotNull(reply); @@ -102,11 +102,11 @@ public class TwitterSearchOutboundGatewayTests { SearchMetadata searchMetadata = mock(SearchMetadata.class); final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertEquals("foo", searchParameters.getQuery()); assertEquals(Integer.valueOf(30), searchParameters.getCount()); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage("foo")); Message reply = this.outputChannel.receive(0); assertNotNull(reply); @@ -125,13 +125,13 @@ public class TwitterSearchOutboundGatewayTests { SearchMetadata searchMetadata = mock(SearchMetadata.class); final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertEquals("bar", searchParameters.getQuery()); assertEquals(Integer.valueOf(1), searchParameters.getCount()); assertEquals(Long.valueOf(2), searchParameters.getSinceId()); assertEquals(Long.valueOf(3), searchParameters.getMaxId()); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage("foo")); Message reply = this.outputChannel.receive(0); assertNotNull(reply); @@ -149,10 +149,10 @@ public class TwitterSearchOutboundGatewayTests { final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata); final SearchParameters parameters = new SearchParameters("bar"); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertSame(parameters, searchParameters); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage(parameters)); Message reply = this.outputChannel.receive(0); assertNotNull(reply); @@ -171,12 +171,12 @@ public class TwitterSearchOutboundGatewayTests { SearchMetadata searchMetadata = mock(SearchMetadata.class); final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertEquals("foobar", searchParameters.getQuery()); assertEquals(Integer.valueOf(5), searchParameters.getCount()); assertEquals(Long.valueOf(11), searchParameters.getSinceId()); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage("bar")); Message reply = this.outputChannel.receive(0); assertNotNull(reply); @@ -193,11 +193,11 @@ public class TwitterSearchOutboundGatewayTests { List empty = new ArrayList(0); final SearchResults searchResults = new SearchResults(empty, searchMetadata); doAnswer(invocation -> { - SearchParameters searchParameters = invocation.getArgumentAt(0, SearchParameters.class); + SearchParameters searchParameters = invocation.getArgument(0); assertEquals("foo", searchParameters.getQuery()); assertEquals(Integer.valueOf(20), searchParameters.getCount()); return searchResults; - }).when(this.searchOps).search(Matchers.any(SearchParameters.class)); + }).when(this.searchOps).search(any(SearchParameters.class)); this.gateway.handleMessage(new GenericMessage("foo")); Message reply = this.outputChannel.receive(0); assertNotNull(reply); diff --git a/spring-integration-twitter/src/test/java/log4j.properties b/spring-integration-twitter/src/test/resources/log4j.properties similarity index 100% rename from spring-integration-twitter/src/test/java/log4j.properties rename to spring-integration-twitter/src/test/resources/log4j.properties diff --git a/spring-integration-twitter/src/test/java/twitter.receiver.properties b/spring-integration-twitter/src/test/resources/twitter.receiver.properties similarity index 100% rename from spring-integration-twitter/src/test/java/twitter.receiver.properties rename to spring-integration-twitter/src/test/resources/twitter.receiver.properties diff --git a/spring-integration-twitter/src/test/java/twitter.sender.properties b/spring-integration-twitter/src/test/resources/twitter.sender.properties similarity index 100% rename from spring-integration-twitter/src/test/java/twitter.sender.properties rename to spring-integration-twitter/src/test/resources/twitter.sender.properties diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceInboundGatewayTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceInboundGatewayTests.java index 4930eb82b1..e84f806933 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceInboundGatewayTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceInboundGatewayTests.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,10 +17,10 @@ package org.springframework.integration.ws; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -39,7 +39,8 @@ 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.internal.hamcrest.HamcrestArgumentMatcher; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.BeanFactory; @@ -114,7 +115,7 @@ public class SimpleWebServiceInboundGatewayTests { private Message messageWithPayload(final Object payload) { - return argThat(new BaseMatcher>() { + return argThat(new HamcrestArgumentMatcher<>(new BaseMatcher>() { @Override public boolean matches(Object candidate) { @@ -126,7 +127,7 @@ public class SimpleWebServiceInboundGatewayTests { description.appendText("A message with payload: " + payload); } - }); + })); } private Answer withReplyTo(final MessageChannel replyChannel) { diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java index fc0bc4fd4c..5236805c1d 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.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. @@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals; 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.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java index f786a7f081..c9bbf3dd12 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.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. @@ -114,9 +114,9 @@ public class UriVariableTests { public void testHttpUriVariables() { WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(this.httpOutboundGateway, "webServiceTemplate", WebServiceTemplate.class); webServiceTemplate = Mockito.spy(webServiceTemplate); - final AtomicReference uri = new AtomicReference(); + final AtomicReference uri = new AtomicReference<>(); doAnswer(invocation -> { - uri.set(invocation.getArgumentAt(0, String.class)); + uri.set(invocation.getArgument(0)); throw new WebServiceIOException("intentional"); }).when(webServiceTemplate) .sendAndReceive(Mockito.anyString(), diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java index ad681fd23e..740dda9518 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.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,16 +20,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import org.junit.Assert; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; @@ -445,7 +445,7 @@ public class WebServiceOutboundGatewayParserTests { doReturn(null).when(webServiceTemplate).sendAndReceive(anyString(), any(WebServiceMessageCallback.class), - Matchers.>any()); + ArgumentMatchers.>any()); new DirectFieldAccessor(handler).setPropertyValue("webServiceTemplate", webServiceTemplate); @@ -453,7 +453,7 @@ public class WebServiceOutboundGatewayParserTests { verify(webServiceTemplate).sendAndReceive(eq("jms:wsQueue"), any(WebServiceMessageCallback.class), - Matchers.>any()); + ArgumentMatchers.>any()); context.close(); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java index 3a61e565c5..bebde8a047 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -59,7 +59,7 @@ public class XmppHeaderEnricherParserTests { MessagingTemplate messagingTemplate = new MessagingTemplate(); MessageHandler handler = mock(MessageHandler.class); doAnswer(invocation -> { - Message message = invocation.getArgumentAt(0, Message.class); + Message message = invocation.getArgument(0); String chatToUser = (String) message.getHeaders().get(XmppHeaders.TO); assertNotNull(chatToUser); assertEquals("test1@example.org", chatToUser); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java index 2ad0acf3d0..9ae350f0f1 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java @@ -21,9 +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.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -37,7 +39,6 @@ import org.apache.commons.logging.Log; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smack.util.PacketParserUtils; @@ -74,21 +75,21 @@ public class ChatMessageListeningEndpointTests { * Should add/remove StanzaListener when endpoint started/stopped */ public void testLifecycle() { - final Set packetListSet = new HashSet(); + final Set packetListSet = new HashSet<>(); XMPPConnection connection = mock(XMPPConnection.class); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(connection); willAnswer(invocation -> { - packetListSet.add(invocation.getArgumentAt(0, StanzaListener.class)); + packetListSet.add(invocation.getArgument(0)); return null; }).given(connection) - .addAsyncStanzaListener(Mockito.any(StanzaListener.class), Mockito.any(StanzaFilter.class)); + .addAsyncStanzaListener(any(StanzaListener.class), isNull()); willAnswer(invocation -> { - packetListSet.remove(invocation.getArguments()[0]); + packetListSet.remove((StanzaListener) invocation.getArgument(0)); return null; }).given(connection) - .removeAsyncStanzaListener(Mockito.any(StanzaListener.class)); + .removeAsyncStanzaListener(any(StanzaListener.class)); assertEquals(0, packetListSet.size()); endpoint.setOutputChannel(new QueueChannel()); @@ -263,6 +264,4 @@ public class ChatMessageListeningEndpointTests { } - - } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java index b4a4a20030..238c3217de 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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,7 +19,7 @@ package org.springframework.integration.xmpp.inbound; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -64,12 +64,12 @@ public class PresenceListeningEndpointTests { instances.put(connection, roster); doAnswer(invocation -> { - rosterSet.add(invocation.getArgumentAt(0, RosterListener.class)); + rosterSet.add(invocation.getArgument(0)); return null; }).when(roster).addRosterListener(any(RosterListener.class)); doAnswer(invocation -> { - rosterSet.remove(invocation.getArgumentAt(0, RosterListener.class)); + rosterSet.remove((RosterListener) invocation.getArgument(0)); return null; }).when(roster).removeRosterListener(any(RosterListener.class)); PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(connection); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java index 4a1c0c6b50..d964a355d8 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,7 +19,7 @@ package org.springframework.integration.xmpp.outbound; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; @@ -31,7 +31,6 @@ import org.jivesoftware.smackx.gcm.packet.GcmPacketExtension; import org.jivesoftware.smackx.gcm.provider.GcmExtensionProvider; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.springframework.beans.factory.BeanFactory; @@ -64,18 +63,12 @@ public class ChatMessageSendingMessageHandlerTests { // first Message new handler.handleMessage(message); - class EqualSmackMessage extends ArgumentMatcher { - - @Override - public boolean matches(Object msg) { - org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg; - boolean bodyMatches = smackMessage.getBody().equals("Test Message"); - boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); - return bodyMatches & toMatches; - } - } - - verify(connection, times(1)).sendStanza(Mockito.argThat(new EqualSmackMessage())); + verify(connection, times(1)) + .sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> { + boolean bodyMatches = smackMessage.getBody().equals("Test Message"); + boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); + return bodyMatches & toMatches; + })); // assuming we know thread ID although currently we do not provide this capability message = MessageBuilder.withPayload("Hello Kitty"). @@ -83,22 +76,17 @@ public class ChatMessageSendingMessageHandlerTests { setHeader(XmppHeaders.THREAD, "123"). build(); - class EqualSmackMessageWithThreadId extends ArgumentMatcher { - - @Override - public boolean matches(Object msg) { - org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg; - boolean bodyMatches = smackMessage.getBody().equals("Hello Kitty"); - boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); - boolean threadIdMatches = smackMessage.getThread().equals("123"); - return bodyMatches & toMatches & threadIdMatches; - } - } reset(connection); handler.handleMessage(message); // in threaded conversation we need to look for existing chat - verify(connection, times(1)).sendStanza(Mockito.argThat(new EqualSmackMessageWithThreadId())); + verify(connection, times(1)) + .sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> { + boolean bodyMatches = smackMessage.getBody().equals("Hello Kitty"); + boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); + boolean threadIdMatches = smackMessage.getThread().equals("123"); + return bodyMatches & toMatches & threadIdMatches; + })); reset(connection); final String json = "{\"foo\": \"bar\"}"; @@ -107,20 +95,14 @@ public class ChatMessageSendingMessageHandlerTests { .build(); handler.handleMessage(message); - class EqualExtension extends ArgumentMatcher { - - @Override - public boolean matches(Object msg) { - org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg; - boolean bodyMatches = smackMessage.getBody() == null; - boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); - GcmPacketExtension gcmPacketExtension = GcmPacketExtension.from(smackMessage); - boolean jsonMatches = gcmPacketExtension != null && gcmPacketExtension.getJson().equals(json); - return bodyMatches & toMatches & jsonMatches; - } - } - - verify(connection, times(1)).sendStanza(Mockito.argThat(new EqualExtension())); + verify(connection, times(1)) + .sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> { + boolean bodyMatches = smackMessage.getBody() == null; + boolean toMatches = smackMessage.getTo().equals("kermit@frog.com"); + GcmPacketExtension gcmPacketExtension = GcmPacketExtension.from(smackMessage); + boolean jsonMatches = gcmPacketExtension != null && gcmPacketExtension.getJson().equals(json); + return bodyMatches & toMatches & jsonMatches; + })); } @Test diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 33fec01af6..543ba4dfcf 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -83,7 +83,7 @@ org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, - org.mockito.Matchers.*, + org.mockito.ArgumentMatchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*,