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:
committed by
Gary Russell
parent
e04a8d9948
commit
54654546b9
@@ -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'
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -578,7 +578,8 @@ public class MessagingMethodInvokerHelper<T> 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<String> logs = new ArrayList<String>();
|
||||
final List<String> 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 -> {
|
||||
|
||||
@@ -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<Message<?>> 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<Message<?>> messages = new LinkedBlockingQueue<>();
|
||||
|
||||
willAnswer(i -> {
|
||||
messages.put(i.getArgumentAt(0, Message.class));
|
||||
messages.put(i.getArgument(0));
|
||||
return null;
|
||||
})
|
||||
.given(testSubscriber)
|
||||
|
||||
@@ -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<String> log = new AtomicReference<String>();
|
||||
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());
|
||||
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -897,7 +897,7 @@ public class AdvisedMessageHandlerTests {
|
||||
when(logger.isWarnEnabled()).thenReturn(Boolean.TRUE);
|
||||
final AtomicReference<String> logMessage = new AtomicReference<String>();
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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});
|
||||
|
||||
@@ -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<String> madeDirs = new ArrayList<String>();
|
||||
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<String> written = new AtomicReference<String>();
|
||||
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<String> written = new AtomicReference<String>();
|
||||
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");
|
||||
|
||||
@@ -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<String> finalPath = new AtomicReference<String>();
|
||||
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<F> handler = new FileTransferringMessageHandler<F>(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> logged = new AtomicReference<String>();
|
||||
final AtomicReference<String> 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<Boolean>() {
|
||||
@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<Boolean>() {
|
||||
@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<Object> ftpFiles = new ArrayList<Object>();
|
||||
Collection<FTPFile> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
|
||||
responseHeaders.set("Connection", "close");
|
||||
responseHeaders.set("Content-Disposition", contentDispositionValue);
|
||||
return new ResponseEntity<Object>(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<Object>(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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String>("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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Void>() {
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<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);
|
||||
}
|
||||
|
||||
@@ -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<String> msg = invocation.getArgumentAt(0, Message.class);
|
||||
Message<String> msg = invocation.getArgument(0);
|
||||
MessageHistory history = MessageHistory.read(msg);
|
||||
assertTrue(history.get(0).contains("jmsChannel"));
|
||||
return null;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Object>() {
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<MqttCallback> callback = new AtomicReference<MqttCallback>();
|
||||
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<MqttIntegrationEvent> events = new LinkedBlockingQueue<MqttIntegrationEvent>();
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> madeDirs = new ArrayList<String>();
|
||||
doAnswer(invocation -> {
|
||||
madeDirs.add(invocation.getArgumentAt(0, String.class));
|
||||
madeDirs.add(invocation.getArgument(0));
|
||||
return null;
|
||||
}).when(session).mkdir(anyString());
|
||||
handler.handleMessage(new GenericMessage<String>("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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
@@ -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:
|
||||
* <p>
|
||||
@@ -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 <T> Message<T> messageWithPayload(Matcher<T> payloadMatcher) {
|
||||
return argThat(hasPayload(payloadMatcher));
|
||||
return argThat(new HamcrestArgumentMatcher<>(hasPayload(payloadMatcher)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Message<T> 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 <T> Message<?> messageWithHeaderEntry(String key,
|
||||
Matcher<T> valueMatcher) {
|
||||
return argThat(HeaderMatcher.<T>hasHeader(key, valueMatcher));
|
||||
public static <T> Message<?> messageWithHeaderEntry(String key, Matcher<T> valueMatcher) {
|
||||
return argThat(new HamcrestArgumentMatcher<>(HeaderMatcher.<T>hasHeader(key, valueMatcher)));
|
||||
}
|
||||
|
||||
public static Message<?> messageWithHeaderEntries(Map<String, ?> entries) {
|
||||
return argThat(HeaderMatcher.hasAllHeaders(entries));
|
||||
return argThat(new HamcrestArgumentMatcher<>(HeaderMatcher.hasAllHeaders(entries)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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<String>("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<String>("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<String>("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<SearchParameters>(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<String>("bar"));
|
||||
Message<?> reply = this.outputChannel.receive(0);
|
||||
assertNotNull(reply);
|
||||
@@ -193,11 +193,11 @@ public class TwitterSearchOutboundGatewayTests {
|
||||
List<Tweet> empty = new ArrayList<Tweet>(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<String>("foo"));
|
||||
Message<?> reply = this.outputChannel.receive(0);
|
||||
assertNotNull(reply);
|
||||
|
||||
@@ -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<Message<?>>() {
|
||||
return argThat(new HamcrestArgumentMatcher<>(new BaseMatcher<Message<?>>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Object candidate) {
|
||||
@@ -126,7 +127,7 @@ public class SimpleWebServiceInboundGatewayTests {
|
||||
description.appendText("A message with payload: " + payload);
|
||||
}
|
||||
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private Answer<Boolean> withReplyTo(final MessageChannel replyChannel) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String> uri = new AtomicReference<String>();
|
||||
final AtomicReference<String> 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(),
|
||||
|
||||
@@ -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.<WebServiceMessageExtractor<Object>>any());
|
||||
ArgumentMatchers.<WebServiceMessageExtractor<Object>>any());
|
||||
|
||||
new DirectFieldAccessor(handler).setPropertyValue("webServiceTemplate", webServiceTemplate);
|
||||
|
||||
@@ -453,7 +453,7 @@ public class WebServiceOutboundGatewayParserTests {
|
||||
|
||||
verify(webServiceTemplate).sendAndReceive(eq("jms:wsQueue"),
|
||||
any(WebServiceMessageCallback.class),
|
||||
Matchers.<WebServiceMessageExtractor<Object>>any());
|
||||
ArgumentMatchers.<WebServiceMessageExtractor<Object>>any());
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<StanzaListener> packetListSet = new HashSet<StanzaListener>();
|
||||
final Set<StanzaListener> 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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<org.jivesoftware.smack.packet.Message> {
|
||||
|
||||
@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<org.jivesoftware.smack.packet.Message> {
|
||||
|
||||
@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<org.jivesoftware.smack.packet.Message> {
|
||||
|
||||
@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
|
||||
|
||||
@@ -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.*,
|
||||
|
||||
Reference in New Issue
Block a user