Skip to content

Commit 1c7196e

Browse files
authored
test: migrate unit tests from JUnit 4 to JUnit 5 in code-generator, configcenter and limiter modules (#119)
* trpc-admin: migrate junit4 to junit5 and upgrade resteasy * feat(admin): Upgrade Jakarta EE dependencies for RESTEasy 6.x compatibility * trpc-code-generator/trpc-configcenter/trpc-limiter: migrate tests to JUnit 5 for Spring Boot 3.x compatibility * chore(configcenter-nacos): remove obsolete TODO comment from test file
1 parent 61c9bd2 commit 1c7196e

25 files changed

Lines changed: 300 additions & 285 deletions

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodeGenerateTest.java

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodegenTestHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.tencent.trpc.codegen.protoc.Protoc;
1616
import com.tencent.trpc.codegen.protoc.ProtocTest;
1717
import com.tencent.trpc.codegen.util.JarUtils;
18-
import org.junit.Assert;
1918
import java.io.File;
2019
import java.io.IOException;
2120
import java.net.URISyntaxException;
@@ -25,6 +24,7 @@
2524
import java.nio.file.Paths;
2625
import java.util.Iterator;
2726
import java.util.jar.JarFile;
27+
import org.junit.jupiter.api.Assertions;
2828

2929
public class CodegenTestHelper {
3030
public static final Path TEST_ROOT = getTestClassesRoot(); // target/test-classes
@@ -34,13 +34,13 @@ public class CodegenTestHelper {
3434

3535
private static Path getTestClassesRoot() {
3636
URL url = ProtocTest.class.getClassLoader().getResource("TEST-1/hello.proto");
37-
Assert.assertNotNull(url);
37+
Assertions.assertNotNull(url);
3838
return Paths.get(url.getPath()).getParent().getParent();
3939
}
4040

4141
private static Path getImportRoot() {
4242
URL url = Protoc.class.getClassLoader().getResource("imports/trpc.proto");
43-
Assert.assertNotNull(url);
43+
Assertions.assertNotNull(url);
4444
Path importRoot = Paths.get(url.getPath()).getParent();
4545
try {
4646
extractCommonProtoFiles(importRoot);

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protobuf/DescriptorProtoCompileTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import com.google.protobuf.Descriptors.FileDescriptor;
1616
import com.tencent.trpc.codegen.CodegenTestHelper;
1717
import com.tencent.trpc.codegen.protoc.ProtocTest;
18-
import org.junit.Assert;
19-
import org.junit.BeforeClass;
20-
import org.junit.Test;
18+
import org.junit.jupiter.api.Assertions;
19+
import org.junit.jupiter.api.BeforeAll;
20+
import org.junit.jupiter.api.Test;
2121
import java.io.IOException;
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
@@ -26,7 +26,7 @@
2626
public class DescriptorProtoCompileTest {
2727
private static final Path rootPath = CodegenTestHelper.TEST_ROOT;
2828

29-
@BeforeClass
29+
@BeforeAll
3030
public static void prepare() {
3131
Path descriptorFile = rootPath.resolve("hello.pb");
3232
if (!Files.exists(descriptorFile)) {
@@ -39,11 +39,11 @@ public static void prepare() {
3939
public void testParseProtoDescriptorSet() throws IOException {
4040
Path descriptorFile = rootPath.resolve("hello.pb");
4141
FileDescriptorSet set = ProtoParser.parseDescriptorSetFile(descriptorFile);
42-
Assert.assertEquals(5, set.getFileCount());
42+
Assertions.assertEquals(5, set.getFileCount());
4343
FileDescriptorsCompiler compiler = new FileDescriptorsCompiler(set.getFileList());
4444
List<FileDescriptor> fdList = compiler.compile();
45-
Assert.assertEquals(5, fdList.size());
45+
Assertions.assertEquals(5, fdList.size());
4646
ProtoSourceInfo sourceInfo = ProtoParser.parseFileDescriptors(fdList);
47-
Assert.assertEquals(1, sourceInfo.getServices().size());
47+
Assertions.assertEquals(1, sourceInfo.getServices().size());
4848
}
4949
}

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protoc/ProtocTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
package com.tencent.trpc.codegen.protoc;
1313

1414
import com.tencent.trpc.codegen.CodegenTestHelper;
15-
import org.junit.Assert;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.Assertions;
16+
import org.junit.jupiter.api.Test;
1717
import java.io.IOException;
1818
import java.nio.file.Files;
1919
import java.nio.file.Path;
@@ -37,7 +37,7 @@ public void testGenerateDescriptorSet() {
3737
.importPaths(Collections.singletonList(importPath))
3838
.output(rootPath.resolve("hello.pb"))
3939
.build());
40-
Assert.assertTrue(result.isSuccess());
40+
Assertions.assertTrue(result.isSuccess());
4141
}
4242

4343
/**
@@ -52,7 +52,7 @@ public void testGenerateDescriptorSetError() {
5252
.importPaths(Collections.singletonList(importPath))
5353
.output(rootPath.resolve("hello2.pb"))
5454
.build());
55-
Assert.assertFalse(result.isSuccess());
55+
Assertions.assertFalse(result.isSuccess());
5656
}
5757

5858
/**
@@ -67,7 +67,7 @@ public void testGenerateDescriptorSetFailed() {
6767
.importPaths(Collections.singletonList(importPath))
6868
.output(rootPath.resolve("non-exist.pb"))
6969
.build());
70-
Assert.assertFalse(result.isSuccess());
70+
Assertions.assertFalse(result.isSuccess());
7171
}
7272

7373
/**
@@ -85,6 +85,6 @@ public void testGenerateStub() throws IOException {
8585
.language(Language.JAVA)
8686
.output(outPath)
8787
.build());
88-
Assert.assertTrue(result.isSuccess());
88+
Assertions.assertTrue(result.isSuccess());
8989
}
9090
}

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/FreeMarkerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import freemarker.template.Configuration;
1515
import freemarker.template.Template;
1616
import freemarker.template.TemplateException;
17-
import org.junit.Test;
17+
import org.junit.jupiter.api.Test;
1818
import java.io.IOException;
1919
import java.io.StringWriter;
2020
import java.util.HashMap;

trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/TemplateEngineTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
package com.tencent.trpc.codegen.template;
1313

1414
import java.util.Map;
15-
import org.junit.Assert;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.Assertions;
16+
import org.junit.jupiter.api.Test;
1717

1818
public class TemplateEngineTest {
1919

@@ -30,6 +30,6 @@ public void testTemplateEngine() {
3030
+ " <#assign name = rtxName>\n"
3131
+ "</#if>\n"
3232
+ "hello ${name}!", context);
33-
Assert.assertEquals("hello kelgonwu!", text);
33+
Assertions.assertEquals("hello kelgonwu!", text);
3434
}
3535
}

trpc-configcenter/trpc-configcenter-nacos/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,15 @@
2121
<groupId>com.fasterxml.jackson.dataformat</groupId>
2222
<artifactId>jackson-dataformat-properties</artifactId>
2323
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-test</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.mockito</groupId>
31+
<artifactId>mockito-core</artifactId>
32+
<scope>test</scope>
33+
</dependency>
2434
</dependencies>
2535
</project>

0 commit comments

Comments
 (0)