INT-4206: Upgrade to Mockito 2.5

JIRA: https://jira.spring.io/browse/INT-4206

* Fix unnecessary dependency resolution in BOM module
* Fix `MessagingMethodInvokerHelper` to handle `$MockitoMock$` generated classed which isn't CGLib `Proxies` any more
* Provide fixes for test classes according upgrade to Mockito `2.5`
* Fix Ceckstyle do not allow static imports for deprecated Mockito classes
This commit is contained in:
Artem Bilan
2017-01-09 17:39:47 -05:00
committed by Gary Russell
parent e04a8d9948
commit 54654546b9
77 changed files with 392 additions and 413 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 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);

View File

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

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.integration.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);

View File

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