diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodeGenerateTest.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodeGenerateTest.java index 3882ff424c..bdd699505a 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodeGenerateTest.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodeGenerateTest.java @@ -32,8 +32,8 @@ import java.util.List; import java.util.Map; import org.apache.commons.codec.digest.DigestUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CodeGenerateTest { @@ -50,11 +50,11 @@ public void testTRpcCase1() throws IOException { runTest(Protocol.TRPC, "TEST-1"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("6eaef685e6b986ce56e3bcc7d14e1c4c", + Assertions.assertEquals("6eaef685e6b986ce56e3bcc7d14e1c4c", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("23446b6413c80bf8a1aa6ee234c6fba9", + Assertions.assertEquals("23446b6413c80bf8a1aa6ee234c6fba9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("9caa57d08d0b3fcb9d617ac8d8d135e5", + Assertions.assertEquals("9caa57d08d0b3fcb9d617ac8d8d135e5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -67,11 +67,11 @@ public void testGRpcCase1() throws IOException { runTest(Protocol.GRPC, "TEST-1"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("7c9a444f814fb2881053aaff9d227db6", + Assertions.assertEquals("7c9a444f814fb2881053aaff9d227db6", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("23446b6413c80bf8a1aa6ee234c6fba9", + Assertions.assertEquals("23446b6413c80bf8a1aa6ee234c6fba9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("9caa57d08d0b3fcb9d617ac8d8d135e5", + Assertions.assertEquals("9caa57d08d0b3fcb9d617ac8d8d135e5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -84,13 +84,13 @@ public void testTRpcCase2() throws IOException { runTest(Protocol.TRPC, "TEST-2"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("7c9944d4b57d3c5bcf0e0e41e543322d", + Assertions.assertEquals("7c9944d4b57d3c5bcf0e0e41e543322d", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("075e5962815321ae423bc38165fdf303", + Assertions.assertEquals("075e5962815321ae423bc38165fdf303", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("285ef96d563b7b5f87472ebb218f1624", + Assertions.assertEquals("285ef96d563b7b5f87472ebb218f1624", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("2eb8ad08c973e8cb107cc596db1709b1", + Assertions.assertEquals("2eb8ad08c973e8cb107cc596db1709b1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -103,13 +103,13 @@ public void testGRpcCase2() throws IOException { runTest(Protocol.GRPC, "TEST-2"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("c61eda56e21950f11615ac0a6c2d5fe8", + Assertions.assertEquals("c61eda56e21950f11615ac0a6c2d5fe8", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("075e5962815321ae423bc38165fdf303", + Assertions.assertEquals("075e5962815321ae423bc38165fdf303", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("be4038417c2098b60a7af42e73c1abf6", + Assertions.assertEquals("be4038417c2098b60a7af42e73c1abf6", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("2eb8ad08c973e8cb107cc596db1709b1", + Assertions.assertEquals("2eb8ad08c973e8cb107cc596db1709b1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -122,15 +122,15 @@ public void testTRpcCase3() throws IOException { runTest(Protocol.TRPC, "TEST-3"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("c817495291050d99de03589c0b2840bf", + Assertions.assertEquals("c817495291050d99de03589c0b2840bf", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", + Assertions.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("926fcc803803125fc0910f4b7c309b26", + Assertions.assertEquals("926fcc803803125fc0910f4b7c309b26", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", + Assertions.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); - Assert.assertEquals("fa93e09f70c157d59019dd62610cb4f3", + Assertions.assertEquals("fa93e09f70c157d59019dd62610cb4f3", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("msg").resolve("Hello.java")))); } @@ -143,15 +143,15 @@ public void testGRpcCase3() throws IOException { runTest(Protocol.GRPC, "TEST-3"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("a3bcaeb3ec937819eb26fe3a60219957", + Assertions.assertEquals("a3bcaeb3ec937819eb26fe3a60219957", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", + Assertions.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("e8108341efbc3d36bf3dcc9ba8ea0b41", + Assertions.assertEquals("e8108341efbc3d36bf3dcc9ba8ea0b41", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", + Assertions.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); - Assert.assertEquals("fa93e09f70c157d59019dd62610cb4f3", + Assertions.assertEquals("fa93e09f70c157d59019dd62610cb4f3", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("msg").resolve("Hello.java")))); } @@ -164,19 +164,19 @@ public void testTRpcCase4() throws IOException { runTest(Protocol.TRPC, "TEST-4"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("trpc", "exp", "helloworld")); - Assert.assertEquals("b5e67d899ef1885461d791a22631e49b", + Assertions.assertEquals("b5e67d899ef1885461d791a22631e49b", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("b7640a2fe62a3464ad25d0be603d1966", + Assertions.assertEquals("b7640a2fe62a3464ad25d0be603d1966", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("608f0a195f7e542aa11be2ff5fb82199", + Assertions.assertEquals("608f0a195f7e542aa11be2ff5fb82199", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloRequest.java")))); - Assert.assertEquals("01e5a8f2f794ee7c81873fc62c93c31a", + Assertions.assertEquals("01e5a8f2f794ee7c81873fc62c93c31a", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloRequestOrBuilder.java")))); - Assert.assertEquals("d24f652118fcd17e03b65c7423b71fbf", + Assertions.assertEquals("d24f652118fcd17e03b65c7423b71fbf", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloReply.java")))); - Assert.assertEquals("d0341d2cdbeaca4557c25e6f07c65458", + Assertions.assertEquals("d0341d2cdbeaca4557c25e6f07c65458", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloReplyOrBuilder.java")))); - Assert.assertEquals("cbea0bc31f8ce927120b77c4b26475d5", + Assertions.assertEquals("cbea0bc31f8ce927120b77c4b26475d5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloNext.java")))); } @@ -189,19 +189,19 @@ public void testGRpcCase4() throws IOException { runTest(Protocol.GRPC, "TEST-4"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("trpc", "exp", "helloworld")); - Assert.assertEquals("154e3b53d0f034155ff1603998a105a5", + Assertions.assertEquals("154e3b53d0f034155ff1603998a105a5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("b7640a2fe62a3464ad25d0be603d1966", + Assertions.assertEquals("b7640a2fe62a3464ad25d0be603d1966", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("608f0a195f7e542aa11be2ff5fb82199", + Assertions.assertEquals("608f0a195f7e542aa11be2ff5fb82199", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloRequest.java")))); - Assert.assertEquals("01e5a8f2f794ee7c81873fc62c93c31a", + Assertions.assertEquals("01e5a8f2f794ee7c81873fc62c93c31a", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloRequestOrBuilder.java")))); - Assert.assertEquals("d24f652118fcd17e03b65c7423b71fbf", + Assertions.assertEquals("d24f652118fcd17e03b65c7423b71fbf", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloReply.java")))); - Assert.assertEquals("d0341d2cdbeaca4557c25e6f07c65458", + Assertions.assertEquals("d0341d2cdbeaca4557c25e6f07c65458", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloReplyOrBuilder.java")))); - Assert.assertEquals("cbea0bc31f8ce927120b77c4b26475d5", + Assertions.assertEquals("cbea0bc31f8ce927120b77c4b26475d5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloNext.java")))); } @@ -214,13 +214,13 @@ public void testTRpcCase5() throws IOException { runTest(Protocol.TRPC, "TEST-5"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test", "helloworld")); - Assert.assertEquals("c0ac8b85e80f949dd9674a31d2fb28c1", + Assertions.assertEquals("c0ac8b85e80f949dd9674a31d2fb28c1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("3d0ff8da3ace15f1bd055164ec1da4b9", + Assertions.assertEquals("3d0ff8da3ace15f1bd055164ec1da4b9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("b23d158eedf9ea3912703f084ff72ec2", + Assertions.assertEquals("b23d158eedf9ea3912703f084ff72ec2", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); - Assert.assertEquals("9277fefe3ff6af9a95062d359db14ebe", + Assertions.assertEquals("9277fefe3ff6af9a95062d359db14ebe", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceValidator.java")))); } @@ -233,13 +233,13 @@ public void testGRpcCase5() throws IOException { runTest(Protocol.GRPC, "TEST-5"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test", "helloworld")); - Assert.assertEquals("53541c1d2a78e70b8e0b7323b77721bf", + Assertions.assertEquals("53541c1d2a78e70b8e0b7323b77721bf", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("3d0ff8da3ace15f1bd055164ec1da4b9", + Assertions.assertEquals("3d0ff8da3ace15f1bd055164ec1da4b9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("b23d158eedf9ea3912703f084ff72ec2", + Assertions.assertEquals("b23d158eedf9ea3912703f084ff72ec2", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); - Assert.assertEquals("9277fefe3ff6af9a95062d359db14ebe", + Assertions.assertEquals("9277fefe3ff6af9a95062d359db14ebe", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceValidator.java")))); } @@ -252,13 +252,13 @@ public void testTRpcCase6() throws IOException { runTest(Protocol.TRPC, "TEST-6"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("0e292fa89a93a0cbd3ecb51d3ca42b31", + Assertions.assertEquals("0e292fa89a93a0cbd3ecb51d3ca42b31", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("70abf7c48136e3f8d2a08ec15796a47e", + Assertions.assertEquals("70abf7c48136e3f8d2a08ec15796a47e", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("2f519ad1efafb3d145c5847e7831b559", + Assertions.assertEquals("2f519ad1efafb3d145c5847e7831b559", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("62ed6dc1ad9883094281a4bc35416c56", + Assertions.assertEquals("62ed6dc1ad9883094281a4bc35416c56", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloCamelCase.java")))); } @@ -271,13 +271,13 @@ public void testGRpcCase6() throws IOException { runTest(Protocol.GRPC, "TEST-6"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("b0bdf649fa7269a0160846d5302952be", + Assertions.assertEquals("b0bdf649fa7269a0160846d5302952be", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("70abf7c48136e3f8d2a08ec15796a47e", + Assertions.assertEquals("70abf7c48136e3f8d2a08ec15796a47e", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("651a3065ac06e2b157ef7b8ba15bce6a", + Assertions.assertEquals("651a3065ac06e2b157ef7b8ba15bce6a", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("62ed6dc1ad9883094281a4bc35416c56", + Assertions.assertEquals("62ed6dc1ad9883094281a4bc35416c56", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloCamelCase.java")))); } @@ -290,13 +290,13 @@ public void testTRpcCase7() throws IOException { runTest(Protocol.TRPC, "TEST-7"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("a5fe0f6823f80d27574e2051da1ed33e", + Assertions.assertEquals("a5fe0f6823f80d27574e2051da1ed33e", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceAPI.java")))); - Assert.assertEquals("33b88906768a6b7c8b665714dfda8bd1", + Assertions.assertEquals("33b88906768a6b7c8b665714dfda8bd1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceAsyncAPI.java")))); - Assert.assertEquals("777387facf2cbc71228c30de20ed2226", + Assertions.assertEquals("777387facf2cbc71228c30de20ed2226", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceStreamAPI.java")))); - Assert.assertEquals("640d503c66e105c9776037895a406613", + Assertions.assertEquals("640d503c66e105c9776037895a406613", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -309,13 +309,13 @@ public void testGRpcCase7() throws IOException { runTest(Protocol.GRPC, "TEST-7"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("b7b0a488c9e5b4c2f3d789a7e9833e8a", + Assertions.assertEquals("b7b0a488c9e5b4c2f3d789a7e9833e8a", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceAPI.java")))); - Assert.assertEquals("33b88906768a6b7c8b665714dfda8bd1", + Assertions.assertEquals("33b88906768a6b7c8b665714dfda8bd1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceAsyncAPI.java")))); - Assert.assertEquals("a0c28a7babedf863e31740b320857b0f", + Assertions.assertEquals("a0c28a7babedf863e31740b320857b0f", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterServiceStreamAPI.java")))); - Assert.assertEquals("640d503c66e105c9776037895a406613", + Assertions.assertEquals("640d503c66e105c9776037895a406613", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -328,13 +328,13 @@ public void testTRpcCase8() throws IOException { runTest(Protocol.TRPC, "TEST-8"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("2d9780f352044c82bfef69afebeb7da5", + Assertions.assertEquals("2d9780f352044c82bfef69afebeb7da5", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceAPI.java")))); - Assert.assertEquals("4ed1fab5faa4a31c54aa452e54664853", + Assertions.assertEquals("4ed1fab5faa4a31c54aa452e54664853", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceAsyncAPI.java")))); - Assert.assertEquals("446ff8e1c7479bb3f7da2d2c61cdf004", + Assertions.assertEquals("446ff8e1c7479bb3f7da2d2c61cdf004", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceStreamAPI.java")))); - Assert.assertEquals("639e78687054ee0ae8a88749fc3f36c3", + Assertions.assertEquals("639e78687054ee0ae8a88749fc3f36c3", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -347,13 +347,13 @@ public void testGRpcCase8() throws IOException { runTest(Protocol.GRPC, "TEST-8"); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("0cb047dba4e1726c8ac909447962e251", + Assertions.assertEquals("0cb047dba4e1726c8ac909447962e251", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceAPI.java")))); - Assert.assertEquals("4ed1fab5faa4a31c54aa452e54664853", + Assertions.assertEquals("4ed1fab5faa4a31c54aa452e54664853", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceAsyncAPI.java")))); - Assert.assertEquals("8e86f7527ddb01d27b574c6de39270d1", + Assertions.assertEquals("8e86f7527ddb01d27b574c6de39270d1", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("HelloWorldServiceStreamAPI.java")))); - Assert.assertEquals("639e78687054ee0ae8a88749fc3f36c3", + Assertions.assertEquals("639e78687054ee0ae8a88749fc3f36c3", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); } @@ -389,15 +389,15 @@ public Map getCustomVariables(List fileDescripto generator.generateCode(); Path base = getOutputBasePath(); Path java = base.resolve(Paths.get("com", "tencent", "trpc", "codegen", "test")); - Assert.assertEquals("c817495291050d99de03589c0b2840bf", + Assertions.assertEquals("c817495291050d99de03589c0b2840bf", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAPI.java")))); - Assert.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", + Assertions.assertEquals("b8cd07293d73ebb299f1997136b9cfd6", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterAsyncAPI.java")))); - Assert.assertEquals("926fcc803803125fc0910f4b7c309b26", + Assertions.assertEquals("926fcc803803125fc0910f4b7c309b26", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterStreamAPI.java")))); - Assert.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", + Assertions.assertEquals("9feac2c00a6b5fb137e0347e9d3c57a9", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("GreeterService.java")))); - Assert.assertEquals("fa93e09f70c157d59019dd62610cb4f3", + Assertions.assertEquals("fa93e09f70c157d59019dd62610cb4f3", DigestUtils.md5Hex(Files.readAllBytes(java.resolve("msg").resolve("Hello.java")))); } @@ -418,4 +418,4 @@ private void runTest(Protocol protocol, String path) { private Path getOutputBasePath() { return Paths.get("target", "generated-sources", "trpc").toAbsolutePath(); } -} \ No newline at end of file +} diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodegenTestHelper.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodegenTestHelper.java index 6995502e0c..42737549c7 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodegenTestHelper.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/CodegenTestHelper.java @@ -15,7 +15,6 @@ import com.tencent.trpc.codegen.protoc.Protoc; import com.tencent.trpc.codegen.protoc.ProtocTest; import com.tencent.trpc.codegen.util.JarUtils; -import org.junit.Assert; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -25,6 +24,7 @@ import java.nio.file.Paths; import java.util.Iterator; import java.util.jar.JarFile; +import org.junit.jupiter.api.Assertions; public class CodegenTestHelper { public static final Path TEST_ROOT = getTestClassesRoot(); // target/test-classes @@ -34,13 +34,13 @@ public class CodegenTestHelper { private static Path getTestClassesRoot() { URL url = ProtocTest.class.getClassLoader().getResource("TEST-1/hello.proto"); - Assert.assertNotNull(url); + Assertions.assertNotNull(url); return Paths.get(url.getPath()).getParent().getParent(); } private static Path getImportRoot() { URL url = Protoc.class.getClassLoader().getResource("imports/trpc.proto"); - Assert.assertNotNull(url); + Assertions.assertNotNull(url); Path importRoot = Paths.get(url.getPath()).getParent(); try { extractCommonProtoFiles(importRoot); diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protobuf/DescriptorProtoCompileTest.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protobuf/DescriptorProtoCompileTest.java index 99576819a6..2edde1fb46 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protobuf/DescriptorProtoCompileTest.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protobuf/DescriptorProtoCompileTest.java @@ -15,9 +15,9 @@ import com.google.protobuf.Descriptors.FileDescriptor; import com.tencent.trpc.codegen.CodegenTestHelper; import com.tencent.trpc.codegen.protoc.ProtocTest; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -26,7 +26,7 @@ public class DescriptorProtoCompileTest { private static final Path rootPath = CodegenTestHelper.TEST_ROOT; - @BeforeClass + @BeforeAll public static void prepare() { Path descriptorFile = rootPath.resolve("hello.pb"); if (!Files.exists(descriptorFile)) { @@ -39,11 +39,11 @@ public static void prepare() { public void testParseProtoDescriptorSet() throws IOException { Path descriptorFile = rootPath.resolve("hello.pb"); FileDescriptorSet set = ProtoParser.parseDescriptorSetFile(descriptorFile); - Assert.assertEquals(5, set.getFileCount()); + Assertions.assertEquals(5, set.getFileCount()); FileDescriptorsCompiler compiler = new FileDescriptorsCompiler(set.getFileList()); List fdList = compiler.compile(); - Assert.assertEquals(5, fdList.size()); + Assertions.assertEquals(5, fdList.size()); ProtoSourceInfo sourceInfo = ProtoParser.parseFileDescriptors(fdList); - Assert.assertEquals(1, sourceInfo.getServices().size()); + Assertions.assertEquals(1, sourceInfo.getServices().size()); } } diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protoc/ProtocTest.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protoc/ProtocTest.java index bf39b93ac2..ae355f4eed 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protoc/ProtocTest.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/protoc/ProtocTest.java @@ -12,8 +12,8 @@ package com.tencent.trpc.codegen.protoc; import com.tencent.trpc.codegen.CodegenTestHelper; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -37,7 +37,7 @@ public void testGenerateDescriptorSet() { .importPaths(Collections.singletonList(importPath)) .output(rootPath.resolve("hello.pb")) .build()); - Assert.assertTrue(result.isSuccess()); + Assertions.assertTrue(result.isSuccess()); } /** @@ -52,7 +52,7 @@ public void testGenerateDescriptorSetError() { .importPaths(Collections.singletonList(importPath)) .output(rootPath.resolve("hello2.pb")) .build()); - Assert.assertFalse(result.isSuccess()); + Assertions.assertFalse(result.isSuccess()); } /** @@ -67,7 +67,7 @@ public void testGenerateDescriptorSetFailed() { .importPaths(Collections.singletonList(importPath)) .output(rootPath.resolve("non-exist.pb")) .build()); - Assert.assertFalse(result.isSuccess()); + Assertions.assertFalse(result.isSuccess()); } /** @@ -85,6 +85,6 @@ public void testGenerateStub() throws IOException { .language(Language.JAVA) .output(outPath) .build()); - Assert.assertTrue(result.isSuccess()); + Assertions.assertTrue(result.isSuccess()); } } diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/FreeMarkerTest.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/FreeMarkerTest.java index 6a3bfbaa55..c8a9be4a28 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/FreeMarkerTest.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/FreeMarkerTest.java @@ -14,7 +14,7 @@ import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; diff --git a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/TemplateEngineTest.java b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/TemplateEngineTest.java index 16c17ab105..16fb81d9f5 100644 --- a/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/TemplateEngineTest.java +++ b/trpc-code-generator/src/test/java/com/tencent/trpc/codegen/template/TemplateEngineTest.java @@ -12,8 +12,8 @@ package com.tencent.trpc.codegen.template; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TemplateEngineTest { @@ -30,6 +30,6 @@ public void testTemplateEngine() { + " <#assign name = rtxName>\n" + "\n" + "hello ${name}!", context); - Assert.assertEquals("hello kelgonwu!", text); + Assertions.assertEquals("hello kelgonwu!", text); } } diff --git a/trpc-configcenter/trpc-configcenter-nacos/pom.xml b/trpc-configcenter/trpc-configcenter-nacos/pom.xml index b4df381545..5fdb721217 100644 --- a/trpc-configcenter/trpc-configcenter-nacos/pom.xml +++ b/trpc-configcenter/trpc-configcenter-nacos/pom.xml @@ -21,5 +21,15 @@ com.fasterxml.jackson.dataformat jackson-dataformat-properties + + org.springframework + spring-test + test + + + org.mockito + mockito-core + test + diff --git a/trpc-configcenter/trpc-configcenter-nacos/src/test/java/com/tencent/trpc/configcenter/nacos/NacosConfigurationLoaderTest.java b/trpc-configcenter/trpc-configcenter-nacos/src/test/java/com/tencent/trpc/configcenter/nacos/NacosConfigurationLoaderTest.java index 5cbfb7f810..e51c40c9d3 100644 --- a/trpc-configcenter/trpc-configcenter-nacos/src/test/java/com/tencent/trpc/configcenter/nacos/NacosConfigurationLoaderTest.java +++ b/trpc-configcenter/trpc-configcenter-nacos/src/test/java/com/tencent/trpc/configcenter/nacos/NacosConfigurationLoaderTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.configcenter.nacos; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; @@ -33,19 +33,12 @@ import com.tencent.trpc.core.exception.ConfigCenterException; import com.tencent.trpc.core.exception.TRpcExtensionException; import com.tencent.trpc.core.extension.ExtensionLoader; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +// // // import org.junit.Rule; // TODO: 迁移到 JUnit5 // TODO: 迁移到 JUnit5 // TODO: 迁移到 JUnit5 +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Collection; @@ -54,13 +47,11 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; +import org.mockito.MockedStatic; /** * NacosConfigurationLoader Test */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({NacosConfigurationLoader.class, NacosFactory.class}) -@PowerMockIgnore({"javax.management.*"}) public class NacosConfigurationLoaderTest { /** @@ -141,7 +132,7 @@ public class NacosConfigurationLoaderTest { /** * setUp */ - @Before + @BeforeEach public void setUp() { ConfigManager.stopTest(); ConfigManager.startTest(); @@ -191,7 +182,7 @@ public void setUp() { } } - @After + @AfterEach public void setDown() { ConfigManager.stopTest(); ExtensionLoader.destroyAllPlugin(); @@ -211,7 +202,7 @@ public void testNacosConfigSetMethod() { config.setDataId(DEFAULT_DATA_ID); NacosConfig.Config configOther = new NacosConfig.Config(DEFAULT_GROUP, DEFAULT_DATA_ID); boolean equals = config.equals(configOther); - Assert.assertTrue(equals); + Assertions.assertTrue(equals); } @Test @@ -220,56 +211,53 @@ public void testGetValue() throws NacosException { String key1 = "example.config.list[0].key1"; when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(YAML_EXAMPLE); - Assert.assertEquals(configYaml.getValue(key, DEFAULT_GROUP), "example"); - Assert.assertEquals(configYaml.getValue(key1, DEFAULT_GROUP), "value1"); + Assertions.assertEquals(configYaml.getValue(key, DEFAULT_GROUP), "example"); + Assertions.assertEquals(configYaml.getValue(key1, DEFAULT_GROUP), "value1"); String key2 = "example.config.list[1].key2"; when(configService.getConfig(APP_DATA_ID, APP_GROUP, TIMEOUT)).thenReturn(PROPERTIES_EXAMPLE); - Assert.assertEquals(configProperties.getValue(key, APP_GROUP), "example"); - Assert.assertEquals(configProperties.getValue(key2, APP_GROUP), "value2"); + Assertions.assertEquals(configProperties.getValue(key, APP_GROUP), "example"); + Assertions.assertEquals(configProperties.getValue(key2, APP_GROUP), "value2"); } - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void testGetValueForException() throws NacosException { - expectedEx.expect(ConfigCenterException.class); - expectedEx.expectMessage(String.format( - "Fetch config failed from Nacos, group: %s, dataId: %s", DEFAULT_GROUP, DEFAULT_DATA_ID)); String key = "example.config.name"; when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenThrow(new NacosException()); - Assert.assertNull(configYaml.getValue(key, DEFAULT_GROUP)); + ConfigCenterException exception = Assertions.assertThrows(ConfigCenterException.class, () -> { + configYaml.getValue(key, DEFAULT_GROUP); + }); + Assertions.assertTrue(exception.getMessage().contains( + String.format("Fetch config failed from Nacos, group: %s, dataId: %s", DEFAULT_GROUP, DEFAULT_DATA_ID))); } @Test @SuppressWarnings({"rawtypes", "unchecked"}) - public void testGroupDataIdCaches() throws NacosException, IllegalAccessException { + public void testGroupDataIdCaches() throws Exception { String key = "example.config.name"; when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(YAML_EXAMPLE); - Assert.assertEquals(configYaml.getValue(key, DEFAULT_GROUP), "example"); + Assertions.assertEquals(configYaml.getValue(key, DEFAULT_GROUP), "example"); - Field groupDataIdToKeysField = Whitebox - .getField(NacosConfigurationLoader.class, "groupDataIdToKeys"); + Field groupDataIdToKeysField = NacosConfigurationLoader.class.getDeclaredField("groupDataIdToKeys"); boolean groupDataIdToKeysFieldAccessible = groupDataIdToKeysField.isAccessible(); groupDataIdToKeysField.setAccessible(true); Multimap groupDataIdToKeys = (Multimap) groupDataIdToKeysField.get(configYaml); groupDataIdToKeysField.setAccessible(groupDataIdToKeysFieldAccessible); Collection keys = groupDataIdToKeys.get(String.format("%s_%s", DEFAULT_GROUP, DEFAULT_DATA_ID)); - Assert.assertEquals(keys.size(), 1); - Assert.assertTrue(keys.contains(key)); + Assertions.assertEquals(keys.size(), 1); + Assertions.assertTrue(keys.contains(key)); - Field groupDataIdToNacosListenerField = Whitebox - .getField(NacosConfigurationLoader.class, "groupDataIdToNacosListener"); + Field groupDataIdToNacosListenerField = NacosConfigurationLoader.class + .getDeclaredField("groupDataIdToNacosListener"); boolean groupDataIdToNacosListenerFieldAccessible = groupDataIdToNacosListenerField.isAccessible(); groupDataIdToNacosListenerField.setAccessible(true); Map groupDataIdToNacosListener = (Map) groupDataIdToNacosListenerField.get(configYaml); groupDataIdToNacosListenerField.setAccessible(groupDataIdToNacosListenerFieldAccessible); Object listener = groupDataIdToNacosListener.get(String.format("%s_%s", DEFAULT_GROUP, DEFAULT_DATA_ID)); - Assert.assertTrue(listener instanceof Listener); - Assert.assertTrue(listener instanceof AbstractConfigChangeListener); + Assertions.assertTrue(listener instanceof Listener); + Assertions.assertTrue(listener instanceof AbstractConfigChangeListener); // Test configuration DELETED changes ConfigChangeItem item = new ConfigChangeItem(key, "", ""); @@ -277,10 +265,10 @@ public void testGroupDataIdCaches() throws NacosException, IllegalAccessExceptio ConfigChangeEvent event = new ConfigChangeEvent(ImmutableMap.of(key, item)); ((AbstractConfigChangeListener) listener).receiveConfigChange(event); keys = groupDataIdToKeys.get(String.format("%s_%s", DEFAULT_GROUP, DEFAULT_DATA_ID)); - Assert.assertEquals(keys.size(), 0); + Assertions.assertEquals(keys.size(), 0); Executor executor = ((AbstractConfigChangeListener) listener).getExecutor(); - Assert.assertNotNull(executor); + Assertions.assertNotNull(executor); } @Test @@ -290,40 +278,48 @@ public void testGetAllValue() throws NacosException { when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(YAML_EXAMPLE); Map allYamlValue = configYaml.getAllValue(DEFAULT_GROUP); - Assert.assertEquals(allYamlValue.get(key), "example"); - Assert.assertEquals(allYamlValue.get(key1), "value1"); + Assertions.assertEquals(allYamlValue.get(key), "example"); + Assertions.assertEquals(allYamlValue.get(key1), "value1"); String key2 = "example.config.list[1].key2"; when(configService.getConfig(APP_DATA_ID, APP_GROUP, TIMEOUT)).thenReturn(PROPERTIES_EXAMPLE); Map allPropsValue1 = configProperties.getAllValue(APP_GROUP); - Assert.assertEquals(allPropsValue1.get(key), "example"); - Assert.assertEquals(allPropsValue1.get(key2), "value2"); + Assertions.assertEquals(allPropsValue1.get(key), "example"); + Assertions.assertEquals(allPropsValue1.get(key2), "value2"); } - @Test(expected = ConfigCenterException.class) - public void testGetAllValueXml() throws NacosException { - String xmlValue = ""; - when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(xmlValue); - configYaml.getAllValue(DEFAULT_GROUP); + @Test + void testGetAllValueXml() { + Assertions.assertThrows(ConfigCenterException.class, () -> { + String xmlValue = ""; + when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(xmlValue); + configYaml.getAllValue(DEFAULT_GROUP); + }); } - @Test(expected = ConfigCenterException.class) - public void testGetAllValueHtml() throws NacosException { - String htmlValue = ""; - when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(htmlValue); - configYaml.getAllValue(DEFAULT_GROUP); + @Test + void testGetAllValueHtml() { + Assertions.assertThrows(ConfigCenterException.class, () -> { + String htmlValue = ""; + when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(htmlValue); + configYaml.getAllValue(DEFAULT_GROUP); + }); } - @Test(expected = ConfigCenterException.class) - public void testGetAllValueText() throws NacosException { - String textValue = "Test text."; - when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(textValue); - configYaml.getAllValue(DEFAULT_GROUP); + @Test + void testGetAllValueText() { + Assertions.assertThrows(ConfigCenterException.class, () -> { + String textValue = "Test text."; + when(configService.getConfig(DEFAULT_DATA_ID, DEFAULT_GROUP, TIMEOUT)).thenReturn(textValue); + configYaml.getAllValue(DEFAULT_GROUP); + }); } - @Test(expected = ConfigCenterException.class) - public void testLoadConfig() { - configYaml.loadConfig("fileName"); + @Test + void testLoadConfig() { + Assertions.assertThrows(ConfigCenterException.class, () -> { + configYaml.loadConfig("fileName"); + }); } @Test @@ -345,22 +341,22 @@ public void testAddListenerError() { } configYaml.setConfigService(configService); - expectedEx.expect(ConfigCenterException.class); - ConfigurationListener listener = Mockito.mock(ConfigurationListener.class); - configYaml.addListener(listener); + Assertions.assertThrows(ConfigCenterException.class, () -> { + configYaml.addListener(listener); + }); } @SuppressWarnings({"rawtypes", "unchecked"}) @Test - public void testListenerCallback() throws IllegalAccessException { + public void testListenerCallback() throws Exception { String key = "example.config.name"; - ConfigurationListener listener = event -> Assert.assertEquals(event.getKey(), key); + ConfigurationListener listener = event -> Assertions.assertEquals(event.getKey(), key); configYaml.addListener(listener); - Field configurationListenerToNacosListener = Whitebox - .getField(NacosConfigurationLoader.class, "configurationListenerToNacosListener"); + Field configurationListenerToNacosListener = NacosConfigurationLoader.class + .getDeclaredField("configurationListenerToNacosListener"); boolean groupDataIdToKeysFieldAccessible = configurationListenerToNacosListener.isAccessible(); configurationListenerToNacosListener.setAccessible(true); Map listenerMap = (Map) configurationListenerToNacosListener.get(configYaml); @@ -368,8 +364,8 @@ public void testListenerCallback() throws IllegalAccessException { Map nacosConfigToListener = (Map) listenerMap.get(listener); Listener changeListener = nacosConfigToListener.get(new NacosConfig.Config(DEFAULT_GROUP, DEFAULT_DATA_ID)); - Assert.assertNotNull(changeListener); - Assert.assertTrue(changeListener instanceof AbstractConfigChangeListener); + Assertions.assertNotNull(changeListener); + Assertions.assertTrue(changeListener instanceof AbstractConfigChangeListener); ConfigChangeItem item = new ConfigChangeItem(key, "", ""); item.setType(PropertyChangeType.DELETED); @@ -377,14 +373,17 @@ public void testListenerCallback() throws IllegalAccessException { ((AbstractConfigChangeListener) changeListener).receiveConfigChange(event); Executor executor = changeListener.getExecutor(); - Assert.assertNotNull(executor); + Assertions.assertNotNull(executor); } @Test public void testConvertConfigurationEvent() throws Exception { ConfigChangeItem changeItem = new ConfigChangeItem("test", "123", "1234"); changeItem.setType(PropertyChangeType.MODIFIED); - Whitebox.invokeMethod(configYaml, "convertConfigurationEvent", DEFAULT_GROUP, changeItem); + java.lang.reflect.Method method = NacosConfigurationLoader.class + .getDeclaredMethod("convertConfigurationEvent", String.class, ConfigChangeItem.class); + method.setAccessible(true); + method.invoke(configYaml, DEFAULT_GROUP, changeItem); } @Test @@ -394,7 +393,6 @@ public void testDestroy() { @Test public void testDestroyError() { - expectedEx.expect(TRpcExtensionException.class); try { doAnswer(it -> { throw new NacosException(); @@ -402,20 +400,19 @@ public void testDestroyError() { } catch (NacosException e) { throw new RuntimeException(e); } - configYaml.destroy(); + Assertions.assertThrows(TRpcExtensionException.class, () -> { + configYaml.destroy(); + }); } @Test public void testInitError() { - expectedEx.expect(TRpcExtensionException.class); - - PowerMockito.mockStatic(NacosFactory.class); - try { - PowerMockito.doThrow(new NacosException()).when(NacosFactory.class, - "createConfigService", any(Properties.class)); - } catch (Exception e) { - throw new RuntimeException(e); + try (MockedStatic mockedNacosFactory = Mockito.mockStatic(NacosFactory.class)) { + mockedNacosFactory.when(() -> NacosFactory.createConfigService(any(Properties.class))) + .thenThrow(new NacosException()); + Assertions.assertThrows(TRpcExtensionException.class, () -> { + configYaml.init(); + }); } - configYaml.init(); } } diff --git a/trpc-configcenter/trpc-configcenter-open-polaris/pom.xml b/trpc-configcenter/trpc-configcenter-open-polaris/pom.xml index aac966b998..02a64b312a 100644 --- a/trpc-configcenter/trpc-configcenter-open-polaris/pom.xml +++ b/trpc-configcenter/trpc-configcenter-open-polaris/pom.xml @@ -23,6 +23,16 @@ + + org.springframework + spring-test + test + + + org.mockito + mockito-core + test + \ No newline at end of file diff --git a/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigTest.java b/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigTest.java index e92fb180e3..64342a521d 100644 --- a/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigTest.java +++ b/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.configcenter.polaris; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import com.tencent.trpc.configcenter.polaris.PolarisConfig.Config; import com.tencent.trpc.core.common.config.PluginConfig; @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PolarisConfigTest { @@ -91,4 +91,4 @@ public void testConfig() { assertNotEquals(config1.hashCode(), config2.hashCode()); } -} \ No newline at end of file +} diff --git a/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigurationLoaderTest.java b/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigurationLoaderTest.java index 6a50a6d2e7..94d4fc717e 100644 --- a/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigurationLoaderTest.java +++ b/trpc-configcenter/trpc-configcenter-open-polaris/src/test/java/com/tencent/trpc/configcenter/polaris/PolarisConfigurationLoaderTest.java @@ -32,8 +32,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class PolarisConfigurationLoaderTest { @@ -91,10 +91,10 @@ public void testGetValue() { Mockito.when(fetcher.getConfigPropertiesFile("default", MOCK_GROUP, MOCK_FILE)).thenReturn(mockKv); String ret = loader.getValue(USER_NAME, MOCK_GROUP); - Assert.assertEquals("polaris", ret); + Assertions.assertEquals("polaris", ret); ret = loader.getValue(USER_NAME, MOCK_GROUP + "123"); - Assert.assertEquals(null, ret); + Assertions.assertEquals(null, ret); } @Test @@ -109,7 +109,7 @@ public void testGetAllValues() { Mockito.when(fetcher.getConfigPropertiesFile("default", MOCK_GROUP, MOCK_FILE)).thenReturn(mockKv); Map values = loader.getAllValue(MOCK_GROUP); - Assert.assertEquals("polaris", values.get("user.name")); + Assertions.assertEquals("polaris", values.get("user.name")); } @Test @@ -136,11 +136,11 @@ public void testAddListener() throws Exception { loader.addListener(listener); latch.await(1, TimeUnit.SECONDS); - Assert.assertNotNull(ref.get()); + Assertions.assertNotNull(ref.get()); ConfigurationEvent event = ref.get(); - Assert.assertEquals(event.getKey(), "user.name"); - Assert.assertEquals(event.getValue(), "polaris"); - Assert.assertEquals(event.getType(), ChangeType.ADDED.name()); + Assertions.assertEquals(event.getKey(), "user.name"); + Assertions.assertEquals(event.getValue(), "polaris"); + Assertions.assertEquals(event.getType(), ChangeType.ADDED.name()); } @Test @@ -308,4 +308,4 @@ public String getFileName() { } } -} \ No newline at end of file +} diff --git a/trpc-limiter/trpc-limiter-sentinel/pom.xml b/trpc-limiter/trpc-limiter-sentinel/pom.xml index 0c835793a8..1a8eb43065 100644 --- a/trpc-limiter/trpc-limiter-sentinel/pom.xml +++ b/trpc-limiter/trpc-limiter-sentinel/pom.xml @@ -127,9 +127,9 @@ - ai.grakn - redis-mock - 0.1.6 + com.github.fppt + jedis-mock + 1.1.6 test diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/SentinelLimiterTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/SentinelLimiterTest.java index 0855f3e11a..0d3db3a7f6 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/SentinelLimiterTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/SentinelLimiterTest.java @@ -21,14 +21,13 @@ import com.tencent.trpc.core.rpc.def.DefRequest; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * SentinelLimiter test class */ -public class SentinelLimiterTest extends TestCase { +public class SentinelLimiterTest { @Test public void testBlock() { @@ -56,7 +55,7 @@ public void testBlock() { limiter01.block(new TestSentinelInvoker(), requestQps).toCompletableFuture().get().getException(); } catch (Exception exception) { Throwable cause = exception.getCause(); - Assert.assertTrue( + Assertions.assertTrue( (cause instanceof LimiterBlockException) || (cause instanceof LimiterFallbackException)); break; @@ -80,7 +79,7 @@ public void testBlock() { .getException(); } catch (Exception exception) { Throwable cause = exception.getCause(); - Assert.assertTrue(cause instanceof LimiterFallbackException); + Assertions.assertTrue(cause instanceof LimiterFallbackException); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelConfigTest.java index bbed62f1ed..e5431d5d27 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelConfigTest.java @@ -15,8 +15,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * SentinelConfig test class @@ -32,7 +32,7 @@ public void testParse() { sentinelMap.put("datasource", datasourceMap); configMap.put("sentinel", sentinelMap); SentinelConfig sentinelConfig = SentinelConfig.parse(sentinelMap); - Assert.assertTrue(sentinelConfig.getDataSourceConfig() instanceof LocalFileDatasourceConfig); + Assertions.assertTrue(sentinelConfig.getDataSourceConfig() instanceof LocalFileDatasourceConfig); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelLimiterConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelLimiterConfigTest.java index 60ab83e6e2..4311e8bcf8 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelLimiterConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/SentinelLimiterConfigTest.java @@ -13,8 +13,8 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Test limit callback, downgrade configuration @@ -31,14 +31,14 @@ public void testParse() { configMap.put("limiter_config", limiterConfigMap); SentinelLimiterConfig sentinelLimiterConfig1 = SentinelLimiterConfig.parse(configMap); - Assert.assertTrue("test_handler".equals(sentinelLimiterConfig1.getBlockHandler())); - Assert.assertTrue("test_fallback".equals(sentinelLimiterConfig1.getFallback())); - Assert.assertTrue("test_resource_extractor".equals(sentinelLimiterConfig1.getResourceExtractor())); + Assertions.assertTrue("test_handler".equals(sentinelLimiterConfig1.getBlockHandler())); + Assertions.assertTrue("test_fallback".equals(sentinelLimiterConfig1.getFallback())); + Assertions.assertTrue("test_resource_extractor".equals(sentinelLimiterConfig1.getResourceExtractor())); SentinelLimiterConfig sentinelLimiterConfig2 = SentinelLimiterConfig.parse(null); - Assert.assertTrue("default".equals(sentinelLimiterConfig2.getBlockHandler())); - Assert.assertTrue("default".equals(sentinelLimiterConfig2.getFallback())); - Assert.assertTrue("default".equals(sentinelLimiterConfig2.getResourceExtractor())); + Assertions.assertTrue("default".equals(sentinelLimiterConfig2.getBlockHandler())); + Assertions.assertTrue("default".equals(sentinelLimiterConfig2.getFallback())); + Assertions.assertTrue("default".equals(sentinelLimiterConfig2.getResourceExtractor())); Map configMap3 = new HashMap<>(); Map limiterConfigMap3 = new HashMap<>(); @@ -46,9 +46,9 @@ public void testParse() { limiterConfigMap3.put("fallback", "test_fallback3"); configMap3.put("limiter_config", limiterConfigMap3); SentinelLimiterConfig sentinelLimiterConfig3 = SentinelLimiterConfig.parse(configMap3); - Assert.assertTrue("test_handler3".equals(sentinelLimiterConfig3.getBlockHandler())); - Assert.assertTrue("test_fallback3".equals(sentinelLimiterConfig3.getFallback())); - Assert.assertTrue("default".equals(sentinelLimiterConfig3.getResourceExtractor())); + Assertions.assertTrue("test_handler3".equals(sentinelLimiterConfig3.getBlockHandler())); + Assertions.assertTrue("test_fallback3".equals(sentinelLimiterConfig3.getFallback())); + Assertions.assertTrue("default".equals(sentinelLimiterConfig3.getResourceExtractor())); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/LocalFileDatasourceConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/LocalFileDatasourceConfigTest.java index 23d7603992..b5c56c8fc3 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/LocalFileDatasourceConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/LocalFileDatasourceConfigTest.java @@ -16,8 +16,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.factory.DatasourceType; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * LocalFileDatasourceConfig test class @@ -43,7 +43,7 @@ public void testRegister1() { localFileDatasourceConfig.register(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } @@ -57,7 +57,7 @@ public void testRegister2() { localFileDatasourceConfig.register(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } @@ -69,7 +69,7 @@ public void testValidate() { try { localFileDatasourceConfig.validate(); } catch (Exception e) { - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/NacosDatasourceConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/NacosDatasourceConfigTest.java index b478273ab3..74a6752176 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/NacosDatasourceConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/NacosDatasourceConfigTest.java @@ -16,8 +16,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.factory.DatasourceType; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * NacosDatasourceConfig test class @@ -35,7 +35,7 @@ public void testValidate1() { nacosDatasourceConfig.validate(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } @@ -50,7 +50,7 @@ public void testValidate2() { localFileDatasourceConfig.register(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } @@ -65,7 +65,7 @@ public void testValidate3() { localFileDatasourceConfig.register(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } @@ -81,7 +81,7 @@ public void testRegister() { localFileDatasourceConfig.register(); } catch (Exception e) { e.printStackTrace(); - Assert.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e instanceof LimiterDataSourceException); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/RedisDatasourceConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/RedisDatasourceConfigTest.java index 3977b902d4..bb99071c21 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/RedisDatasourceConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/RedisDatasourceConfigTest.java @@ -11,16 +11,17 @@ package com.tencent.trpc.limiter.sentinel.config.datasource; +import com.github.fppt.jedismock.RedisServer; import com.tencent.trpc.core.exception.LimiterDataSourceException; import com.tencent.trpc.limiter.sentinel.config.datasource.factory.DatasourceConfigFactoryManger; import com.tencent.trpc.limiter.sentinel.config.datasource.factory.DatasourceType; +import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import redis.embedded.RedisServer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * RedisDatasourceConfig test class @@ -30,12 +31,11 @@ public class RedisDatasourceConfigTest { private RedisServer redisServer; private int port = 6380; - @Before - public void setUp() { - - redisServer = RedisServer.builder().setting("maxmemory 128M").setting("bind localhost") - .port(port).build(); - redisServer.start(); + @BeforeEach + public void setUp() throws Exception { + redisServer = RedisServer + .newRedisServer(port) + .start(); } @Test @@ -61,8 +61,8 @@ public void testValidate1() { try { configWithoutRuleKey1.validate(); } catch (Exception e) { - Assert.assertTrue(e instanceof LimiterDataSourceException); - Assert.assertTrue(e.getMessage().equals("sentinel redis datasource config error, channel is empty")); + Assertions.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e.getMessage().equals("sentinel redis datasource config error, channel is empty")); } } @@ -78,13 +78,13 @@ public void testValidate2() { try { configWithoutRuleKey.validate(); } catch (Exception e) { - Assert.assertTrue(e instanceof LimiterDataSourceException); - Assert.assertTrue(e.getMessage().equals("sentinel redis datasource config error, rule key is empty")); + Assertions.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue(e.getMessage().equals("sentinel redis datasource config error, rule key is empty")); } } - @After - public void after() { + @AfterEach + public void after() throws IOException { if (redisServer != null) { redisServer.stop(); } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/ZookeeperDatasourceConfigTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/ZookeeperDatasourceConfigTest.java index f18e1497cc..eb350955a2 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/ZookeeperDatasourceConfigTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/ZookeeperDatasourceConfigTest.java @@ -18,10 +18,10 @@ import java.util.HashMap; import java.util.Map; import org.apache.curator.test.TestingServer; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * ZookeeperDatasourceConfig test class @@ -31,7 +31,7 @@ public class ZookeeperDatasourceConfigTest { private ZookeeperDatasourceConfig zookeeperDatasourceConfig; private TestingServer zkServer; - @Before + @BeforeEach public void setUp() throws Exception { int port = 2183; zkServer = new TestingServer(port, new File("/tmp/sentinel")); @@ -58,8 +58,8 @@ public void testValidate1() { try { zookeeperDatasourceConfig.validate(); } catch (Exception e) { - Assert.assertTrue(e instanceof LimiterDataSourceException); - Assert.assertTrue( + Assertions.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue( "sentinel zookeeper datasource config error, remote address is empty".equals(e.getMessage())); } } @@ -73,13 +73,13 @@ public void testValidate2() { try { zookeeperDatasourceConfig.validate(); } catch (Exception e) { - Assert.assertTrue(e instanceof LimiterDataSourceException); - Assert.assertTrue( + Assertions.assertTrue(e instanceof LimiterDataSourceException); + Assertions.assertTrue( "sentinel zookeeper datasource config error, path is empty".equals(e.getMessage())); } } - @After + @AfterEach public void after() throws Exception { if (zkServer != null) { zkServer.stop(); diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/DatasourceConfigFactoryMangerTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/DatasourceConfigFactoryMangerTest.java index 2a76a2c23b..b48bda106a 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/DatasourceConfigFactoryMangerTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/DatasourceConfigFactoryMangerTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.limiter.sentinel.config.datasource.factory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * DatasourceConfigFactoryManger test class @@ -21,16 +21,16 @@ public class DatasourceConfigFactoryMangerTest { @Test public void testGetDatasourceConfigFactory() { - Assert.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( + Assertions.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( DatasourceType.LOCAL_FILE.getName()) instanceof LocalFileDatasourceConfigFactory); - Assert.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( + Assertions.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( DatasourceType.REDIS.getName()) instanceof RedisDatasourceConfigFactory); - Assert.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( + Assertions.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( DatasourceType.NACOS.getName()) instanceof NacosDatasourceConfigFactory); - Assert.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( + Assertions.assertTrue(DatasourceConfigFactoryManger.getDatasourceConfigFactory( DatasourceType.ZOOKEEPER.getName()) instanceof ZookeeperDatasourceConfigFactory); } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/LocalFileDatasourceConfigFactoryTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/LocalFileDatasourceConfigFactoryTest.java index 15e99c86b4..a8369a331a 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/LocalFileDatasourceConfigFactoryTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/LocalFileDatasourceConfigFactoryTest.java @@ -15,8 +15,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.LocalFileDatasourceConfig; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * LocalFileDatasourceConfigFactory test class @@ -28,14 +28,14 @@ public void testCreate() { Map configs = new HashMap<>(); configs.put("path", "classpath:flow_rule.json"); DatasourceConfig datasourceConfig = new LocalFileDatasourceConfigFactory().create(configs); - Assert.assertTrue(datasourceConfig instanceof LocalFileDatasourceConfig); + Assertions.assertTrue(datasourceConfig instanceof LocalFileDatasourceConfig); } @Test public void testName() { Map configs = new HashMap<>(); configs.put("path", "classpath:flow_rule.json"); - Assert.assertTrue(DatasourceType.LOCAL_FILE.getName().equals(new LocalFileDatasourceConfigFactory().name())); + Assertions.assertTrue(DatasourceType.LOCAL_FILE.getName().equals(new LocalFileDatasourceConfigFactory().name())); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/NacosDatasourceConfigFactoryTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/NacosDatasourceConfigFactoryTest.java index d8b2d8c881..2385649237 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/NacosDatasourceConfigFactoryTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/NacosDatasourceConfigFactoryTest.java @@ -15,8 +15,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.NacosDatasourceConfig; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * NacosDatasourceConfigFactory test class @@ -30,7 +30,7 @@ public void testCreate() { configs.put("data_id", "test_data_id"); configs.put("remote_address", "127.0.0.1"); DatasourceConfig datasourceConfig = new NacosDatasourceConfigFactory().create(configs); - Assert.assertTrue(datasourceConfig instanceof NacosDatasourceConfig); + Assertions.assertTrue(datasourceConfig instanceof NacosDatasourceConfig); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/RedisDatasourceConfigFactoryTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/RedisDatasourceConfigFactoryTest.java index 17dd639984..395fbb764c 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/RedisDatasourceConfigFactoryTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/RedisDatasourceConfigFactoryTest.java @@ -15,8 +15,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.RedisDatasourceConfig; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * RedisDatasourceConfigFactory test class @@ -36,12 +36,12 @@ public void testCreate() { configs.put("sentinel_master_id", "sentinel_master_id"); configs.put("timeout", 5000); DatasourceConfig datasourceConfig = new RedisDatasourceConfigFactory().create(configs); - Assert.assertTrue(datasourceConfig instanceof RedisDatasourceConfig); + Assertions.assertTrue(datasourceConfig instanceof RedisDatasourceConfig); } @Test public void testName() { - Assert.assertTrue(new RedisDatasourceConfigFactory().name().equals(DatasourceType.REDIS.getName())); + Assertions.assertTrue(new RedisDatasourceConfigFactory().name().equals(DatasourceType.REDIS.getName())); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/ZookeeperDatasourceConfigFactoryTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/ZookeeperDatasourceConfigFactoryTest.java index 2fcec163e0..df5a306416 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/ZookeeperDatasourceConfigFactoryTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/config/datasource/factory/ZookeeperDatasourceConfigFactoryTest.java @@ -15,8 +15,8 @@ import com.tencent.trpc.limiter.sentinel.config.datasource.ZookeeperDatasourceConfig; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * ZookeeperDatasourceConfigFactory test class @@ -29,7 +29,7 @@ public void testCreate() { configs.put("remote_address", "127.0.0.1:2181"); configs.put("path", "/"); DatasourceConfig datasourceConfig = new ZookeeperDatasourceConfigFactory().create(configs); - Assert.assertTrue(datasourceConfig instanceof ZookeeperDatasourceConfig); + Assertions.assertTrue(datasourceConfig instanceof ZookeeperDatasourceConfig); } } diff --git a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/filter/SentinelLimiterFilterTest.java b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/filter/SentinelLimiterFilterTest.java index 1d7d3d4812..73290d5d10 100644 --- a/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/filter/SentinelLimiterFilterTest.java +++ b/trpc-limiter/trpc-limiter-sentinel/src/test/java/com/tencent/trpc/limiter/sentinel/filter/SentinelLimiterFilterTest.java @@ -22,9 +22,9 @@ import com.tencent.trpc.limiter.sentinel.TestSentinelInvoker; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * SentinelLimiterFilter test class @@ -33,7 +33,7 @@ public class SentinelLimiterFilterTest { private static final Logger logger = LoggerFactory.getLogger(SentinelLimiterFilterTest.class); - @Before + @BeforeEach public void setUp() { try { Map extMap = new HashMap<>(); @@ -52,7 +52,7 @@ public void setUp() { @Test public void testFilter() { SentinelLimiterFilter sentinelLimiterFilter = new SentinelLimiterFilter(); - Assert.assertEquals(FilterOrdered.SENTINEL_LIMITER_ORDERED, sentinelLimiterFilter.getOrder()); + Assertions.assertEquals(FilterOrdered.SENTINEL_LIMITER_ORDERED, sentinelLimiterFilter.getOrder()); sentinelLimiterFilter.init(); DefRequest request = new DefRequest();