INT-2916 - Upgrade to JUnit 4.11 in support of JDK7

For reference see: https://jira.springsource.org/browse/INT-2916

Changes:

* INT-2919 - Upgrade Spring Data Gemfire to 1.2.2.RELEASE
* Exclude Hamcrest transitive dependency from JUnit (as already explicitly declared)
* Set sourceCompatibility in build.gradle to 1.6
* Set targetCompatibility in build.gradle to 1.6
* Upgrade Hamcrest to 1.3 and fix deprications
  - Corematcher is(*class) change to is(instanceOf(*class))
  - Change org.junit.internal.matchers.TypeSafeMatcher to org.hamcrest.TypeSafeMatcher
  - Change import org.junit.matchers.JUnitMatchers.containsString to org.hamcrest.CoreMatchers.containsString
  - Change import org.junit.matchers.JUnitMatchers.both to org.hamcrest.CoreMatchers.both
  - Change import org.junit.matchers.JUnitMatchers.containsString to org.hamcrest.CoreMatchers.containsString
* Fix JUnit deprecations
  - changed junit.framework.Assert to org.junit.Assert
* Add few missing licenses headers to tests
* Marked several test classes with: @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
  - SplitterIntegrationTests
  - GatewayInvokingMessageHandlerTests
  - FileToChannelIntegrationTests
  - FileInboundChannelAdapterWithRecursiveDirectoryTests
  - JdbcMessageStoreChannelTests
  - ChatMessageInboundChannelAdapterParserTests
* 3 Tests ignored (Still needs to be addressed):
  - testOperationOnPrototypeBean
  - testFailOperationWithCustomScope
  - testOperationOfControlBus
* Update SQL script (test-failure):
  - spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/outboundSchema.sql
  - add drop table statements
  - add ignore-failures="DROPS" to "jdbcOutboundChannelAdapterCommonConfig.xml"

INT-2916 - Code Review Changes

INT-2916 - Fix ignored Tests

Fix 3 previously ignored tests in *GroovyControlBusTests*:

* testOperationOnPrototypeBean
* testFailOperationWithCustomScope
* testOperationOfControlBus

INT-2916 - CI Build Testing

INT-2963 - Remove JDK7 Compilation Warnings

* Upgrade Mockito to 1.9.5
* Fix failing SubscribableJmsChannelTests

