You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2025/09/29 09:17:17 UTC
(rocketmq) branch develop updated: [ISSUE #9658] Replace JUnit 5 imports with JUnit 4 (#9659)
This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 1c83b11768 [ISSUE #9658] Replace JUnit 5 imports with JUnit 4 (#9659)
1c83b11768 is described below
commit 1c83b117685e715bfec215bf0afdb492cc86718f
Author: yx9o <ya...@163.com>
AuthorDate: Mon Sep 29 17:17:12 2025 +0800
[ISSUE #9658] Replace JUnit 5 imports with JUnit 4 (#9659)
* [ISSUE #9658] Replace JUnit 5 imports with JUnit 4
* Update test
---
.../client/impl/mqclient/MQClientAPITest.java | 31 +++++++++--------
.../service/cert/TlsCertificateManagerTest.java | 40 +++++++++-------------
2 files changed, 32 insertions(+), 39 deletions(-)
diff --git a/client/src/test/java/org/apache/rocketmq/client/impl/mqclient/MQClientAPITest.java b/client/src/test/java/org/apache/rocketmq/client/impl/mqclient/MQClientAPITest.java
index 965c5ae16b..698aa1e97d 100644
--- a/client/src/test/java/org/apache/rocketmq/client/impl/mqclient/MQClientAPITest.java
+++ b/client/src/test/java/org/apache/rocketmq/client/impl/mqclient/MQClientAPITest.java
@@ -17,8 +17,9 @@
package org.apache.rocketmq.client.impl.mqclient;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
@@ -27,11 +28,11 @@ import org.apache.rocketmq.client.impl.ClientRemotingProcessor;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.utils.ThreadUtils;
import org.apache.rocketmq.remoting.RPCHook;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-class MQClientAPITest {
+public class MQClientAPITest {
private NameserverAccessConfig nameserverAccessConfig;
private final ClientRemotingProcessor clientRemotingProcessor = new DoNothingClientRemotingProcessor(null);
@@ -39,18 +40,18 @@ class MQClientAPITest {
private ScheduledExecutorService scheduledExecutorService;
private MQClientAPIFactory mqClientAPIFactory;
- @BeforeEach
- void setUp() {
+ @Before
+ public void setUp() {
scheduledExecutorService = ThreadUtils.newSingleThreadScheduledExecutor("TestScheduledExecutorService", true);
}
- @AfterEach
+ @After
public void tearDown() {
scheduledExecutorService.shutdownNow();
}
@Test
- void testInitWithNamesrvAddr() {
+ public void testInitWithNamesrvAddr() {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
mqClientAPIFactory = new MQClientAPIFactory(
@@ -66,7 +67,7 @@ class MQClientAPITest {
}
@Test
- void testInitWithNamesrvDomain() {
+ public void testInitWithNamesrvDomain() {
nameserverAccessConfig = new NameserverAccessConfig("", "test-domain", "");
mqClientAPIFactory = new MQClientAPIFactory(
@@ -82,7 +83,7 @@ class MQClientAPITest {
}
@Test
- void testInitThrowsExceptionWhenBothEmpty() {
+ public void testInitThrowsExceptionWhenBothEmpty() {
nameserverAccessConfig = new NameserverAccessConfig("", "", "");
RuntimeException exception = assertThrows(RuntimeException.class, () -> new MQClientAPIFactory(
@@ -98,7 +99,7 @@ class MQClientAPITest {
}
@Test
- void testStartCreatesClients() throws Exception {
+ public void testStartCreatesClients() throws Exception {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
mqClientAPIFactory = new MQClientAPIFactory(
@@ -122,7 +123,7 @@ class MQClientAPITest {
}
@Test
- void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
+ public void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
mqClientAPIFactory = new MQClientAPIFactory(
@@ -141,6 +142,6 @@ class MQClientAPITest {
MQClientAPIExt client = mqClientAPIFactory.getClient();
List<String> nameServerAddressList = client.getNameServerAddressList();
assertEquals(2, nameServerAddressList.size());
- assertEquals("new-address0", nameServerAddressList.get(0));
+ assertTrue(nameServerAddressList.contains("new-address0"));
}
}
diff --git a/proxy/src/test/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManagerTest.java b/proxy/src/test/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManagerTest.java
index 8c0f1ef549..2e3d2e9aae 100644
--- a/proxy/src/test/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManagerTest.java
+++ b/proxy/src/test/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManagerTest.java
@@ -16,25 +16,24 @@
*/
package org.apache.rocketmq.proxy.service.cert;
-import java.io.FileWriter;
import org.apache.rocketmq.proxy.config.ConfigurationManager;
import org.apache.rocketmq.proxy.config.ProxyConfig;
import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
import org.apache.rocketmq.srvutil.FileWatchService;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.io.TempDir;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
+import java.io.FileWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -49,17 +48,14 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-@ExtendWith(MockitoExtension.class)
+@RunWith(MockitoJUnitRunner.class)
public class TlsCertificateManagerTest {
- @TempDir
- Path tempDir;
+ @Rule
+ public TemporaryFolder tempDir = new TemporaryFolder();
private TlsCertificateManager manager;
- @Mock
- private ProxyConfig proxyConfig;
-
@Mock
private TlsCertificateManager.TlsContextReloadListener listener1;
@@ -72,17 +68,13 @@ public class TlsCertificateManagerTest {
private Field configField;
private ProxyConfig originalConfig;
- @BeforeAll
- public static void setUpAll() throws Exception {
+ @Before
+ public void setUp() throws Exception {
ConfigurationManager.initEnv();
ConfigurationManager.intConfig();
- }
-
- @BeforeEach
- public void setUp() throws Exception {
// Create temporary certificate and key files
- certFile = new File(tempDir.toFile(), "server.crt");
- keyFile = new File(tempDir.toFile(), "server.key");
+ certFile = tempDir.newFile("server.crt");
+ keyFile = tempDir.newFile("server.key");
try (FileWriter certWriter = new FileWriter(certFile);
FileWriter keyWriter = new FileWriter(keyFile)) {
certWriter.write("test certificate content");
@@ -100,7 +92,7 @@ public class TlsCertificateManagerTest {
fileWatchListener = extractFileWatchListener(manager);
}
- @AfterEach
+ @After
public void tearDown() throws Exception {
// Restore the original config
if (configField != null && originalConfig != null) {