Skip to content

Commit 5298afd

Browse files
lovepoembeiwei30
authored andcommitted
Upgrade junt to junit5 (#3149)
* upgrade junit to junit5 * modify test * 批量修改upgrade_junt_to_junit5 * 删除多余的文件 * fi test case * Disabled soem test case temporarily * upgrade junit to junit5 and batch modify test case * copy some code from jupiter5.4.0.M1 for some issues * 修改rat福泽 * update rat path * revert case * add junit-platform-surefire-provider to maven-surefire-plugin * update dependency * fix coverage issue (#1) * use jupiter 5.4.0-M1 and remove junit5 source code
1 parent 460c3a1 commit 5298afd

File tree

336 files changed

+4613
-4293
lines changed

Some content is hidden

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

336 files changed

+4613
-4293
lines changed

dubbo-all/pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,16 @@
398398

399399
<!-- Temporarily add this part to exclude transitive dependency -->
400400
<dependency>
401-
<groupId>junit</groupId>
402-
<artifactId>junit</artifactId>
403-
<version>${junit_version}</version>
401+
<groupId>org.junit.jupiter</groupId>
402+
<artifactId>junit-jupiter-engine</artifactId>
403+
<version>${junit_jupiter_version}</version>
404+
<scope>test</scope>
405+
</dependency>
406+
<dependency>
407+
<groupId>org.junit.jupiter</groupId>
408+
<artifactId>junit-jupiter-params</artifactId>
409+
<version>${junit_jupiter_version}</version>
404410
<scope>test</scope>
405-
<optional>true</optional>
406411
</dependency>
407412
<dependency>
408413
<groupId>cglib</groupId>

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.apache.dubbo.rpc.RpcResult;
2929
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
3030

31-
import org.junit.Assert;
32-
import org.junit.Before;
33-
import org.junit.Test;
31+
import org.junit.jupiter.api.Assertions;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3434

3535
import java.util.ArrayList;
3636
import java.util.List;
@@ -56,7 +56,7 @@ public class StickyTest {
5656
);
5757
private int runs = 1;
5858

59-
@Before
59+
@BeforeEach
6060
public void setUp() throws Exception {
6161
dic = mock(Directory.class);
6262
invocation = new RpcInvocation();
@@ -77,34 +77,34 @@ public void setUp() throws Exception {
7777
public void testStickyNoCheck() {
7878
int count = testSticky(null, false);
7979
System.out.println(count);
80-
Assert.assertTrue(count > 0 && count <= runs);
80+
Assertions.assertTrue(count > 0 && count <= runs);
8181
}
8282

8383
@Test
8484
public void testStickyForceCheck() {
8585
int count = testSticky(null, true);
86-
Assert.assertTrue(count == 0 || count == runs);
86+
Assertions.assertTrue(count == 0 || count == runs);
8787
}
8888

8989
@Test
9090
public void testMethodStickyNoCheck() {
9191
int count = testSticky("method1", false);
9292
System.out.println(count);
93-
Assert.assertTrue(count > 0 && count <= runs);
93+
Assertions.assertTrue(count > 0 && count <= runs);
9494
}
9595

9696
@Test
9797
public void testMethodStickyForceCheck() {
9898
int count = testSticky("method1", true);
99-
Assert.assertTrue(count == 0 || count == runs);
99+
Assertions.assertTrue(count == 0 || count == runs);
100100
}
101101

102102
@Test
103103
public void testMethodsSticky() {
104104
for (int i = 0; i < 100; i++) {//Two different methods should always use the same invoker every time.
105105
int count1 = testSticky("method1", true);
106106
int count2 = testSticky("method2", true);
107-
Assert.assertTrue(count1 == count2);
107+
Assertions.assertTrue(count1 == count2);
108108
}
109109
}
110110

@@ -129,7 +129,7 @@ public int testSticky(String methodName, boolean check) {
129129

130130
int count = 0;
131131
for (int i = 0; i < runs; i++) {
132-
Assert.assertEquals(null, clusterinvoker.invoke(invocation));
132+
Assertions.assertEquals(null, clusterinvoker.invoke(invocation));
133133
if (invoker1 == clusterinvoker.getSelectedInvoker()) {
134134
count++;
135135
}

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/absent/AbsentConfiguratorTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.apache.dubbo.common.utils.NetUtils;
2121
import org.apache.dubbo.rpc.cluster.configurator.consts.UrlConstant;
2222

23-
import org.junit.Assert;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* OverrideConfiguratorTest
@@ -34,35 +34,35 @@ public void testOverrideApplication() {
3434
AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://[email protected]/com.foo.BarService?timeout=200"));
3535

3636
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
37-
Assert.assertEquals("200", url.getParameter("timeout"));
37+
Assertions.assertEquals("200", url.getParameter("timeout"));
3838

3939
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
40-
Assert.assertEquals("1000", url.getParameter("timeout"));
40+
Assertions.assertEquals("1000", url.getParameter("timeout"));
4141

4242
url = configurator.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_11));
43-
Assert.assertNull(url.getParameter("timeout"));
43+
Assertions.assertNull(url.getParameter("timeout"));
4444

4545
url = configurator.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_11));
46-
Assert.assertEquals("1000", url.getParameter("timeout"));
46+
Assertions.assertEquals("1000", url.getParameter("timeout"));
4747
}
4848

4949
@Test
5050
public void testOverrideHost() {
5151
AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://" + NetUtils.getLocalHost() + "/com.foo.BarService?timeout=200"));
5252

5353
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
54-
Assert.assertEquals("200", url.getParameter("timeout"));
54+
Assertions.assertEquals("200", url.getParameter("timeout"));
5555

5656
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
57-
Assert.assertEquals("1000", url.getParameter("timeout"));
57+
Assertions.assertEquals("1000", url.getParameter("timeout"));
5858

5959
AbsentConfigurator configurator1 = new AbsentConfigurator(URL.valueOf(UrlConstant.SERVICE_TIMEOUT_200));
6060

6161
url = configurator1.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_10));
62-
Assert.assertNull(url.getParameter("timeout"));
62+
Assertions.assertNull(url.getParameter("timeout"));
6363

6464
url = configurator1.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_10));
65-
Assert.assertEquals("1000", url.getParameter("timeout"));
65+
Assertions.assertEquals("1000", url.getParameter("timeout"));
6666
}
6767

