From b081992910f55f069210422035dd74b9d5bd9e9e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 17 Mar 2022 11:12:36 -0400 Subject: [PATCH] Code clean up for XMPP module * Ugrade to Checkstyle `10.0` * Migrate XMPP test to JUnit `5` --- build.gradle | 2 +- .../ChatMessageSendingMessageHandler.java | 2 +- .../xmpp/support/DefaultXmppHeaderMapper.java | 7 ++---- ...ssageInboundChannelAdapterParserTests.java | 13 ++++------ ...sageOutboundChannelAdapterParserTests.java | 12 ++++------ ...senceInboundChannelAdapterParserTests.java | 13 ++++++---- ...enceOutboundChannelAdapterParserTests.java | 12 ++++------ .../XmppConnectionFactoryBeanTests.java | 14 +++++++---- .../config/XmppConnectionParserTests.java | 8 +++---- .../config/XmppHeaderEnricherParserTests.java | 11 ++++----- .../xmpp/ignore/ConsoleChatTests.java | 16 ++++++------- .../xmpp/ignore/InboundChatTests.java | 15 +++++------- .../xmpp/ignore/InboundPresenceTests.java | 16 ++++++------- .../xmpp/ignore/OutboundChatTests.java | 15 +++++------- .../xmpp/ignore/OutboundPresenceTests.java | 13 ++++------ .../xmpp/ignore/SmackMessageSampleTests.java | 6 ++--- .../xmpp/ignore/XmppMessageConsumer.java | 6 ++--- .../ChatMessageListeningEndpointTests.java | 20 ++++++++-------- .../PresenceListeningEndpointTests.java | 13 ++++++---- ...ChatMessageSendingMessageHandlerTests.java | 24 +++++++++++-------- .../PresenceSendingMessageHandlerTests.java | 15 +++++++----- .../support/DefaultXmppHeaderMapperTests.java | 4 ++-- 22 files changed, 124 insertions(+), 133 deletions(-) diff --git a/build.gradle b/build.gradle index fe38741754..8d4001b0f1 100644 --- a/build.gradle +++ b/build.gradle @@ -359,7 +359,7 @@ configure(javaProjects) { subproject -> checkstyle { configDirectory.set(rootProject.file('src/checkstyle')) - toolVersion = project.hasProperty('checkstyleVersion') ? project.checkstyleVersion : '9.2.1' + toolVersion = project.hasProperty('checkstyleVersion') ? project.checkstyleVersion : '10.0' } jar { diff --git a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandler.java b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandler.java index 54199b22de..36f554585e 100644 --- a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandler.java +++ b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandler.java @@ -40,7 +40,7 @@ import org.springframework.util.StringUtils; /** * MessageHandler that sends an XMPP Chat Message. Supported payload types are Smack Message - * (org.jivesoftware.smack.packet.Message) or String. + * {@link org.jivesoftware.smack.packet.Message} or String. * * @author Josh Long * @author Mario Gray diff --git a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapper.java b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapper.java index e751c906ec..475b338dd3 100644 --- a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapper.java +++ b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapper.java @@ -105,7 +105,6 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper + new ClassPathXmlApplicationContext("PresenceInboundChannelAdapterParserTests-context.xml", + this.getClass()) + .close()); } } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java index bbbd64188f..4d61370b0a 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -35,17 +34,16 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Oleg Zhurakousky * @author Mark Fisher * @author Gary Russell * @author Gunnar Hillert + * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig public class PresenceOutboundChannelAdapterParserTests { @Autowired diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java index 6cfed2b375..ce192005b7 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,13 +17,14 @@ package org.springframework.integration.xmpp.config; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.Mockito.mock; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -47,9 +48,12 @@ public class XmppConnectionFactoryBeanTests { } @Test - public void testXmppConnectionFactoryBeanViaConfig() throws Exception { - new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml", this.getClass()).close(); - // the fact that no exception was thrown satisfies this test + public void testXmppConnectionFactoryBeanViaConfig() { + assertThatNoException() + .isThrownBy(() -> + new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml", + this.getClass()) + .close()); } @Test diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionParserTests.java index 4a302c8d89..7e158588b6 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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.config; import static org.assertj.core.api.Assertions.assertThat; import org.jivesoftware.smack.XMPPConnection; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -38,7 +38,7 @@ public class XmppConnectionParserTests { public void testSimpleConfiguration() { ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass()); - XMPPConnection connection = ac.getBean("connection", XMPPConnection.class); + XMPPConnection connection = ac.getBean("connection", XMPPConnection.class); assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("my.domain"); assertThat(connection.isConnected()).isFalse(); XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class); @@ -57,7 +57,7 @@ public class XmppConnectionParserTests { public void testCompleteConfiguration() { ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass()); - XMPPConnection connection = ac.getBean("connection", XMPPConnection.class); + XMPPConnection connection = ac.getBean("connection", XMPPConnection.class); assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("foogle.com"); assertThat(connection.isConnected()).isFalse(); XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java index a2981bf507..970e160272 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,7 @@ import static org.mockito.Mockito.verify; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -38,8 +37,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Mark Fisher @@ -50,8 +48,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class XmppHeaderEnricherParserTests { diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests.java index a9211ad847..d8d1738795 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,13 +16,12 @@ package org.springframework.integration.xmpp.ignore; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Mark Fisher @@ -30,8 +29,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@Disabled public class ConsoleChatTests { public static void main(String[] args) { @@ -39,7 +38,6 @@ public class ConsoleChatTests { } @Test - @Ignore public void run() throws Exception { Thread.sleep(10 * 1000 * 1000); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundChatTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundChatTests.java index b253e9adf7..b16174eef9 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundChatTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundChatTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,23 +16,20 @@ package org.springframework.integration.xmpp.ignore; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Josh Long * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@Disabled public class InboundChatTests { @Test - @Ignore public void run() throws Exception { Thread.sleep(10 * 1000 * 1000); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundPresenceTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundPresenceTests.java index 1974cb5aa7..2bba649849 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundPresenceTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundPresenceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,12 +16,11 @@ package org.springframework.integration.xmpp.ignore; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * this class demonstrates that when I launch this and then manipulate the status of the @@ -30,12 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Josh Long * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@Disabled public class InboundPresenceTests { @Test - @Ignore public void run() throws Exception { Thread.sleep(60 * 1000 * 1000); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundChatTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundChatTests.java index 79ec9d3f10..6fd8666d9a 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundChatTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundChatTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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,12 +16,10 @@ package org.springframework.integration.xmpp.ignore; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Testing support for sending messages. @@ -29,12 +27,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Josh Long * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@Disabled public class OutboundChatTests { @Test - @Ignore public void run() throws Exception { Thread.sleep(10 * 1000 * 100); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundPresenceTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundPresenceTests.java index cb0ff6aaea..d2c05b33cc 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundPresenceTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/OutboundPresenceTests.java @@ -18,17 +18,15 @@ package org.springframework.integration.xmpp.ignore; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.StanzaBuilder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.xmpp.outbound.PresenceSendingMessageHandler; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Tests {@link PresenceSendingMessageHandler} to ensure that we are able to publish status. @@ -38,8 +36,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@Disabled public class OutboundPresenceTests { @Autowired @@ -47,7 +45,6 @@ public class OutboundPresenceTests { private DirectChannel input; @Test - @Ignore public void testOutbound() throws Throwable { Presence presence = StanzaBuilder.buildPresence().build(); input.send(new GenericMessage<>(presence)); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/SmackMessageSampleTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/SmackMessageSampleTests.java index 3d84978860..2709ec7a51 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/SmackMessageSampleTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/SmackMessageSampleTests.java @@ -17,8 +17,8 @@ package org.springframework.integration.xmpp.ignore; import org.jivesoftware.smack.packet.StanzaBuilder; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.jxmpp.stringprep.XmppStringprepException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -32,10 +32,10 @@ import org.springframework.messaging.support.GenericMessage; * @author Artem Bilan * @author Florian Schmaus */ +@Disabled public class SmackMessageSampleTests { @Test - @Ignore public void validateSmackMessageSent() throws XmppStringprepException { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("SmackMessageSampleTest-context.xml", this.getClass()); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/XmppMessageConsumer.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/XmppMessageConsumer.java index 4a0d4928f7..52c9a2d5a1 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/XmppMessageConsumer.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/XmppMessageConsumer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -37,8 +37,8 @@ public class XmppMessageConsumer { private final Log logger = LogFactory.getLog(getClass()); @ServiceActivator - public void consume(Object input) throws Throwable { - String text = null; + public void consume(Object input) { + String text; if (input instanceof Message) { text = ((Message) input).getBody(); } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java index 793471298b..58a9561e00 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/ChatMessageListeningEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -218,15 +218,15 @@ public class ChatMessageListeningEndpointTests { @Test public void testGcmExtension() throws Exception { - String data = "{\n" + - " \"to\":\"me\",\n" + - " \"notification\": {\n" + - " \"title\": \"Something interesting\",\n" + - " \"text\": \"Here we go\"\n" + - " },\n" + - " \"time_to_live\":\"600\"\n" + - " }\n" + - "}"; + String data = """ + { + "to":"me", + "notification": { + "title": "Something interesting", + "text": "Here we go" + }, + "time_to_live":"600" + }"""; GcmPacketExtension packetExtension = new GcmPacketExtension(data); MessageBuilder smackMessage = StanzaBuilder.buildMessage(); smackMessage.addExtension(packetExtension); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java index 64b732d092..985d5c91a6 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/inbound/PresenceListeningEndpointTests.java @@ -17,6 +17,7 @@ package org.springframework.integration.xmpp.inbound; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.Mockito.mock; import java.util.Set; @@ -26,7 +27,7 @@ import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.StanzaBuilder; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.roster.RosterListener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -67,10 +68,11 @@ public class PresenceListeningEndpointTests { assertThat(rosterSet.size()).isEqualTo(0); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNonInitializedFailure() { PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(mock(XMPPConnection.class)); - rosterEndpoint.start(); + assertThatIllegalArgumentException() + .isThrownBy(rosterEndpoint::start); } @Test @@ -104,11 +106,12 @@ public class PresenceListeningEndpointTests { assertThat(TestUtils.getPropertyValue(endpoint, "xmppConnection")).isNotNull(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNoXmppConnection() { PresenceListeningEndpoint handler = new PresenceListeningEndpoint(); handler.setBeanFactory(mock(BeanFactory.class)); - handler.afterPropertiesSet(); + assertThatIllegalArgumentException() + .isThrownBy(handler::afterPropertiesSet); } @Test diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java index 519da3cff0..ebcf2f1055 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandlerTests.java @@ -17,6 +17,8 @@ package org.springframework.integration.xmpp.outbound; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -28,7 +30,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.StanzaBuilder; import org.jivesoftware.smackx.gcm.packet.GcmPacketExtension; import org.jivesoftware.smackx.gcm.provider.GcmExtensionProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -50,7 +52,6 @@ import org.springframework.messaging.support.GenericMessage; */ public class ChatMessageSendingMessageHandlerTests { - @Test public void testSendMessages() throws Exception { XMPPConnection connection = mock(XMPPConnection.class); @@ -184,16 +185,18 @@ public class ChatMessageSendingMessageHandlerTests { } - @Test(expected = MessageHandlingException.class) - public void validateFailureNoChatToUser() throws Exception { + @Test + public void validateFailureNoChatToUser() { ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class)); - handler.handleMessage(new GenericMessage<>("hello")); + assertThatExceptionOfType(MessageHandlingException.class) + .isThrownBy(() -> handler.handleMessage(new GenericMessage<>("hello"))); } - @Test(expected = MessageHandlingException.class) - public void validateMessageWithUnsupportedPayload() throws Exception { + @Test + public void validateMessageWithUnsupportedPayload() { ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class)); - handler.handleMessage(new GenericMessage<>(123)); + assertThatExceptionOfType(MessageHandlingException.class) + .isThrownBy(() -> handler.handleMessage(new GenericMessage<>(123))); } @Test @@ -206,11 +209,12 @@ public class ChatMessageSendingMessageHandlerTests { assertThat(TestUtils.getPropertyValue(handler, "xmppConnection")).isNotNull(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNoXmppConnection() { ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(); handler.setBeanFactory(mock(BeanFactory.class)); - handler.afterPropertiesSet(); + assertThatIllegalArgumentException() + .isThrownBy(handler::afterPropertiesSet); } } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/PresenceSendingMessageHandlerTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/PresenceSendingMessageHandlerTests.java index e1b136491f..6788c5a6c1 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/PresenceSendingMessageHandlerTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/outbound/PresenceSendingMessageHandlerTests.java @@ -17,11 +17,13 @@ package org.springframework.integration.xmpp.outbound; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.Mockito.mock; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.StanzaBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -46,13 +48,13 @@ public class PresenceSendingMessageHandlerTests { handler.handleMessage(new GenericMessage<>(StanzaBuilder.buildPresence().build())); } - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test(expected = MessageHandlingException.class) + @Test public void testWrongPayload() { PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler(mock(XMPPConnection.class)); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); - handler.handleMessage(new GenericMessage(new Object())); + assertThatExceptionOfType(MessageHandlingException.class) + .isThrownBy(() -> handler.handleMessage(new GenericMessage<>(new Object()))); } @Test @@ -65,11 +67,12 @@ public class PresenceSendingMessageHandlerTests { assertThat(TestUtils.getPropertyValue(handler, "xmppConnection")).isNotNull(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNoXmppConnection() { PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler(); handler.setBeanFactory(mock(BeanFactory.class)); - handler.afterPropertiesSet(); + assertThatIllegalArgumentException() + .isThrownBy(handler::afterPropertiesSet); } } diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapperTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapperTests.java index 67f6ebe877..0f6062badc 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapperTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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,7 +25,7 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.MessageBuilder; import org.jivesoftware.smack.packet.StanzaBuilder; import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.jxmpp.stringprep.XmppStringprepException; import org.springframework.integration.xmpp.XmppHeaders;