Skip to content

Commit d229cb4

Browse files
authored
spring-projectsGH-9996: Migrating tests to Junit Jupiter and Deprecate Junit4 utilities
Fixes: spring-projects#9996 Signed-off-by: Jiandong Ma <[email protected]>
1 parent bf9d391 commit d229cb4

File tree

54 files changed

+396
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+396
-287
lines changed

build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ configure(javaProjects) { subproject ->
299299
testImplementation("org.awaitility:awaitility:$awaitilityVersion") {
300300
exclude group: 'org.hamcrest'
301301
}
302-
testImplementation("junit:junit:$junit4Version") {
303-
exclude group: 'org.hamcrest'
304-
}
305302
testImplementation 'org.junit.jupiter:junit-jupiter-api'
306303
testImplementation 'org.junit.jupiter:junit-jupiter-params'
307304
testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertkVersion") {
@@ -314,8 +311,6 @@ configure(javaProjects) { subproject ->
314311

315312
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
316313
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
317-
// To support JUnit 4 tests
318-
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
319314

320315
testRuntimeOnly 'org.apache.logging.log4j:log4j-core'
321316
testRuntimeOnly 'org.apache.logging.log4j:log4j-jcl'

spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,7 +20,7 @@
2020
import java.util.List;
2121

2222
import org.springframework.integration.test.predicate.MessagePredicate;
23-
import org.springframework.integration.test.support.AbstractRequestResponseScenarioTests;
23+
import org.springframework.integration.test.support.AbstractRequestResponseScenarioTest;
2424
import org.springframework.integration.test.support.MessageValidator;
2525
import org.springframework.integration.test.support.PayloadValidator;
2626
import org.springframework.integration.test.support.RequestResponseScenario;
@@ -37,7 +37,7 @@
3737
*/
3838
@ContextConfiguration
3939
@DirtiesContext
40-
public class MessageScenariosTests extends AbstractRequestResponseScenarioTests {
40+
public class MessageScenariosTests extends AbstractRequestResponseScenarioTest {
4141

4242
@Override
4343
protected List<RequestResponseScenario> defineRequestResponseScenarios() {

spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -18,7 +18,7 @@
1818

1919
import org.springframework.integration.test.support.PayloadValidator;
2020
import org.springframework.integration.test.support.RequestResponseScenario;
21-
import org.springframework.integration.test.support.SingleRequestResponseScenarioTests;
21+
import org.springframework.integration.test.support.SingleRequestResponseScenarioTest;
2222
import org.springframework.test.annotation.DirtiesContext;
2323
import org.springframework.test.context.ContextConfiguration;
2424

@@ -31,7 +31,7 @@
3131
*/
3232
@ContextConfiguration("MessageScenariosTests-context.xml")
3333
@DirtiesContext
34-
public class SingleScenarioTests extends SingleRequestResponseScenarioTests {
34+
public class SingleScenarioTests extends SingleRequestResponseScenarioTest {
3535

3636
@Override
3737
protected RequestResponseScenario defineRequestResponseScenario() {

spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
directory="#{inputDirectory.path}"
2020
channel="fileMessages" filter="compositeFilter"/>
2121

22-
<bean id="temp" class="org.junit.rules.TemporaryFolder"
23-
init-method="create" destroy-method="delete"/>
24-
2522
<bean id="inputDirectory" class="java.io.File">
26-
<constructor-arg value="#{temp.newFolder('FileToChannelIntegrationTests').path}"/>
23+
<constructor-arg value="#{T(org.springframework.integration.file.FileToChannelIntegrationTests).tempDir.path}"/>
2724
</bean>
2825

2926
<si:channel id="fileMessages">

spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020

2121
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.io.TempDir;
2223

2324
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.messaging.Message;
@@ -37,6 +38,9 @@
3738
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
3839
public class FileToChannelIntegrationTests {
3940

41+
@TempDir
42+
public static File tempDir;
43+
4044
@Autowired
4145
File inputDirectory;
4246

spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests-context.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
https://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
1212

1313
<!-- under test -->
14-
<file:inbound-channel-adapter id="customLockingAdapter" directory="#{directory.root}">
14+
<file:inbound-channel-adapter id="customLockingAdapter" directory="#{directory}">
1515
<file:locker ref="customLocker"/>
1616
</file:inbound-channel-adapter>
1717

18-
<file:inbound-channel-adapter id="nioLockingAdapter" directory="#{directory.root}">
18+
<file:inbound-channel-adapter id="nioLockingAdapter" directory="#{directory}">
1919
<file:nio-locker/>
2020
</file:inbound-channel-adapter>
2121

2222
<bean id="customLocker" class="org.springframework.integration.file.locking.FileLockingNamespaceTests$StubLocker"/>
2323

24-
<bean id="directory" class="org.junit.rules.TemporaryFolder" init-method="create" destroy-method="delete"/>
24+
<bean id="directory" class="java.io.File">
25+
<constructor-arg value="#{T(org.springframework.integration.file.locking.FileLockingNamespaceTests).tempDir.path}"/>
26+
</bean>
2527

2628
<si:poller default="true" fixed-delay="100000000"/>
2729

spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.junit.jupiter.api.BeforeEach;
2222
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.io.TempDir;
2324

2425
import org.springframework.beans.DirectFieldAccessor;
2526
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +42,9 @@
4142
@DirtiesContext
4243
public class FileLockingNamespaceTests {
4344

45+
@TempDir
46+
public static File tempDir;
47+
4448
@Autowired
4549
@Qualifier("nioLockingAdapter.adapter")
4650
SourcePollingChannelAdapter nioAdapter;

spring-integration-jmx/src/test/java/org/springframework/integration/jmx/AttributePollingMessageSourceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,7 +20,7 @@
2020

2121
import javax.management.MBeanServer;
2222

23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.jmx.support.MBeanServerFactoryBean;
2626
import org.springframework.jmx.support.ObjectNameManager;

spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanTreePollingMessageSourceTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2025 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.
@@ -21,9 +21,9 @@
2121

2222
import javax.management.MBeanServer;
2323

24-
import org.junit.AfterClass;
25-
import org.junit.BeforeClass;
26-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterAll;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.jmx.support.MBeanServerFactoryBean;
2929

@@ -40,15 +40,15 @@ public class MBeanTreePollingMessageSourceTests {
4040

4141
private static MBeanServer server;
4242

43-
@BeforeClass
43+
@BeforeAll
4444
public static void setup() {
4545
factoryBean = new MBeanServerFactoryBean();
4646
factoryBean.setLocateExistingServerIfPossible(true);
4747
factoryBean.afterPropertiesSet();
4848
server = factoryBean.getObject();
4949
}
5050

51-
@AfterClass
51+
@AfterAll
5252
public static void tearDown() {
5353
factoryBean.destroy();
5454
}

spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -22,11 +22,11 @@
2222
import javax.management.Notification;
2323
import javax.management.ObjectName;
2424

25-
import org.junit.After;
26-
import org.junit.AfterClass;
27-
import org.junit.Before;
28-
import org.junit.BeforeClass;
29-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
3030
import org.mockito.Mockito;
3131

3232
import org.springframework.beans.factory.BeanFactory;
@@ -59,13 +59,13 @@ public class NotificationListeningMessageProducerTests {
5959

6060
private ObjectName objectName;
6161

62-
@BeforeClass
62+
@BeforeAll
6363
public static void setupClass() {
6464
serverFactoryBean = new MBeanServerFactoryBean();
6565
serverFactoryBean.afterPropertiesSet();
6666
}
6767

68-
@Before
68+
@BeforeEach
6969
public void setup() throws Exception {
7070
this.server = serverFactoryBean.getObject();
7171
MBeanExporter exporter = new MBeanExporter();
@@ -75,12 +75,12 @@ public void setup() throws Exception {
7575
exporter.registerManagedResource(this.numberHolder, this.objectName);
7676
}
7777

78-
@After
78+
@AfterEach
7979
public void cleanup() throws Exception {
8080
this.server.unregisterMBean(this.objectName);
8181
}
8282

83-
@AfterClass
83+
@AfterAll
8484
public static void tearDown() {
8585
serverFactoryBean.destroy();
8686
}

0 commit comments

Comments
 (0)