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 965c5ae16b6..698aa1e97d4 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.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 @@ void testInitWithNamesrvAddr() { } @Test - void testInitWithNamesrvDomain() { + public void testInitWithNamesrvDomain() { nameserverAccessConfig = new NameserverAccessConfig("", "test-domain", ""); mqClientAPIFactory = new MQClientAPIFactory( @@ -82,7 +83,7 @@ void testInitWithNamesrvDomain() { } @Test - void testInitThrowsExceptionWhenBothEmpty() { + public void testInitThrowsExceptionWhenBothEmpty() { nameserverAccessConfig = new NameserverAccessConfig("", "", ""); RuntimeException exception = assertThrows(RuntimeException.class, () -> new MQClientAPIFactory( @@ -98,7 +99,7 @@ void testInitThrowsExceptionWhenBothEmpty() { } @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 @@ void testStartCreatesClients() throws Exception { } @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 @@ void testOnNameServerAddressChangeUpdatesAllClients() throws Exception { MQClientAPIExt client = mqClientAPIFactory.getClient(); List 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 8c0f1ef549e..2e3d2e9aaee 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.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 void setUp() throws Exception { fileWatchListener = extractFileWatchListener(manager); } - @AfterEach + @After public void tearDown() throws Exception { // Restore the original config if (configField != null && originalConfig != null) {