Skip to content

Commit b081992

Browse files
committed
Code clean up for XMPP module
* Ugrade to Checkstyle `10.0` * Migrate XMPP test to JUnit `5`
1 parent 330dfd0 commit b081992

22 files changed

+124
-133
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ configure(javaProjects) { subproject ->
359359

360360
checkstyle {
361361
configDirectory.set(rootProject.file('src/checkstyle'))
362-
toolVersion = project.hasProperty('checkstyleVersion') ? project.checkstyleVersion : '9.2.1'
362+
toolVersion = project.hasProperty('checkstyleVersion') ? project.checkstyleVersion : '10.0'
363363
}
364364

365365
jar {

spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/outbound/ChatMessageSendingMessageHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
/**
4242
* MessageHandler that sends an XMPP Chat Message. Supported payload types are Smack Message
43-
* (org.jivesoftware.smack.packet.Message) or String.
43+
* {@link org.jivesoftware.smack.packet.Message} or String.
4444
*
4545
* @author Josh Long
4646
* @author Mario Gray

spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/support/DefaultXmppHeaderMapper.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ protected void populateStandardHeaders(Map<String, Object> headers, MessageBuild
105105
target.setThread(threadId);
106106
}
107107
populateToHeader(headers, target);
108-
109108
populateFromHeader(headers, target);
110109

111110
String subject = getHeaderIfAvailable(headers, XmppHeaders.SUBJECT, String.class);
@@ -119,10 +118,8 @@ protected void populateStandardHeaders(Map<String, Object> headers, MessageBuild
119118
typeHeader = Message.Type.valueOf((String) typeHeader);
120119
}
121120
catch (Exception e) {
122-
if (logger.isWarnEnabled()) {
123-
logger.warn("XMPP Type must be either a valid [Message.Type] " +
124-
"enum value or a String representation of such.");
125-
}
121+
logger.warn("XMPP Type must be either a valid [Message.Type] " +
122+
"enum value or a String representation of such.");
126123
}
127124
}
128125
if (typeHeader instanceof Message.Type messageType) {

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,7 @@
2626
import org.jivesoftware.smack.packet.MessageBuilder;
2727
import org.jivesoftware.smack.packet.StanzaBuilder;
2828
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
29-
import org.junit.Test;
30-
import org.junit.runner.RunWith;
29+
import org.junit.jupiter.api.Test;
3130
import org.jxmpp.jid.impl.JidCreate;
3231
import org.mockito.Mockito;
3332

@@ -40,8 +39,7 @@
4039
import org.springframework.messaging.MessageChannel;
4140
import org.springframework.test.annotation.DirtiesContext;
4241
import org.springframework.test.annotation.DirtiesContext.ClassMode;
43-
import org.springframework.test.context.ContextConfiguration;
44-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
42+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4543
import org.springframework.util.ReflectionUtils;
4644

4745
/**
@@ -51,8 +49,7 @@
5149
* @author Florian Schmaus
5250
* @author Artem Bilan
5351
*/
54-
@ContextConfiguration
55-
@RunWith(SpringJUnit4ClassRunner.class)
52+
@SpringJUnitConfig
5653
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
5754
public class ChatMessageInboundChannelAdapterParserTests {
5855

@@ -70,7 +67,7 @@ public class ChatMessageInboundChannelAdapterParserTests {
7067
private ChatMessageListeningEndpoint autoChannelAdapter;
7168

7269
@Test
73-
@SuppressWarnings({"rawtypes", "unchecked"})
70+
@SuppressWarnings({ "rawtypes", "unchecked" })
7471
public void testInboundAdapter() {
7572
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
7673
MessageChannel errorChannel = (MessageChannel) TestUtils.getPropertyValue(adapter, "errorChannel");

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageOutboundChannelAdapterParserTests.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,7 @@
2424
import org.jivesoftware.smack.XMPPConnection;
2525
import org.jivesoftware.smack.provider.ExtensionElementProvider;
2626
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.Test;
2928
import org.mockito.Mockito;
3029

3130
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,8 +44,7 @@
4544
import org.springframework.messaging.MessageHandler;
4645
import org.springframework.messaging.SubscribableChannel;
4746
import org.springframework.messaging.support.GenericMessage;
48-
import org.springframework.test.context.ContextConfiguration;
49-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
47+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5048

5149
/**
5250
* @author Oleg Zhurakousky
@@ -55,8 +53,7 @@
5553
* @author Gunnar Hillert
5654
* @author Florian Schmaus
5755
*/
58-
@ContextConfiguration
59-
@RunWith(SpringJUnit4ClassRunner.class)
56+
@SpringJUnitConfig
6057
public class ChatMessageOutboundChannelAdapterParserTests {
6158

6259
@Autowired
@@ -114,7 +111,6 @@ public void testEventConsumer() {
114111
.isSameAs(this.extensionElementProvider);
115112
}
116113

117-
@SuppressWarnings("rawtypes")
118114
@Test
119115
public void withHeaderMapper() throws Exception {
120116
Object pollingConsumer = context.getBean("withHeaderMapper");

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceInboundChannelAdapterParserTests.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,9 @@
1616

1717
package org.springframework.integration.xmpp.config;
1818

19-
import org.junit.Test;
19+
import static org.assertj.core.api.Assertions.assertThatNoException;
20+
21+
import org.junit.jupiter.api.Test;
2022

2123
import org.springframework.context.support.ClassPathXmlApplicationContext;
2224

@@ -28,8 +30,11 @@ public class PresenceInboundChannelAdapterParserTests {
2830

2931
@Test
3032
public void testPresenceInboundChannelAdapterParser() {
31-
new ClassPathXmlApplicationContext("PresenceInboundChannelAdapterParserTests-context.xml", this.getClass()).close();
32-
// no assertion needed. The fact that no exception was thrown satisfies this test
33+
assertThatNoException()
34+
.isThrownBy(() ->
35+
new ClassPathXmlApplicationContext("PresenceInboundChannelAdapterParserTests-context.xml",
36+
this.getClass())
37+
.close());
3338
}
3439

3540
}

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
2020

2121
import java.util.Set;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2524

2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.context.ApplicationContext;
@@ -35,17 +34,16 @@
3534
import org.springframework.messaging.MessageHandler;
3635
import org.springframework.messaging.SubscribableChannel;
3736
import org.springframework.messaging.support.GenericMessage;
38-
import org.springframework.test.context.ContextConfiguration;
39-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4038

4139
/**
4240
* @author Oleg Zhurakousky
4341
* @author Mark Fisher
4442
* @author Gary Russell
4543
* @author Gunnar Hillert
44+
* @author Artem Bilan
4645
*/
47-
@ContextConfiguration
48-
@RunWith(SpringJUnit4ClassRunner.class)
46+
@SpringJUnitConfig
4947
public class PresenceOutboundChannelAdapterParserTests {
5048

5149
@Autowired

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,13 +17,14 @@
1717
package org.springframework.integration.xmpp.config;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatNoException;
2021
import static org.mockito.Mockito.mock;
2122

2223
import org.jivesoftware.smack.XMPPConnection;
2324
import org.jivesoftware.smack.roster.Roster;
2425
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
2526
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
26-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2728

2829
import org.springframework.context.support.ClassPathXmlApplicationContext;
2930

@@ -47,9 +48,12 @@ public void testXmppConnectionFactoryBean() throws Exception {
4748
}
4849

4950
@Test
50-
public void testXmppConnectionFactoryBeanViaConfig() throws Exception {
51-
new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml", this.getClass()).close();
52-
// the fact that no exception was thrown satisfies this test
51+
public void testXmppConnectionFactoryBeanViaConfig() {
52+
assertThatNoException()
53+
.isThrownBy(() ->
54+
new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml",
55+
this.getClass())
56+
.close());
5357
}
5458

5559
@Test

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionParserTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import static org.assertj.core.api.Assertions.assertThat;
2020

2121
import org.jivesoftware.smack.XMPPConnection;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.context.ConfigurableApplicationContext;
2525
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -38,7 +38,7 @@ public class XmppConnectionParserTests {
3838
public void testSimpleConfiguration() {
3939
ConfigurableApplicationContext ac =
4040
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
41-
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
41+
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
4242
assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("my.domain");
4343
assertThat(connection.isConnected()).isFalse();
4444
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
@@ -57,7 +57,7 @@ public void testSimpleConfiguration() {
5757
public void testCompleteConfiguration() {
5858
ConfigurableApplicationContext ac =
5959
new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
60-
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
60+
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
6161
assertThat(connection.getXMPPServiceDomain().toString()).isEqualTo("foogle.com");
6262
assertThat(connection.isConnected()).isFalse();
6363
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppHeaderEnricherParserTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,7 @@
2525
import java.util.concurrent.CountDownLatch;
2626
import java.util.concurrent.TimeUnit;
2727

28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
28+
import org.junit.jupiter.api.Test;
3029
import org.mockito.Mockito;
3130

3231
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,8 +37,7 @@
3837
import org.springframework.messaging.MessageChannel;
3938
import org.springframework.messaging.MessageHandler;
4039
import org.springframework.test.annotation.DirtiesContext;
41-
import org.springframework.test.context.ContextConfiguration;
42-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4341

4442
/**
4543
* @author Mark Fisher
@@ -50,8 +48,7 @@
5048
*
5149
* @since 2.0
5250
*/
53-
@ContextConfiguration
54-
@RunWith(SpringJUnit4ClassRunner.class)
51+
@SpringJUnitConfig
5552
@DirtiesContext
5653
public class XmppHeaderEnricherParserTests {
5754

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,30 +16,28 @@
1616

1717
package org.springframework.integration.xmpp.ignore;
1818

19-
import org.junit.Ignore;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
19+
20+
import org.junit.jupiter.api.Disabled;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.context.support.ClassPathXmlApplicationContext;
24-
import org.springframework.test.context.ContextConfiguration;
25-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2625

2726
/**
2827
* @author Mark Fisher
2928
* @author Artem Bilan
3029
* @author Gary Russell
3130
* @since 2.0
3231
*/
33-
@ContextConfiguration
34-
@RunWith(SpringJUnit4ClassRunner.class)
32+
@SpringJUnitConfig
33+
@Disabled
3534
public class ConsoleChatTests {
3635

3736
public static void main(String[] args) {
3837
new ClassPathXmlApplicationContext("ConsoleChatTests-context.xml", ConsoleChatTests.class).close();
3938
}
4039

4140
@Test
42-
@Ignore
4341
public void run() throws Exception {
4442
Thread.sleep(10 * 1000 * 1000);
4543
}

spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/InboundChatTests.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,23 +16,20 @@
1616

1717
package org.springframework.integration.xmpp.ignore;
1818

19-
import org.junit.Ignore;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Disabled;
20+
import org.junit.jupiter.api.Test;
2221

23-
import org.springframework.test.context.ContextConfiguration;
24-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
22+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2523

2624
/**
2725
* @author Josh Long
2826
* @since 2.0
2927
*/
30-
@ContextConfiguration
31-
@RunWith(SpringJUnit4ClassRunner.class)
28+
@SpringJUnitConfig
29+
@Disabled
3230
public class InboundChatTests {
3331

3432
@Test
35-
@Ignore
3633
public void run() throws Exception {
3734
Thread.sleep(10 * 1000 * 1000);
3835
}

0 commit comments

Comments
 (0)