Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Field;
import java.util.Map;
@@ -75,20 +73,20 @@ public class ChatMessageInboundChannelAdapterParserTests {
public void testInboundAdapter() {
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
MessageChannel errorChannel = (MessageChannel) TestUtils.getPropertyValue(adapter, "errorChannel");
assertEquals(context.getBean("errorChannel"), errorChannel);
assertFalse(adapter.isAutoStartup());
assertThat(errorChannel).isEqualTo(context.getBean("errorChannel"));
assertThat(adapter.isAutoStartup()).isFalse();
QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(adapter, "outputChannel");
assertEquals("xmppInbound", channel.getComponentName());
assertThat(channel.getComponentName()).isEqualTo("xmppInbound");
XMPPConnection connection = (XMPPConnection) TestUtils.getPropertyValue(adapter, "xmppConnection");
assertSame(connection, context.getBean("testConnection"));
assertThat(context.getBean("testConnection")).isSameAs(connection);
Object stanzaFilter = context.getBean("stanzaFilter");
assertSame(stanzaFilter, TestUtils.getPropertyValue(adapter, "stanzaFilter"));
assertEquals("#root", TestUtils.getPropertyValue(adapter, "payloadExpression.expression"));
assertThat(TestUtils.getPropertyValue(adapter, "stanzaFilter")).isSameAs(stanzaFilter);
assertThat(TestUtils.getPropertyValue(adapter, "payloadExpression.expression")).isEqualTo("#root");
adapter.start();
Map asyncRecvListeners = TestUtils.getPropertyValue(connection, "asyncRecvListeners", Map.class);
assertEquals(6, asyncRecvListeners.size());
assertThat(asyncRecvListeners.size()).isEqualTo(6);
Object lastListener = asyncRecvListeners.values().stream().reduce((first, second) -> second).get();
assertSame(stanzaFilter, TestUtils.getPropertyValue(lastListener, "packetFilter"));
assertThat(TestUtils.getPropertyValue(lastListener, "packetFilter")).isSameAs(stanzaFilter);
adapter.stop();
}
@@ -111,13 +109,13 @@ public class ChatMessageInboundChannelAdapterParserTests {
JivePropertiesManager.addProperty(message, "bar", "bar");
stanzaListener.processStanza(message);
org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
assertEquals("foo", siMessage.getHeaders().get("foo"));
assertEquals("oleg", siMessage.getHeaders().get("xmpp_to"));
assertThat(siMessage.getHeaders().get("foo")).isEqualTo("foo");
assertThat(siMessage.getHeaders().get("xmpp_to")).isEqualTo("oleg");
}
@Test
public void testAutoChannel() {
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,10 +16,7 @@
package org.springframework.integration.xmpp.config;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -77,14 +74,14 @@ public class ChatMessageOutboundChannelAdapterParserTests {
public void testPollingConsumer() {
Object pollingConsumer = context.getBean("withHeaderMapper");
QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(pollingConsumer, "inputChannel");
assertEquals("outboundPollingChannel", channel.getComponentName());
assertTrue(pollingConsumer instanceof PollingConsumer);
assertThat(channel.getComponentName()).isEqualTo("outboundPollingChannel");
assertThat(pollingConsumer instanceof PollingConsumer).isTrue();
}
@Test
public void testEventConsumerWithNoChannel() {
Object eventConsumer = context.getBean("outboundNoChannelAdapter");
assertTrue(eventConsumer instanceof SubscribableChannel);
assertThat(eventConsumer instanceof SubscribableChannel).isTrue();
}
@Test
@@ -92,7 +89,7 @@ public class ChatMessageOutboundChannelAdapterParserTests {
MessageHandler handler = TestUtils.getPropertyValue(context.getBean("advised"),
"handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertThat(adviceCalled).isEqualTo(1);
}
@Test
@@ -103,26 +100,26 @@ public class ChatMessageOutboundChannelAdapterParserTests {
AbstractHeaderMapper.HeaderMatcher requestHeaderMatcher = TestUtils.getPropertyValue(headerMapper,
"requestHeaderMatcher", AbstractHeaderMapper.HeaderMatcher.class);
assertTrue(requestHeaderMatcher.matchHeader("foo"));
assertTrue(requestHeaderMatcher.matchHeader("foo123"));
assertTrue(requestHeaderMatcher.matchHeader("bar"));
assertTrue(requestHeaderMatcher.matchHeader("bar123"));
assertFalse(requestHeaderMatcher.matchHeader("biz"));
assertFalse(requestHeaderMatcher.matchHeader("else"));
assertTrue(eventConsumer instanceof EventDrivenConsumer);
assertThat(requestHeaderMatcher.matchHeader("foo")).isTrue();
assertThat(requestHeaderMatcher.matchHeader("foo123")).isTrue();
assertThat(requestHeaderMatcher.matchHeader("bar")).isTrue();
assertThat(requestHeaderMatcher.matchHeader("bar123")).isTrue();
assertThat(requestHeaderMatcher.matchHeader("biz")).isFalse();
assertThat(requestHeaderMatcher.matchHeader("else")).isFalse();
assertThat(eventConsumer instanceof EventDrivenConsumer).isTrue();
MessageHandler outboundEventAdapterHandle =
context.getBean("outboundEventAdapter.handler", MessageHandler.class);
assertSame(this.extensionElementProvider,
TestUtils.getPropertyValue(outboundEventAdapterHandle, "extensionProvider"));
assertThat(TestUtils.getPropertyValue(outboundEventAdapterHandle, "extensionProvider"))
.isSameAs(this.extensionElementProvider);
}
@SuppressWarnings("rawtypes")
@Test
public void withHeaderMapper() throws Exception {
Object pollingConsumer = context.getBean("withHeaderMapper");
assertTrue(pollingConsumer instanceof PollingConsumer);
assertEquals(headerMapper, TestUtils.getPropertyValue(pollingConsumer, "handler.headerMapper"));
assertThat(pollingConsumer instanceof PollingConsumer).isTrue();
assertThat(TestUtils.getPropertyValue(pollingConsumer, "handler.headerMapper")).isEqualTo(headerMapper);
MessageChannel channel = context.getBean("outboundEventChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload("hello").setHeader(XmppHeaders.TO, "oleg").
setHeader("foobar", "foobar").build();
@@ -131,8 +128,8 @@ public class ChatMessageOutboundChannelAdapterParserTests {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("oleg", xmppMessage.getTo().toString());
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
assertThat(xmppMessage.getTo().toString()).isEqualTo("oleg");
assertThat(JivePropertiesManager.getProperty(xmppMessage, "foobar")).isEqualTo("foobar");
return null;
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
@@ -150,8 +147,8 @@ public class ChatMessageOutboundChannelAdapterParserTests {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("artem", xmppMessage.getTo().toString());
assertEquals("hello", xmppMessage.getBody());
assertThat(xmppMessage.getTo().toString()).isEqualTo("artem");
assertThat(xmppMessage.getBody()).isEqualTo("hello");
return null;
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
@@ -57,40 +56,40 @@ public class PresenceOutboundChannelAdapterParserTests {
@Test
public void testRosterEventOutboundChannelAdapterParserAsPollingConsumer() {
Object pollingConsumer = context.getBean("pollingOutboundRosterAdapter");
assertTrue(pollingConsumer instanceof PollingConsumer);
assertThat(pollingConsumer instanceof PollingConsumer).isTrue();
AbstractXmppConnectionAwareMessageHandler handler = (AbstractXmppConnectionAwareMessageHandler) TestUtils
.getPropertyValue(pollingConsumer, "handler");
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
assertThat(TestUtils.getPropertyValue(handler, "order")).isEqualTo(23);
}
@Test
public void testRosterEventOutboundChannelAdapterParserEventConsumer() {
Object eventConsumer = context.getBean("eventOutboundRosterAdapter");
assertTrue(eventConsumer instanceof EventDrivenConsumer);
assertThat(eventConsumer instanceof EventDrivenConsumer).isTrue();
AbstractXmppConnectionAwareMessageHandler handler = (AbstractXmppConnectionAwareMessageHandler) TestUtils
.getPropertyValue(eventConsumer, "handler");
assertEquals(34, TestUtils.getPropertyValue(handler, "order"));
assertThat(TestUtils.getPropertyValue(handler, "order")).isEqualTo(34);
}
@Test
public void advised() {
Object eventConsumer = context.getBean("advised");
assertTrue(eventConsumer instanceof EventDrivenConsumer);
assertThat(eventConsumer instanceof EventDrivenConsumer).isTrue();
MessageHandler handler = TestUtils.getPropertyValue(eventConsumer, "handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertThat(adviceCalled).isEqualTo(1);
}
@Test
public void testRosterEventOutboundChannel() {
Object channel = context.getBean("eventOutboundRosterChannel");
assertTrue(channel instanceof SubscribableChannel);
assertThat(channel instanceof SubscribableChannel).isTrue();
UnicastingDispatcher dispatcher = (UnicastingDispatcher) TestUtils
.getPropertyValue(channel, "dispatcher");
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
.getPropertyValue(dispatcher, "handlers");
assertEquals(45, TestUtils.getPropertyValue(handlers.toArray()[0], "order"));
assertThat(TestUtils.getPropertyValue(handlers.toArray()[0], "order")).isEqualTo(45);
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.config;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.jivesoftware.smack.XMPPConnection;
@@ -45,7 +43,7 @@ public class XmppConnectionFactoryBeanTests {
.setXmppDomain("foo")
.build());
XMPPConnection connection = xmppConnectionFactoryBean.createInstance();
assertNotNull(connection);
assertThat(connection).isNotNull();
}
@Test
@@ -71,7 +69,7 @@ public class XmppConnectionFactoryBeanTests {
xmppConnectionFactoryBean.start();
XMPPConnection connection = xmppConnectionFactoryBean.getObject();
assertFalse(Roster.getInstanceFor(connection).isRosterLoadedAtLogin());
assertThat(Roster.getInstanceFor(connection).isRosterLoadedAtLogin()).isFalse();
}
@Test
@@ -91,7 +89,7 @@ public class XmppConnectionFactoryBeanTests {
xmppConnectionFactoryBean.start();
XMPPConnection connection = xmppConnectionFactoryBean.getObject();
assertTrue(Roster.getInstanceFor(connection).isRosterLoadedAtLogin());
assertThat(Roster.getInstanceFor(connection).isRosterLoadedAtLogin()).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.jivesoftware.smack.XMPPConnection;
import org.junit.Test;
@@ -41,17 +39,17 @@ public class XmppConnectionParserTests {
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
assertEquals("my.domain", connection.getXMPPServiceDomain().toString());
assertFalse(connection.isConnected());
assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("my.domain");
assertThat(connection.isConnected()).isFalse();
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
assertEquals("happy.user@my.domain", TestUtils.getPropertyValue(xmppFb, "user"));
assertEquals("blah", TestUtils.getPropertyValue(xmppFb, "password"));
assertNull(TestUtils.getPropertyValue(xmppFb, "resource"));
assertEquals("accept_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString());
assertThat(TestUtils.getPropertyValue(xmppFb, "user")).isEqualTo("happy.user@my.domain");
assertThat(TestUtils.getPropertyValue(xmppFb, "password")).isEqualTo("blah");
assertThat(TestUtils.getPropertyValue(xmppFb, "resource")).isNull();
assertThat(TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString()).isEqualTo("accept_all");
xmppFb = ac.getBean("&connectionWithResource", XmppConnectionFactoryBean.class);
assertEquals("Smack", TestUtils.getPropertyValue(xmppFb, "resource"));
assertNull(TestUtils.getPropertyValue(xmppFb, "subscriptionMode"));
assertThat(TestUtils.getPropertyValue(xmppFb, "resource")).isEqualTo("Smack");
assertThat(TestUtils.getPropertyValue(xmppFb, "subscriptionMode")).isNull();
ac.close();
}
@@ -60,13 +58,13 @@ public class XmppConnectionParserTests {
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
assertEquals("foogle.com", connection.getXMPPServiceDomain().toString());
assertFalse(connection.isConnected());
assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("foogle.com");
assertThat(connection.isConnected()).isFalse();
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
assertEquals("blah", TestUtils.getPropertyValue(xmppFb, "password"));
assertEquals("SpringSource", TestUtils.getPropertyValue(xmppFb, "resource"));
assertEquals("reject_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString());
assertThat(TestUtils.getPropertyValue(xmppFb, "user")).isEqualTo("happy.user");
assertThat(TestUtils.getPropertyValue(xmppFb, "password")).isEqualTo("blah");
assertThat(TestUtils.getPropertyValue(xmppFb, "resource")).isEqualTo("SpringSource");
assertThat(TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString()).isEqualTo("reject_all");
ac.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -71,8 +69,8 @@ public class XmppHeaderEnricherParserTests {
willAnswer(invocation -> {
Message<?> message = invocation.getArgument(0);
String chatToUser = (String) message.getHeaders().get(XmppHeaders.TO);
assertNotNull(chatToUser);
assertEquals("test1@example.org", chatToUser);
assertThat(chatToUser).isNotNull();
assertThat(chatToUser).isEqualTo("test1@example.org");
callLatch.countDown();
return null;
})
@@ -80,7 +78,7 @@ public class XmppHeaderEnricherParserTests {
.handleMessage(Mockito.any(Message.class));
this.output.subscribe(handler);
messagingTemplate.send(this.input, MessageBuilder.withPayload("foo").build());
assertTrue(callLatch.await(10, TimeUnit.SECONDS));
assertThat(callLatch.await(10, TimeUnit.SECONDS)).isTrue();
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,11 +16,7 @@
package org.springframework.integration.xmpp.inbound;
import static org.hamcrest.CoreMatchers.instanceOf;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
@@ -93,14 +89,14 @@ public class ChatMessageListeningEndpointTests {
}).given(connection)
.removeAsyncStanzaListener(any(StanzaListener.class));
assertEquals(0, packetListSet.size());
assertThat(packetListSet.size()).isEqualTo(0);
endpoint.setOutputChannel(new QueueChannel());
endpoint.setBeanFactory(mock(BeanFactory.class));
endpoint.afterPropertiesSet();
endpoint.start();
assertEquals(1, packetListSet.size());
assertThat(packetListSet.size()).isEqualTo(1);
endpoint.stop();
assertEquals(0, packetListSet.size());
assertThat(packetListSet.size()).isEqualTo(0);
}
@Test(expected = IllegalArgumentException.class)
@@ -117,7 +113,7 @@ public class ChatMessageListeningEndpointTests {
endpoint.setBeanFactory(bf);
endpoint.setOutputChannel(new QueueChannel());
endpoint.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection"));
assertThat(TestUtils.getPropertyValue(endpoint, "xmppConnection")).isNotNull();
}
@Test(expected = IllegalArgumentException.class)
@@ -152,7 +148,7 @@ public class ChatMessageListeningEndpointTests {
ErrorMessage msg =
(ErrorMessage) errorChannel.receive();
assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
assertThat(((MessagingException) msg.getPayload()).getFailedMessage().getPayload()).isEqualTo("hello");
}
@Test
@@ -178,12 +174,12 @@ public class ChatMessageListeningEndpointTests {
testXMPPConnection.parseAndProcessStanza(xmlPullParser);
org.springframework.messaging.Message<?> receive = inputChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
Object payload = receive.getPayload();
assertThat(payload, instanceOf(Message.class));
assertEquals(smackMessage.getStanzaId(), ((Message) payload).getStanzaId());
assertEquals(smackMessage.getBody(), ((Message) payload).getBody());
assertThat(payload).isInstanceOf(Message.class);
assertThat(((Message) payload).getStanzaId()).isEqualTo(smackMessage.getStanzaId());
assertThat(((Message) payload).getBody()).isEqualTo(smackMessage.getBody());
Log logger = Mockito.spy(TestUtils.getPropertyValue(endpoint, "logger", Log.class));
given(logger.isInfoEnabled()).willReturn(true);
@@ -205,12 +201,12 @@ public class ChatMessageListeningEndpointTests {
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
assertTrue(logLatch.await(10, TimeUnit.SECONDS));
assertThat(logLatch.await(10, TimeUnit.SECONDS)).isTrue();
verify(logger).info(argumentCaptor.capture());
assertEquals("The XMPP Message [" + smackMessage + "] with empty body is ignored.",
argumentCaptor.getValue());
assertThat(argumentCaptor.getValue())
.isEqualTo("The XMPP Message [" + smackMessage + "] with empty body is ignored.");
endpoint.stop();
}
@@ -248,9 +244,9 @@ public class ChatMessageListeningEndpointTests {
testXMPPConnection.parseAndProcessStanza(xmlPullParser);
org.springframework.messaging.Message<?> receive = inputChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
assertEquals(data, receive.getPayload());
assertThat(receive.getPayload()).isEqualTo(data);
endpoint.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Set;
@@ -62,11 +60,11 @@ public class PresenceListeningEndpointTests {
rosterEndpoint.setOutputChannel(new QueueChannel());
rosterEndpoint.setBeanFactory(mock(BeanFactory.class));
rosterEndpoint.afterPropertiesSet();
assertEquals(0, rosterSet.size());
assertThat(rosterSet.size()).isEqualTo(0);
rosterEndpoint.start();
assertEquals(1, rosterSet.size());
assertThat(rosterSet.size()).isEqualTo(1);
rosterEndpoint.stop();
assertEquals(0, rosterSet.size());
assertThat(rosterSet.size()).isEqualTo(0);
}
@Test(expected = IllegalArgumentException.class)
@@ -89,7 +87,7 @@ public class PresenceListeningEndpointTests {
Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
rosterListener.presenceChanged(presence);
Message<?> message = channel.receive(10);
assertEquals(presence, message.getPayload());
assertThat(message.getPayload()).isEqualTo(presence);
}
@Test
@@ -100,7 +98,7 @@ public class PresenceListeningEndpointTests {
endpoint.setBeanFactory(bf);
endpoint.setOutputChannel(new QueueChannel());
endpoint.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection"));
assertThat(TestUtils.getPropertyValue(endpoint, "xmppConnection")).isNotNull();
}
@Test(expected = IllegalArgumentException.class)
@@ -134,9 +132,9 @@ public class PresenceListeningEndpointTests {
ErrorMessage msg =
(ErrorMessage) errorChannel.receive();
assertSame(presence, ((MessagingException) msg.getPayload())
.getFailedMessage()
.getPayload());
assertThat(((MessagingException) msg.getPayload())
.getFailedMessage()
.getPayload()).isSameAs(presence);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,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.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -160,11 +158,11 @@ public class ChatMessageSendingMessageHandlerTests {
org.jivesoftware.smack.packet.Message smackMessage = argumentCaptor.getValue();
assertNull(smackMessage.getBody());
assertEquals("kermit@frog.com", smackMessage.getTo().toString());
assertThat(smackMessage.getBody()).isNull();
assertThat(smackMessage.getTo().toString()).isEqualTo("kermit@frog.com");
GcmPacketExtension gcmPacketExtension = GcmPacketExtension.from(smackMessage);
assertNotNull(gcmPacketExtension);
assertEquals(json, gcmPacketExtension.getJson());
assertThat(gcmPacketExtension).isNotNull();
assertThat(gcmPacketExtension.getJson()).isEqualTo(json);
verify(extensionElementProvider).from(eq(json));
}
@@ -189,7 +187,7 @@ public class ChatMessageSendingMessageHandlerTests {
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler();
handler.setBeanFactory(bf);
handler.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(handler, "xmppConnection"));
assertThat(TestUtils.getPropertyValue(handler, "xmppConnection")).isNotNull();
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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 org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.jivesoftware.smack.XMPPConnection;
@@ -62,7 +62,7 @@ public class PresenceSendingMessageHandlerTests {
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler();
handler.setBeanFactory(bf);
handler.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(handler, "xmppConnection"));
assertThat(TestUtils.getPropertyValue(handler, "xmppConnection")).isNotNull();
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 @@
package org.springframework.integration.xmpp.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -56,19 +55,19 @@ public class DefaultXmppHeaderMapperTests {
mapper.fromHeadersToRequest(headers, target);
// "standard" XMPP headers
assertEquals("test.thread", target.getThread());
assertEquals("test.to", target.getTo().toString());
assertEquals("test.from", target.getFrom().toString());
assertEquals("test.subject", target.getSubject());
assertEquals(Message.Type.headline, target.getType());
assertThat(target.getThread()).isEqualTo("test.thread");
assertThat(target.getTo().toString()).isEqualTo("test.to");
assertThat(target.getFrom().toString()).isEqualTo("test.from");
assertThat(target.getSubject()).isEqualTo("test.subject");
assertThat(target.getType()).isEqualTo(Message.Type.headline);
// user-defined headers not included by default
assertNull(JivePropertiesManager.getProperty(target, "userDefined1"));
assertNull(JivePropertiesManager.getProperty(target, "userDefined2"));
assertThat(JivePropertiesManager.getProperty(target, "userDefined1")).isNull();
assertThat(JivePropertiesManager.getProperty(target, "userDefined2")).isNull();
// transient headers should not be copied
assertNull(JivePropertiesManager.getProperty(target, "id"));
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
assertThat(JivePropertiesManager.getProperty(target, "id")).isNull();
assertThat(JivePropertiesManager.getProperty(target, "timestamp")).isNull();
}
@Test
@@ -89,22 +88,24 @@ public class DefaultXmppHeaderMapperTests {
mapper.fromHeadersToRequest(headers, target);
// "standard" XMPP headers not included
assertNull(target.getThread());
assertNull(target.getTo());
assertNull(target.getFrom());
assertNull(target.getSubject());
assertEquals(Message.Type.normal, target.getType());
assertThat(target.getThread()).isNull();
Object to = target.getTo();
assertThat(to).isNull();
Object from = target.getFrom();
assertThat(from).isNull();
assertThat(target.getSubject()).isNull();
assertThat(target.getType()).isEqualTo(Message.Type.normal);
// user-defined headers are included if in the list
assertEquals("foo", JivePropertiesManager.getProperty(target, "userDefined1"));
assertEquals("bar", JivePropertiesManager.getProperty(target, "userDefined2"));
assertThat(JivePropertiesManager.getProperty(target, "userDefined1")).isEqualTo("foo");
assertThat(JivePropertiesManager.getProperty(target, "userDefined2")).isEqualTo("bar");
// user-defined headers are not included if not in the list
assertNull(JivePropertiesManager.getProperty(target, "userDefined3"));
assertThat(JivePropertiesManager.getProperty(target, "userDefined3")).isNull();
// transient headers should not be copied
assertNull(JivePropertiesManager.getProperty(target, "id"));
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
assertThat(JivePropertiesManager.getProperty(target, "id")).isNull();
assertThat(JivePropertiesManager.getProperty(target, "timestamp")).isNull();
}
@Test
@@ -117,13 +118,13 @@ public class DefaultXmppHeaderMapperTests {
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
Map<String, Object> headers = mapper.toHeadersFromRequest(source);
assertEquals("test.to", headers.get(XmppHeaders.TO).toString());
assertEquals("test.from", headers.get(XmppHeaders.FROM).toString());
assertEquals("test.subject", headers.get(XmppHeaders.SUBJECT));
assertEquals("test.thread", headers.get(XmppHeaders.THREAD));
assertEquals(Message.Type.headline, headers.get(XmppHeaders.TYPE));
assertNull(headers.get("userDefined1"));
assertNull(headers.get("userDefined2"));
assertThat(headers.get(XmppHeaders.TO).toString()).isEqualTo("test.to");
assertThat(headers.get(XmppHeaders.FROM).toString()).isEqualTo("test.from");
assertThat(headers.get(XmppHeaders.SUBJECT)).isEqualTo("test.subject");
assertThat(headers.get(XmppHeaders.THREAD)).isEqualTo("test.thread");
assertThat(headers.get(XmppHeaders.TYPE)).isEqualTo(Message.Type.headline);
assertThat(headers.get("userDefined1")).isNull();
assertThat(headers.get("userDefined2")).isNull();
}
@Test
@@ -137,13 +138,13 @@ public class DefaultXmppHeaderMapperTests {
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
Map<String, Object> headers = mapper.toHeadersFromReply(source);
assertNull(headers.get(XmppHeaders.TO));
assertNull(headers.get(XmppHeaders.FROM));
assertNull(headers.get(XmppHeaders.SUBJECT));
assertNull(headers.get(XmppHeaders.THREAD));
assertNull(headers.get(XmppHeaders.TYPE));
assertEquals("foo", headers.get("userDefined1"));
assertEquals("bar", headers.get("userDefined2"));
assertThat(headers.get(XmppHeaders.TO)).isNull();
assertThat(headers.get(XmppHeaders.FROM)).isNull();
assertThat(headers.get(XmppHeaders.SUBJECT)).isNull();
assertThat(headers.get(XmppHeaders.THREAD)).isNull();
assertThat(headers.get(XmppHeaders.TYPE)).isNull();
assertThat(headers.get("userDefined1")).isEqualTo("foo");
assertThat(headers.get("userDefined2")).isEqualTo("bar");
}
}