Skip to content

GH-9996: Migrating remaining tests to Junit Jupiter and Deprecate Junit4 utilities #10087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ configure(javaProjects) { subproject ->
testImplementation("org.awaitility:awaitility:$awaitilityVersion") {
exclude group: 'org.hamcrest'
}
testImplementation("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest'
}
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertkVersion") {
Expand All @@ -314,8 +311,6 @@ configure(javaProjects) { subproject ->

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// To support JUnit 4 tests
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

testRuntimeOnly 'org.apache.logging.log4j:log4j-core'
testRuntimeOnly 'org.apache.logging.log4j:log4j-jcl'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -20,7 +20,7 @@
import java.util.List;

import org.springframework.integration.test.predicate.MessagePredicate;
import org.springframework.integration.test.support.AbstractRequestResponseScenarioTests;
import org.springframework.integration.test.support.AbstractRequestResponseScenarioTest;
import org.springframework.integration.test.support.MessageValidator;
import org.springframework.integration.test.support.PayloadValidator;
import org.springframework.integration.test.support.RequestResponseScenario;
Expand All @@ -37,7 +37,7 @@
*/
@ContextConfiguration
@DirtiesContext
public class MessageScenariosTests extends AbstractRequestResponseScenarioTests {
public class MessageScenariosTests extends AbstractRequestResponseScenarioTest {

@Override
protected List<RequestResponseScenario> defineRequestResponseScenarios() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -18,7 +18,7 @@

import org.springframework.integration.test.support.PayloadValidator;
import org.springframework.integration.test.support.RequestResponseScenario;
import org.springframework.integration.test.support.SingleRequestResponseScenarioTests;
import org.springframework.integration.test.support.SingleRequestResponseScenarioTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

Expand All @@ -31,7 +31,7 @@
*/
@ContextConfiguration("MessageScenariosTests-context.xml")
@DirtiesContext
public class SingleScenarioTests extends SingleRequestResponseScenarioTests {
public class SingleScenarioTests extends SingleRequestResponseScenarioTest {

@Override
protected RequestResponseScenario defineRequestResponseScenario() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
directory="#{inputDirectory.path}"
channel="fileMessages" filter="compositeFilter"/>

<bean id="temp" class="org.junit.rules.TemporaryFolder"
init-method="create" destroy-method="delete"/>

<bean id="inputDirectory" class="java.io.File">
<constructor-arg value="#{temp.newFolder('FileToChannelIntegrationTests').path}"/>
<constructor-arg value="#{T(org.springframework.integration.file.FileToChannelIntegrationTests).tempDir.path}"/>
</bean>

<si:channel id="fileMessages">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

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

@TempDir
public static File tempDir;

@Autowired
File inputDirectory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
https://www.springframework.org/schema/integration/file/spring-integration-file.xsd">

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -41,6 +42,9 @@
@DirtiesContext
public class FileLockingNamespaceTests {

@TempDir
public static File tempDir;

@Autowired
@Qualifier("nioLockingAdapter.adapter")
SourcePollingChannelAdapter nioAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -20,7 +20,7 @@

import javax.management.MBeanServer;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.jmx.support.ObjectNameManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2025 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.
Expand All @@ -21,9 +21,9 @@

import javax.management.MBeanServer;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.springframework.jmx.support.MBeanServerFactoryBean;

Expand All @@ -40,15 +40,15 @@ public class MBeanTreePollingMessageSourceTests {

private static MBeanServer server;

@BeforeClass
@BeforeAll
public static void setup() {
factoryBean = new MBeanServerFactoryBean();
factoryBean.setLocateExistingServerIfPossible(true);
factoryBean.afterPropertiesSet();
server = factoryBean.getObject();
}

@AfterClass
@AfterAll
public static void tearDown() {
factoryBean.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -22,11 +22,11 @@
import javax.management.Notification;
import javax.management.ObjectName;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import org.springframework.beans.factory.BeanFactory;
Expand Down Expand Up @@ -59,13 +59,13 @@ public class NotificationListeningMessageProducerTests {

private ObjectName objectName;

@BeforeClass
@BeforeAll
public static void setupClass() {
serverFactoryBean = new MBeanServerFactoryBean();
serverFactoryBean.afterPropertiesSet();
}

@Before
@BeforeEach
public void setup() throws Exception {
this.server = serverFactoryBean.getObject();
MBeanExporter exporter = new MBeanExporter();
Expand All @@ -75,12 +75,12 @@ public void setup() throws Exception {
exporter.registerManagedResource(this.numberHolder, this.objectName);
}

@After
@AfterEach
public void cleanup() throws Exception {
this.server.unregisterMBean(this.objectName);
}

@AfterClass
@AfterAll
public static void tearDown() {
serverFactoryBean.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -23,9 +23,9 @@
import javax.management.NotificationListener;
import javax.management.ObjectName;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class NotificationPublishingMessageHandlerTests {

private volatile ObjectName publisherObjectName;

@Before
@BeforeEach
public void setup() throws Exception {
this.publisherObjectName = ObjectNameManager.getInstance("test:type=publisher");
this.context.registerBean("mbeanServer", MBeanServerFactoryBean.class, MBeanServerFactoryBean::new);
Expand All @@ -72,7 +72,7 @@ public void setup() throws Exception {
exporter.getServer().addNotificationListener(publisherObjectName, this.listener, null, null);
}

@After
@AfterEach
public void cleanup() {
this.listener.clearNotifications();
context.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -23,11 +23,11 @@

import javax.management.MBeanServer;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.channel.QueueChannel;
Expand All @@ -39,6 +39,7 @@
import org.springframework.messaging.MessagingException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;

/**
Expand All @@ -61,24 +62,24 @@ public class OperationInvokingMessageHandlerTests {

private final String objectName = "si:name=test";

@BeforeClass
@BeforeAll
public static void setupClass() {
factoryBean = new MBeanServerFactoryBean();
factoryBean.afterPropertiesSet();
server = factoryBean.getObject();
}

@AfterClass
@AfterAll
public static void tearDown() {
factoryBean.destroy();
}

@Before
@BeforeEach
public void setup() throws Exception {
server.registerMBean(new TestOps(), ObjectNameManager.getInstance(this.objectName));
}

@After
@AfterEach
public void cleanup() throws Exception {
server.unregisterMBean(ObjectNameManager.getInstance(this.objectName));
}
Expand Down Expand Up @@ -115,7 +116,7 @@ public void invocationWithPayloadNoReturnValue() {
handler.handleMessage(message);
}

@Test(expected = MessagingException.class)
@Test
public void invocationWithMapPayloadNotEnoughParameters() {
QueueChannel outputChannel = new QueueChannel();
OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler(server);
Expand All @@ -127,10 +128,8 @@ public void invocationWithMapPayloadNotEnoughParameters() {
Map<String, Object> params = new HashMap<>();
params.put("p1", "foo");
Message<?> message = MessageBuilder.withPayload(params).build();
handler.handleMessage(message);
Message<?> reply = outputChannel.receive(0);
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foobar");
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> handler.handleMessage(message));
}

@Test
Expand Down
Loading