6868
}

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/override/OverrideConfiguratorTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.dubbo.rpc.cluster.configurator.absent.AbsentConfigurator;
2222
import org.apache.dubbo.rpc.cluster.configurator.consts.UrlConstant;
2323

24-
import org.junit.Assert;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* OverrideConfiguratorTest
@@ -34,35 +34,35 @@ public void testOverride_Application() {
3434
OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://[email protected]/com.foo.BarService?timeout=200"));
3535

3636
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
37-
Assert.assertEquals("200", url.getParameter("timeout"));
37+
Assertions.assertEquals("200", url.getParameter("timeout"));
3838

3939
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
40-
Assert.assertEquals("200", url.getParameter("timeout"));
40+
Assertions.assertEquals("200", url.getParameter("timeout"));
4141

4242
url = configurator.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_11));
43-
Assert.assertNull(url.getParameter("timeout"));
43+
Assertions.assertNull(url.getParameter("timeout"));
4444

4545
url = configurator.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_11));
46-
Assert.assertEquals("1000", url.getParameter("timeout"));
46+
Assertions.assertEquals("1000", url.getParameter("timeout"));
4747
}
4848

4949
@Test
5050
public void testOverride_Host() {
5151
OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://" + NetUtils.getLocalHost() + "/com.foo.BarService?timeout=200"));
5252

5353
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
54-
Assert.assertEquals("200", url.getParameter("timeout"));
54+
Assertions.assertEquals("200", url.getParameter("timeout"));
5555

5656
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
57-
Assert.assertEquals("200", url.getParameter("timeout"));
57+
Assertions.assertEquals("200", url.getParameter("timeout"));
5858

5959
AbsentConfigurator configurator1 = new AbsentConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
6060

6161
url = configurator1.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_10));
62-
Assert.assertNull(url.getParameter("timeout"));
62+
Assertions.assertNull(url.getParameter("timeout"));
6363

6464
url = configurator1.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_10));
65-
Assert.assertEquals("1000", url.getParameter("timeout"));
65+
Assertions.assertEquals("1000", url.getParameter("timeout"));
6666
}
6767

6868
}

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfigItem;
2222
import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfiguratorConfig;
2323

24-
import org.junit.Assert;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.Test;
2626
import org.yaml.snakeyaml.TypeDescription;
2727
import org.yaml.snakeyaml.Yaml;
2828
import org.yaml.snakeyaml.constructor.Constructor;
@@ -44,7 +44,7 @@ private String streamToString(InputStream stream) throws IOException {
4444

4545
@Test
4646
public void snakeYamlBasicTest() throws IOException {
47-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
47+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
4848

4949
Constructor constructor = new Constructor(ConfiguratorConfig.class);
5050
TypeDescription carDescription = new TypeDescription(ConfiguratorConfig.class);
@@ -59,109 +59,111 @@ public void snakeYamlBasicTest() throws IOException {
5959

6060
@Test
6161
public void parseConfiguratorsServiceNoAppTest() throws Exception {
62-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
62+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
6363
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
64-
Assert.assertNotNull(urls);
65-
Assert.assertEquals(2, urls.size());
64+
Assertions.assertNotNull(urls);
65+
Assertions.assertEquals(2, urls.size());
6666
URL url = urls.get(0);
67-
Assert.assertEquals(url.getAddress(), "127.0.0.1:20880");
68-
Assert.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222);
67+
Assertions.assertEquals(url.getAddress(), "127.0.0.1:20880");
68+
Assertions.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222);
6969
}
7070
}
7171

