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
This commit is contained in:
Artem Bilan
2017-01-09 17:39:47 -05:00
committed by Gary Russell
parent e04a8d9948
commit 54654546b9
77 changed files with 392 additions and 413 deletions

View File

@@ -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;

View File

@@ -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<String> logList = new ArrayList<String>();
doAnswer(invocation -> {
String message = invocation.getArgumentAt(0, String.class);
String message = invocation.getArgument(0);
if (message.startsWith("Dispatcher has no subscribers")) {
logList.add(message);
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<String, Object> 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());

View File

@@ -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");

View File

@@ -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<Message> 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<Message> amqpMessage =
new AtomicReference<Message>();
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<Message> amqpMessage =
new AtomicReference<Message>();
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())