INT-2916 - Standardize Hamcrest assertions
Ensure Hamcrest assertions are standardized to: is(instanceOf(...))
This commit is contained in:
Gunnar Hillert
2013-02-06 15:51:58 -05:00
committed by Gary Russell
parent 3c98b371fa
commit 0271acaf4c
183 changed files with 1730 additions and 1482 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.xmpp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import java.lang.reflect.Field;
@@ -37,6 +37,8 @@ import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpoint;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ReflectionUtils;
@@ -44,9 +46,11 @@ import org.springframework.util.ReflectionUtils;
/**
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class ChatMessageInboundChannelAdapterParserTests {
@Autowired
@@ -72,7 +76,7 @@ public class ChatMessageInboundChannelAdapterParserTests {
XMPPConnection connection = (XMPPConnection)TestUtils.getPropertyValue(adapter, "xmppConnection");
assertEquals(connection, context.getBean("testConnection"));
}
@Test
public void testInboundAdapterUsageWithHeaderMapper() {
XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class);
@@ -80,15 +84,15 @@ public class ChatMessageInboundChannelAdapterParserTests {
Mockito.when(xmppConnection.getChatManager()).thenReturn(chatManager);
Chat chat = Mockito.mock(Chat.class);
Mockito.when(chatManager.getThreadChat(Mockito.any(String.class))).thenReturn(chat);
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
Field xmppConnectionField = ReflectionUtils.findField(ChatMessageListeningEndpoint.class, "xmppConnection");
xmppConnectionField.setAccessible(true);
ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection);
PacketListener packetListener = TestUtils.getPropertyValue(adapter, "packetListener", PacketListener.class);
Message message = new Message();
message.setBody("hello");
message.setTo("oleg");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.xmpp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -52,6 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Artem Bilan
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.xmpp.config;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.util.Set;
@@ -42,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gary Russell
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.xmpp.config;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import org.jivesoftware.smack.ConnectionConfiguration;
@@ -27,6 +27,7 @@ import org.springframework.integration.xmpp.config.XmppConnectionFactoryBean;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class XmppConnectionFactoryBeanTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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,9 +16,9 @@
package org.springframework.integration.xmpp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import java.util.List;
@@ -33,6 +33,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
*/
public class XmppConnectionParserTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.xmpp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Josh Long
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,8 +15,8 @@
*/
package org.springframework.integration.xmpp.inbound;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,11 +47,12 @@ import org.springframework.integration.xmpp.core.XmppContextUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class ChatMessageListeningEndpointTests {
@Test
/**
* Should add/remove PacketListener when endpoint started/stopped
@@ -74,7 +75,7 @@ public class ChatMessageListeningEndpointTests {
return null;
}
}).when(connection).removePacketListener(Mockito.any(PacketListener.class));
assertEquals(0, packetListSet.size());
endpoint.setOutputChannel(new QueueChannel());
endpoint.afterPropertiesSet();
@@ -83,13 +84,13 @@ public class ChatMessageListeningEndpointTests {
endpoint.stop();
assertEquals(0, packetListSet.size());
}
@Test(expected=IllegalArgumentException.class)
public void testNonInitializationFailure(){
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(mock(XMPPConnection.class));
endpoint.start();
}
@Test
public void testWithImplicitXmppConnection(){
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
@@ -100,28 +101,28 @@ public class ChatMessageListeningEndpointTests {
endpoint.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
}
@Test(expected=IllegalArgumentException.class)
public void testNoXmppConnection(){
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
endpoint.afterPropertiesSet();
}
@Test
public void testWithErrorChannel(){
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XMPPConnection connection = mock(XMPPConnection.class);
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
ChatManager cm = mock(ChatManager.class);
when(connection.getChatManager()).thenReturn(cm);
Chat chat = mock(Chat.class);
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(new MessageHandler() {
outChannel.subscribe(new MessageHandler() {
public void handleMessage(org.springframework.integration.Message<?> message)
throws MessagingException {
throw new RuntimeException("ooops");
@@ -137,8 +138,8 @@ public class ChatMessageListeningEndpointTests {
smackMessage.setBody("hello");
smackMessage.setThread("1234");
listener.processPacket(smackMessage);
ErrorMessage msg =
ErrorMessage msg =
(ErrorMessage) errorChannel.receive();
assertEquals("hello", ((MessagingException)msg.getPayload()).getFailedMessage().getPayload());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.xmpp.inbound;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,6 +51,7 @@ import org.springframework.integration.xmpp.core.XmppContextUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class PresenceListeningEndpointTests {
@@ -83,13 +84,13 @@ public class PresenceListeningEndpointTests {
rosterEndpoint.stop();
assertEquals(0, rosterSet.size());
}
@Test(expected=IllegalArgumentException.class)
public void testNonInitializedFailure() {
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(mock(XMPPConnection.class));
rosterEndpoint.start();
}
@Test
public void testRosterPresenceChangeEvent() {
XMPPConnection connection = mock(XMPPConnection.class);
@@ -117,7 +118,7 @@ public class PresenceListeningEndpointTests {
endpoint.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
}
@Test(expected=IllegalArgumentException.class)
public void testNoXmppConnection() {
PresenceListeningEndpoint handler = new PresenceListeningEndpoint();
@@ -129,16 +130,16 @@ public class PresenceListeningEndpointTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XMPPConnection connection = mock(XMPPConnection.class);
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
ChatManager cm = mock(ChatManager.class);
when(connection.getChatManager()).thenReturn(cm);
Chat chat = mock(Chat.class);
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
PresenceListeningEndpoint endpoint = new PresenceListeningEndpoint();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(new MessageHandler() {
outChannel.subscribe(new MessageHandler() {
public void handleMessage(org.springframework.integration.Message<?> message)
throws MessagingException {
throw new RuntimeException("ooops");
@@ -151,10 +152,10 @@ public class PresenceListeningEndpointTests {
endpoint.afterPropertiesSet();
RosterListener listener = (RosterListener) TestUtils.getPropertyValue(endpoint, "rosterListener");
Presence presence = new Presence(Type.available);
listener.presenceChanged(presence);
ErrorMessage msg =
ErrorMessage msg =
(ErrorMessage) errorChannel.receive();
assertEquals(Type.available.toString(), ((MessagingException)msg.getPayload()).getFailedMessage().getPayload().toString());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.xmpp.outbound;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
@@ -38,10 +38,11 @@ import org.springframework.integration.xmpp.core.XmppContextUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class ChatMessageSendingMessageHandlerTests {
@Test
public void validateMessagePostAsString() throws Exception{
@@ -51,79 +52,79 @@ public class ChatMessageSendingMessageHandlerTests {
Message<?> message = MessageBuilder.withPayload("Test Message").
setHeader(XmppHeaders.TO, "kermit@frog.com").
build();
// first Message new
// first Message new
handler.handleMessage(message);
class EqualSmackMessage extends ArgumentMatcher<org.jivesoftware.smack.packet.Message> {
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;
return bodyMatches & toMatches;
}
}
verify(connection, times(1)).sendPacket(Mockito.argThat(new EqualSmackMessage()));
// assuming we know thread ID although currently we do not provide this capability
message = MessageBuilder.withPayload("Hello Kitty").
setHeader(XmppHeaders.TO, "kermit@frog.com").
setHeader(XmppHeaders.THREAD, "123").
build();
class EqualSmackMessageWithThreadId extends ArgumentMatcher<org.jivesoftware.smack.packet.Message> {
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;
return bodyMatches & toMatches & threadIdMatches;
}
}
reset(connection);
handler.handleMessage(message);
// in threaded conversation we need to look for existing chat
verify(connection, times(1)).sendPacket(Mockito.argThat(new EqualSmackMessageWithThreadId()));
}
@Test
public void validateMessagePostAsSmackMessage() throws Exception{
XMPPConnection connection = mock(XMPPConnection.class);
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(connection);
handler.afterPropertiesSet();
org.jivesoftware.smack.packet.Message smackMessage = new org.jivesoftware.smack.packet.Message("kermit@frog.com");
smackMessage.setBody("Test Message");
Message<?> message = MessageBuilder.withPayload(smackMessage).build();
// first Message new
// first Message new
handler.handleMessage(message);
verify(connection, times(1)).sendPacket(smackMessage);
// assuming we know thread ID although currently we do not provide this capability
smackMessage = new org.jivesoftware.smack.packet.Message("kermit@frog.com");
smackMessage.setBody("Hello Kitty");
smackMessage.setThread("123");
message = MessageBuilder.withPayload(smackMessage).build();
reset(connection);
handler.handleMessage(message);
// in threaded conversation we need to look for existing chat
verify(connection, times(1)).sendPacket(smackMessage);
}
@Test(expected=MessageHandlingException.class)
public void validateFailureNoChatToUser() throws Exception{
public void validateFailureNoChatToUser() throws Exception{
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class));
handler.handleMessage(new GenericMessage<String>("hello"));
}
@Test(expected=MessageHandlingException.class)
public void validateMessageWithUnsupportedPayload() throws Exception{
public void validateMessageWithUnsupportedPayload() throws Exception{
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class));
handler.handleMessage(new GenericMessage<Integer>(123));
}
@@ -136,7 +137,7 @@ public class ChatMessageSendingMessageHandlerTests {
handler.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
}
@Test(expected=IllegalArgumentException.class)
public void testNoXmppConnection(){
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.xmpp.outbound;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import org.jivesoftware.smack.XMPPConnection;
@@ -31,10 +31,11 @@ import org.springframework.integration.xmpp.outbound.PresenceSendingMessageHandl
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class PresenceSendingMessageHandlerTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testPresencePayload(){
@@ -42,7 +43,7 @@ public class PresenceSendingMessageHandlerTests {
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage(mock(Presence.class)));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(expected=MessageHandlingException.class)
public void testWrongPayload(){
@@ -50,7 +51,7 @@ public class PresenceSendingMessageHandlerTests {
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage(new Object()));
}
@Test
public void testWithImplicitXmppConnection(){
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
@@ -60,7 +61,7 @@ public class PresenceSendingMessageHandlerTests {
handler.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
}
@Test(expected=IllegalArgumentException.class)
public void testNoXmppConnection(){
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler();