Skip to content

Commit 1c83b11

Browse files
authored
[ISSUE #9658] Replace JUnit 5 imports with JUnit 4 (#9659)
* [ISSUE #9658] Replace JUnit 5 imports with JUnit 4 * Update test
1 parent 64999c1 commit 1c83b11

2 files changed

Lines changed: 32 additions & 39 deletions

File tree

client/src/test/java/org/apache/rocketmq/client/impl/mqclient/MQClientAPITest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
package org.apache.rocketmq.client.impl.mqclient;
1919

20-
import static org.junit.jupiter.api.Assertions.assertEquals;
21-
import static org.junit.jupiter.api.Assertions.assertThrows;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertThrows;
22+
import static org.junit.Assert.assertTrue;
2223

2324
import java.util.List;
2425
import java.util.concurrent.ScheduledExecutorService;
@@ -27,30 +28,30 @@
2728
import org.apache.rocketmq.common.MixAll;
2829
import org.apache.rocketmq.common.utils.ThreadUtils;
2930
import org.apache.rocketmq.remoting.RPCHook;
30-
import org.junit.jupiter.api.AfterEach;
31-
import org.junit.jupiter.api.BeforeEach;
32-
import org.junit.jupiter.api.Test;
31+
import org.junit.After;
32+
import org.junit.Before;
33+
import org.junit.Test;
3334

34-
class MQClientAPITest {
35+
public class MQClientAPITest {
3536

3637
private NameserverAccessConfig nameserverAccessConfig;
3738
private final ClientRemotingProcessor clientRemotingProcessor = new DoNothingClientRemotingProcessor(null);
3839
private final RPCHook rpcHook = null;
3940
private ScheduledExecutorService scheduledExecutorService;
4041
private MQClientAPIFactory mqClientAPIFactory;
4142

42-
@BeforeEach
43-
void setUp() {
43+
@Before
44+
public void setUp() {
4445
scheduledExecutorService = ThreadUtils.newSingleThreadScheduledExecutor("TestScheduledExecutorService", true);
4546
}
4647

47-
@AfterEach
48+
@After
4849
public void tearDown() {
4950
scheduledExecutorService.shutdownNow();
5051
}
5152

5253
@Test
53-
void testInitWithNamesrvAddr() {
54+
public void testInitWithNamesrvAddr() {
5455
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
5556

5657
mqClientAPIFactory = new MQClientAPIFactory(
@@ -66,7 +67,7 @@ void testInitWithNamesrvAddr() {
6667
}
6768

6869
@Test
69-
void testInitWithNamesrvDomain() {
70+
public void testInitWithNamesrvDomain() {
7071
nameserverAccessConfig = new NameserverAccessConfig("", "test-domain", "");
7172

7273
mqClientAPIFactory = new MQClientAPIFactory(
@@ -82,7 +83,7 @@ void testInitWithNamesrvDomain() {
8283
}
8384

8485
@Test
85-
void testInitThrowsExceptionWhenBothEmpty() {
86+
public void testInitThrowsExceptionWhenBothEmpty() {
8687
nameserverAccessConfig = new NameserverAccessConfig("", "", "");
8788

8889
RuntimeException exception = assertThrows(RuntimeException.class, () -> new MQClientAPIFactory(
@@ -98,7 +99,7 @@ void testInitThrowsExceptionWhenBothEmpty() {
9899
}
99100

100101
@Test
101-
void testStartCreatesClients() throws Exception {
102+
public void testStartCreatesClients() throws Exception {
102103
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
103104

104105
mqClientAPIFactory = new MQClientAPIFactory(
@@ -122,7 +123,7 @@ void testStartCreatesClients() throws Exception {
122123
}
123124

124125
@Test
125-
void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
126+
public void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
126127
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
127128

128129
mqClientAPIFactory = new MQClientAPIFactory(
@@ -141,6 +142,6 @@ void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
141142
MQClientAPIExt client = mqClientAPIFactory.getClient();
142143
List<String> nameServerAddressList = client.getNameServerAddressList();
143144
assertEquals(2, nameServerAddressList.size());
144-
assertEquals("new-address0", nameServerAddressList.get(0));
145+
assertTrue(nameServerAddressList.contains("new-address0"));
145146
}
146147
}

proxy/src/test/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManagerTest.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616
*/
1717
package org.apache.rocketmq.proxy.service.cert;
1818

19-
import java.io.FileWriter;
2019
import org.apache.rocketmq.proxy.config.ConfigurationManager;
2120
import org.apache.rocketmq.proxy.config.ProxyConfig;
2221
import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
2322
import org.apache.rocketmq.srvutil.FileWatchService;
24-
import org.junit.jupiter.api.AfterEach;
25-
import org.junit.jupiter.api.BeforeAll;
26-
import org.junit.jupiter.api.BeforeEach;
27-
import org.junit.jupiter.api.Test;
28-
import org.junit.jupiter.api.extension.ExtendWith;
29-
import org.junit.jupiter.api.io.TempDir;
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
import org.junit.rules.TemporaryFolder;
28+
import org.junit.runner.RunWith;
3029
import org.mockito.Mock;
31-
import org.mockito.junit.jupiter.MockitoExtension;
30+
import org.mockito.junit.MockitoJUnitRunner;
3231

3332
import java.io.File;
33+
import java.io.FileWriter;
3434
import java.lang.reflect.Constructor;
3535
import java.lang.reflect.Field;
3636
import java.lang.reflect.Method;
37-
import java.nio.file.Path;
3837
import java.util.List;
3938

4039
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -49,17 +48,14 @@
4948
import static org.mockito.Mockito.times;
5049
import static org.mockito.Mockito.verify;
5150

52-
@ExtendWith(MockitoExtension.class)
51+
@RunWith(MockitoJUnitRunner.class)
5352
public class TlsCertificateManagerTest {
5453

55-
@TempDir
56-
Path tempDir;
54+
@Rule
55+
public TemporaryFolder tempDir = new TemporaryFolder();
5756

5857
private TlsCertificateManager manager;
5958

60-
@Mock
61-
private ProxyConfig proxyConfig;
62-
6359
@Mock
6460
private TlsCertificateManager.TlsContextReloadListener listener1;
6561

@@ -72,17 +68,13 @@ public class TlsCertificateManagerTest {
7268
private Field configField;
7369
private ProxyConfig originalConfig;
7470

75-
@BeforeAll
76-
public static void setUpAll() throws Exception {
71+
@Before
72+
public void setUp() throws Exception {
7773
ConfigurationManager.initEnv();
7874
ConfigurationManager.intConfig();
79-
}
80-
81-
@BeforeEach
82-
public void setUp() throws Exception {
8375
// Create temporary certificate and key files
84-
certFile = new File(tempDir.toFile(), "server.crt");
85-
keyFile = new File(tempDir.toFile(), "server.key");
76+
certFile = tempDir.newFile("server.crt");
77+
keyFile = tempDir.newFile("server.key");
8678
try (FileWriter certWriter = new FileWriter(certFile);
8779
FileWriter keyWriter = new FileWriter(keyFile)) {
8880
certWriter.write("test certificate content");
@@ -100,7 +92,7 @@ public void setUp() throws Exception {
10092
fileWatchListener = extractFileWatchListener(manager);
10193
}
10294

103-
@AfterEach
95+
@After
10496
public void tearDown() throws Exception {
10597
// Restore the original config
10698
if (configField != null && originalConfig != null) {

0 commit comments

Comments
 (0)