7272
@Test
7373
public void parseConfiguratorsServiceGroupVersionTest() throws Exception {
74-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml")) {
74+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml")) {
7575
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
76-
Assert.assertNotNull(urls);
77-
Assert.assertEquals(1, urls.size());
76+
Assertions.assertNotNull(urls);
77+
Assertions.assertEquals(1, urls.size());
7878
URL url = urls.get(0);
79-
Assert.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
80-
Assert.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY));
79+
Assertions.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
80+
Assertions.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY));
8181
}
8282
}
8383

8484
@Test
8585
public void parseConfiguratorsServiceMultiAppsTest() throws IOException {
86-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml")) {
86+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml")) {
8787
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
88-
Assert.assertNotNull(urls);
89-
Assert.assertEquals(4, urls.size());
88+
Assertions.assertNotNull(urls);
89+
Assertions.assertEquals(4, urls.size());
9090
URL url = urls.get(0);
91-
Assert.assertEquals("127.0.0.1", url.getAddress());
92-
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
93-
Assert.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
91+
Assertions.assertEquals("127.0.0.1", url.getAddress());
92+
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
93+
Assertions.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
9494
}
9595
}
9696

97-
@Test(expected = IllegalStateException.class)
98-
public void parseConfiguratorsServiceNoRuleTest() throws IOException {
99-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) {
100-
ConfigParser.parseConfigurators(streamToString(yamlStream));
101-
Assert.fail();
102-
}
97+
@Test
98+
public void parseConfiguratorsServiceNoRuleTest() {
99+
Assertions.assertThrows(IllegalStateException.class, () -> {
100+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) {
101+
ConfigParser.parseConfigurators(streamToString(yamlStream));
102+
Assertions.fail();
103+
}
104+
});
103105
}
104106

105107
@Test
106108
public void parseConfiguratorsAppMultiServicesTest() throws IOException {
107-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml")) {
109+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml")) {
108110
String yamlFile = streamToString(yamlStream);
109111
List<URL> urls = ConfigParser.parseConfigurators(yamlFile);
110-
Assert.assertNotNull(urls);
111-
Assert.assertEquals(4, urls.size());
112+
Assertions.assertNotNull(urls);
113+
Assertions.assertEquals(4, urls.size());
112114
URL url = urls.get(0);
113-
Assert.assertEquals("127.0.0.1", url.getAddress());
114-
Assert.assertEquals("service1", url.getServiceInterface());
115-
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
116-
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
117-
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
115+
Assertions.assertEquals("127.0.0.1", url.getAddress());
116+
Assertions.assertEquals("service1", url.getServiceInterface());
117+
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
118+
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
119+
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
118120
}
119121
}
120122

121123

122124
@Test
123125
public void parseConfiguratorsAppAnyServicesTest() throws IOException {
124-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml")) {
126+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml")) {
125127
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
126-
Assert.assertNotNull(urls);
127-
Assert.assertEquals(2, urls.size());
128+
Assertions.assertNotNull(urls);
129+
Assertions.assertEquals(2, urls.size());
128130
URL url = urls.get(0);
129-
Assert.assertEquals("127.0.0.1", url.getAddress());
130-
Assert.assertEquals("*", url.getServiceInterface());
131-
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
132-
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
133-
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
131+
Assertions.assertEquals("127.0.0.1", url.getAddress());
132+
Assertions.assertEquals("*", url.getServiceInterface());
133+
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
134+
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
135+
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
134136
}
135137
}
136138

137139
@Test
138140
public void parseConfiguratorsAppNoServiceTest() throws IOException {
139-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml")) {
141+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml")) {
140142
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
141-
Assert.assertNotNull(urls);
142-
Assert.assertEquals(1, urls.size());
143+
Assertions.assertNotNull(urls);
144+
Assertions.assertEquals(1, urls.size());
143145
URL url = urls.get(0);
144-
Assert.assertEquals("127.0.0.1", url.getAddress());
145-
Assert.assertEquals("*", url.getServiceInterface());
146-
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
147-
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
148-
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
146+
Assertions.assertEquals("127.0.0.1", url.getAddress());
147+
Assertions.assertEquals("*", url.getServiceInterface());
148+
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
149+
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
150+
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
149151
}
150152
}
151153

152154
@Test
153155
public void parseConsumerSpecificProvidersTest() throws IOException {
154-
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml")) {
156+
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml")) {
155157
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
156-
Assert.assertNotNull(urls);
157-
Assert.assertEquals(1, urls.size());
158+
Assertions.assertNotNull(urls);
159+
Assertions.assertEquals(1, urls.size());
158160
URL url = urls.get(0);
159-
Assert.assertEquals("127.0.0.1", url.getAddress());
160-
Assert.assertEquals("*", url.getServiceInterface());
161-
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
162-
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
163-
Assert.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY));
164-
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
161+
Assertions.assertEquals("127.0.0.1", url.getAddress());
162+
Assertions.assertEquals("*", url.getServiceInterface());
163+
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
164+
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
165+
Assertions.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY));
166+
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
165167
}
166168
}
167169

0 commit comments

Comments
 (0)