From dfc53aa04371fd941538b06cd1c6aa88b12e580e Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 16:45:31 +0800 Subject: [PATCH 1/8] feat: optimize test --- pom.xml | 64 +++++++------------ trpc-core/pom.xml | 25 ++++++++ .../trpc-dependencies-bom/pom.xml | 9 ++- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 2f5abeb62..c7a91c727 100644 --- a/pom.xml +++ b/pom.xml @@ -82,22 +82,26 @@ UTF-8 - false - false - 3.0.0 - 3.5.0 - 3.0.1 - 3.0.1 - 3.1.2 17 17 - 3.7.0 + 17 + + false + false + 3.11.0 + 3.0.0-M9 + 3.0.0-M9 + 3.3.0 + 3.3.0 + 3.5.0 + 3.1.1 + 3.4.1 + 3.1.0 3.1.0 - false - 3.1.2 - 3.0.1 + 0.7.0 3.1.0 + 5.14.2 UTF-8 @@ -124,42 +128,22 @@ org.junit.jupiter junit-jupiter-api - 5.9.3 + ${junit.version} test org.junit.jupiter junit-jupiter-engine - 5.9.3 - test - - - - junit - junit - 4.13.2 + ${junit.version} test - - - - - - - - - - - - - - - - - - - - + + + + + + + org.jacoco org.jacoco.agent diff --git a/trpc-core/pom.xml b/trpc-core/pom.xml index f9c18ce73..9d2eb8999 100644 --- a/trpc-core/pom.xml +++ b/trpc-core/pom.xml @@ -20,6 +20,31 @@ + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + + + org.mockito + mockito-inline + test + org.assertj assertj-core diff --git a/trpc-dependencies/trpc-dependencies-bom/pom.xml b/trpc-dependencies/trpc-dependencies-bom/pom.xml index 98a5b354e..f902c1824 100644 --- a/trpc-dependencies/trpc-dependencies-bom/pom.xml +++ b/trpc-dependencies/trpc-dependencies-bom/pom.xml @@ -99,7 +99,7 @@ 11.0.25 2.7 2.4.14 - 5.10.0 + 5.14.2 3.28.0-GA 3.1.0 3.0.2 @@ -113,7 +113,7 @@ 3.3.0 1.4.1 3.0.2 - 5.5.0 + 5.21.0 5.2.0 1.4.2 2.2.1 @@ -127,7 +127,6 @@ 1.26.0 3.4.0 1.15.5 - 2.0.9 3.25.5 0.4.1 0.6.13 @@ -792,13 +791,13 @@ org.mockito mockito-core - ${mockito_core.version} + ${mockito-core.version} test org.mockito mockito-junit-jupiter - ${mockito_core.version} + ${mockito-core.version} test From 3fbb6d086b0a50fa58bd5e7c88ccd39a0c8e457f Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 16:49:03 +0800 Subject: [PATCH 2/8] feat: optimize test --- .../cluster/AbstractClusterInvokerTest.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java index f4b92fd0a..a5968b371 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java @@ -22,20 +22,16 @@ import com.tencent.trpc.core.selector.spi.Selector; import com.tencent.trpc.core.worker.WorkerPoolManager; import java.util.concurrent.CompletionException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -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.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(PowerMockRunner.class) -@PrepareForTest(SelectorManager.class) -@PowerMockIgnore({"javax.management.*", "javax.security.*", "javax.ws.*"}) +@ExtendWith(MockitoExtension.class) public class AbstractClusterInvokerTest { private static final String INVALID_SELECTOR = "invalid"; @@ -45,10 +41,7 @@ public class AbstractClusterInvokerTest { @Mock private ExtensionManager mockManager; - /** - * Init defClusterInvoker & mockManager - */ - @Before + @BeforeEach public void setUp() { BackendConfig backendConfig = new BackendConfig(); backendConfig.setServiceInterface(GenericClient.class); @@ -64,23 +57,28 @@ public void setUp() { ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setBackendConfig(backendConfig); consumerConfig.setServiceInterface(GenericClient.class); - // mock SelectorManager and ExtensionManager - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(SelectorManager.class); - PowerMockito.when(SelectorManager.getManager()).thenReturn(mockManager); - PowerMockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); - this.defClusterInvoker = new DefClusterInvoker<>(consumerConfig); + + try (MockedStatic mockedStatic = Mockito.mockStatic(SelectorManager.class)) { + mockedStatic.when(SelectorManager::getManager).thenReturn(mockManager); + Mockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); + this.defClusterInvoker = new DefClusterInvoker<>(consumerConfig); + } } @Test public void testInvoke() { - try { - defClusterInvoker.invoke(new DefRequest()).toCompletableFuture().join(); - } catch (CompletionException exception) { - NamingOptions namingOptions = defClusterInvoker.getConfig().getBackendConfig().getNamingOptions(); - String expect = "com.tencent.trpc.core.exception.TRpcException: " - + "the selector name:" + namingOptions.getSelectorId() + " not found selector"; - Assert.assertEquals(expect, exception.getMessage()); + try (MockedStatic mockedStatic = Mockito.mockStatic(SelectorManager.class)) { + mockedStatic.when(SelectorManager::getManager).thenReturn(mockManager); + Mockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); + + try { + defClusterInvoker.invoke(new DefRequest()).toCompletableFuture().join(); + } catch (CompletionException exception) { + NamingOptions namingOptions = defClusterInvoker.getConfig().getBackendConfig().getNamingOptions(); + String expect = "com.tencent.trpc.core.exception.TRpcException: " + + "the selector name:" + namingOptions.getSelectorId() + " not found selector"; + Assertions.assertEquals(expect, exception.getMessage()); + } } } From 4a7f3aca7dda01465449f19707a09d7f7d8963a5 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 18:04:34 +0800 Subject: [PATCH 3/8] feat: optimize test --- pom.xml | 67 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index c7a91c727..425e2d54b 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ 17 false + false false 3.11.0 3.0.0-M9 @@ -99,6 +100,7 @@ 3.1.0 3.1.0 + 0.8.11 0.7.0 3.1.0 5.14.2 @@ -137,17 +139,10 @@ ${junit.version} test - - - - - - - org.jacoco org.jacoco.agent - 0.8.11 + ${jacoco.version} runtime test @@ -183,14 +178,14 @@ --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.io=ALL-UNNAMED ${maven.ignore.testfailure} false - - ${project.build.directory}/coverage.exec - - ../../site/junit + false + 1 + true @@ -256,22 +251,22 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + ${jacoco.version} false + ${project.build.directory}/coverage.exec + true - default-instrument + prepare-agent - instrument - - - - default-restore-instrumented-classes - - restore-instrumented-classes + prepare-agent + + surefireArgLine + ${project.build.directory}/coverage.exec + report @@ -284,6 +279,13 @@ ../../site/${project.artifactId} + + aggregate + verify + + report-aggregate + + @@ -291,6 +293,25 @@ exec-maven-plugin ${exec.maven.version} + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven.failsafe.version} + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + + + + + + integration-test + verify + + + + @@ -311,6 +332,10 @@ org.jacoco jacoco-maven-plugin + + org.apache.maven.plugins + maven-failsafe-plugin + From ef5057d586ff136ca49d84244497f05bfcb51985 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 18:10:15 +0800 Subject: [PATCH 4/8] feat: optimize trpc-container test --- .../trpc/container/config/YamlUtilsTest.java | 32 +++---- .../system/EnvironmentConfigurationTest.java | 16 ++-- .../config/system/EnvironmentTest.java | 84 ++++++++++++------- .../system/SystemConfigurationTest.java | 9 +- .../DefaultPropertySourceParserTest.java | 15 ++-- .../config/yaml/BackendConfigParserTest.java | 10 +-- .../config/yaml/ClientConfigParserTest.java | 10 +-- .../config/yaml/GlobalConfigParserTest.java | 15 ++-- .../config/yaml/ParseErrorInfoTest.java | 15 ++-- .../yaml/PluginConfigParserHelperTest.java | 46 +++++----- .../config/yaml/PluginConfigParserTest.java | 13 ++- .../config/yaml/ServerConfigParserTest.java | 20 ++--- .../config/yaml/ServiceConfigParserTest.java | 15 ++-- .../yaml/YamlApplicationConfigParserTest.java | 46 +++++----- .../container/ConsumerProxyTest.java | 27 +++--- .../container/DefaultContainerTest.java | 16 ++-- .../src/test/resources/trpc_java.yaml | 4 +- 17 files changed, 205 insertions(+), 188 deletions(-) diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java index 6acd1cb64..bbf699be5 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java @@ -16,10 +16,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -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; /** @@ -31,7 +31,7 @@ public class YamlUtilsTest { private YamlUtils yamlUtils; - @Before + @BeforeEach public void setUp() throws Exception { this.properties = new HashMap<>(); properties.put("string", "string"); @@ -41,7 +41,7 @@ public void setUp() throws Exception { this.yamlUtils = new YamlUtils(""); } - @After + @AfterEach public void tearDown() throws Exception { properties.clear(); } @@ -49,64 +49,64 @@ public void tearDown() throws Exception { @Test public void testGetString() { String string = yamlUtils.getString(properties, "string"); - Assert.assertEquals("string", string); + Assertions.assertEquals("string", string); properties.put("string", null); try { yamlUtils.getString(properties, "string"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetInteger() { int integer = yamlUtils.getInteger(properties, "integer"); - Assert.assertEquals(integer, 10); + Assertions.assertEquals(integer, 10); properties.put("integer", null); try { yamlUtils.getInteger(properties, "integer"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetBoolean() { boolean bool = yamlUtils.getBoolean(properties, "boolean"); - Assert.assertTrue(bool); + Assertions.assertTrue(bool); properties.put("boolean", null); try { yamlUtils.getBoolean(properties, "boolean"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetCollection() { Collection collection = yamlUtils.getCollection(properties, "collection"); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); properties.put("collection", null); try { yamlUtils.getBoolean(properties, "collection"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetStringList() { List collection = yamlUtils.getStringList(properties, "collection"); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); try { yamlUtils.requireMap(Arrays.asList(1, 2), "key"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java index 6fcd0d5fc..e4d543c24 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java @@ -2,16 +2,16 @@ import com.tencent.trpc.container.config.ApplicationConfigParser; import com.tencent.trpc.core.extension.ExtensionLoader; -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; public class EnvironmentConfigurationTest { private Environment environment; - @Before + @BeforeEach public void init() { System.setProperty("global.namespace", "${env_type_enhancer}"); System.setProperty("server.app", "wechat"); @@ -34,7 +34,7 @@ public void init() { environment = new Environment(parser); } - @After + @AfterEach public void teardown() { System.clearProperty("global.namespace"); System.clearProperty("server.app"); @@ -57,6 +57,6 @@ public void teardown() { @Test public void testGetInternalProperty() { Object internalProperty = environment.getInternalProperty("server.app"); - Assert.assertEquals(internalProperty, "wechat"); + Assertions.assertEquals(internalProperty, "wechat"); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java index 25e91f60e..8c0cae980 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java @@ -11,19 +11,19 @@ package com.tencent.trpc.container.config.system; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.container.config.ApplicationConfigParser; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.extension.ExtensionLoader; import java.util.Map; import java.util.NoSuchElementException; -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; /** * Environment test class @@ -34,7 +34,7 @@ public class EnvironmentTest { private ConfigManager configManager; private ConfigManager otherConfigManager; - @Before + @BeforeEach public void init() { System.setProperty("global.namespace", "${env_type_enhancer}"); System.setProperty("server.app", "wechat"); @@ -59,7 +59,7 @@ public void init() { otherConfigManager = environment.parse(); } - @After + @AfterEach public void teardown() { System.clearProperty("global.namespace"); System.clearProperty("server.app"); @@ -123,9 +123,11 @@ public void testOverrideConfig() { assertEquals(protocol, configManager.getClientConfig().getProtocol()); } - @Test(expected = IllegalStateException.class) + @Test public void testInteger() { - environment.getInteger("global.namespace", 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getInteger("global.namespace", 2); + }); } @Test @@ -133,54 +135,74 @@ public void testBoolean() { environment.getBoolean("global.namespace", true); } - @Test(expected = IllegalStateException.class) + @Test public void testShort() { - environment.getShort("global.namespace", (short) 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getShort("global.namespace", (short) 2); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testByte() { - environment.getByte("global.namespace", (byte) 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getByte("global.namespace", (byte) 2); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testFloat() { - environment.getFloat("global.namespace", 2f); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getFloat("global.namespace", 2f); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testDouble() { - environment.getDouble("global.namespace", 2d); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getDouble("global.namespace", 2d); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testIntNoElement() { - environment.getInt("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getInt("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testBooleanNoElement() { - environment.getBoolean("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getBoolean("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testShortNoElement() { - environment.getShort("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getShort("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testByteNoElement() { - environment.getByte("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getByte("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testFloatNoElement() { - environment.getFloat("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getFloat("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testDoubleNoElement() { - environment.getDouble("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getDouble("global.namespace.not.exist"); + }); } @Test diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java index 7f216d975..0bfa80171 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java @@ -1,17 +1,16 @@ package com.tencent.trpc.container.config.system; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SystemConfigurationTest { @Test public void testGetInternalProperty() { - System.setProperty("testSysProperty","1"); + System.setProperty("testSysProperty", "1"); SystemConfiguration systemConfiguration = new SystemConfiguration(); Object result = systemConfiguration.getInternalProperty("testSysProperty"); assertEquals("1", result); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java index c03eb914f..3919db6f4 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java @@ -3,18 +3,17 @@ import com.tencent.trpc.container.config.system.Configuration; import com.tencent.trpc.core.utils.YamlParser; 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; -public class DefaultPropertySourceParserTest extends TestCase { +public class DefaultPropertySourceParserTest { @Test public void testGetFlattableMap() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); Map flattableMap = propertySourceParser.getFlattableMap(yamlConfigMap); - Assert.assertEquals(147, flattableMap.size()); + Assertions.assertEquals(147, flattableMap.size()); } @Test @@ -22,8 +21,8 @@ public void testParseFlattableMap() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); Map stringObjectMap = propertySourceParser.parseFlattableMap(yamlConfigMap); - Assert.assertEquals(4, stringObjectMap.size()); + Assertions.assertEquals(4, stringObjectMap.size()); Boolean aBoolean = Configuration.toBooleanObject(true); - Assert.assertTrue(aBoolean); + Assertions.assertTrue(aBoolean); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java index 708675a0e..fbd81e718 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java @@ -13,8 +13,8 @@ import com.tencent.trpc.core.common.config.BackendConfig; import com.tencent.trpc.core.utils.YamlParser; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -27,18 +27,18 @@ public class BackendConfigParserTest { @Test public void testParseConfigMap() { BackendConfigParser backendConfigParser = new BackendConfigParser(); - Assert.assertNotNull(backendConfigParser); + Assertions.assertNotNull(backendConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); List> maps = Arrays.asList(yamlConfigMap); Map stringBackendConfigMap = BackendConfigParser.parseConfigMap(maps); - Assert.assertNotNull(stringBackendConfigMap); + Assertions.assertNotNull(stringBackendConfigMap); } @Test public void testParseConfig() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); BackendConfig backendConfig = BackendConfigParser.parseConfig(yamlConfigMap); - Assert.assertNotNull(backendConfig); + Assertions.assertNotNull(backendConfig); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java index f24338bfa..77bedf1b7 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java @@ -4,8 +4,8 @@ import com.tencent.trpc.core.common.config.ClientConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -14,11 +14,11 @@ public class ClientConfigParserTest { @Test public void testParseClientConfig() { ClientConfigParser clientConfigParser = new ClientConfigParser(); - Assert.assertNotNull(clientConfigParser); + Assertions.assertNotNull(clientConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); ClientConfig clientConfig = ClientConfigParser.parseClientConfig(yamlUtils.getMap(yamlConfigMap, ConfigConstants.CLIENT)); - Assert.assertNotNull(clientConfig.getNamespace()); + Assertions.assertNotNull(clientConfig.getNamespace()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java index a755fca6e..2b763bad1 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java @@ -4,23 +4,22 @@ import com.tencent.trpc.core.common.config.GlobalConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Map; -public class GlobalConfigParserTest extends TestCase { +public class GlobalConfigParserTest { @Test public void testParseGlobalConfig() { GlobalConfigParser globalConfigParser = new GlobalConfigParser(); - Assert.assertNotNull(globalConfigParser); + Assertions.assertNotNull(globalConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map map = yamlUtils.getMap(yamlConfigMap, ConfigConstants.GLOBAL); GlobalConfig globalConfig = GlobalConfigParser.parseGlobalConfig(map); - Assert.assertNotNull(globalConfig.getNamespace()); - Assert.assertNotNull(globalConfig.getEnvName()); + Assertions.assertNotNull(globalConfig.getNamespace()); + Assertions.assertNotNull(globalConfig.getEnvName()); GlobalConfigParser.parseGlobalConfig(null); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java index 5c58a5516..ec1053377 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java @@ -1,22 +1,21 @@ package com.tencent.trpc.container.config.yaml; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; -public class ParseErrorInfoTest extends TestCase { +public class ParseErrorInfoTest { @Test public void testInfo() { ParseErrorInfo parseErrorInfo = new ParseErrorInfo(); - Assert.assertNotNull(parseErrorInfo); + Assertions.assertNotNull(parseErrorInfo); String info = ParseErrorInfo.info("key", "value"); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); } @Test public void testTestInfo() { String info = ParseErrorInfo.info("key", "index", "value"); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java index f63f95b05..cb0d2cc4a 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -20,15 +20,15 @@ import java.util.HashMap; import java.util.List; 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 PluginConfigParserHelperTest { @Test public void testParseAllPluginConfig() { PluginConfigParserHelper pluginConfigParserHelper = new PluginConfigParserHelper(); - Assert.assertNotNull(pluginConfigParserHelper); + Assertions.assertNotNull(pluginConfigParserHelper); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); @@ -37,11 +37,11 @@ public void testParseAllPluginConfig() { checkRegistry(plugins.get(Registry.class).get("polaris")); try { Map mockMap = new HashMap(); - mockMap.put("key","v"); + mockMap.put("key", "v"); PluginConfigParserHelper .parseAllPluginConfig(yamlUtils.getMap(mockMap, ConfigConstants.PLUGINS)); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } try { Map mockMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); @@ -50,7 +50,7 @@ public void testParseAllPluginConfig() { PluginConfigParserHelper .parseAllPluginConfig(yamlUtils.getMap(mockMap, ConfigConstants.PLUGINS)); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @@ -62,34 +62,32 @@ public void testParsePluginConfig() { .getMap(yamlConfigMap, ConfigConstants.PLUGINS) .get("registry"); Map plugins = PluginConfigParserHelper - .parsePluginConfig("plugin(type=registry)",Registry.class,polaris); + .parsePluginConfig("plugin(type=registry)", Registry.class, polaris); checkRegistry(plugins.get("polaris")); try { - Map mockMap = new HashMap(); - mockMap.put("key1","v"); - mockMap.put("key1","v"); + Map mockMap = new HashMap(); + mockMap.put("key1", "v"); + mockMap.put("key1", "v"); PluginConfigParserHelper - .parsePluginConfig("plugin(type=registry)",Registry.class,mockMap); + .parsePluginConfig("plugin(type=registry)", Registry.class, mockMap); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } - - private void checkRegistry(PluginConfig config) { - Assert.assertEquals(config.getName(), "polaris"); - Assert.assertEquals(config.getPluginInterface(), Registry.class); - Assert.assertEquals(config.getPluginClass(), PolarisRegistry.class); - Assert.assertEquals(config.getProperties().get("address_list"), "10.235.25.48:8090"); - Assert.assertEquals(config.getProperties().get("register_self"), false); + Assertions.assertEquals(config.getName(), "polaris"); + Assertions.assertEquals(config.getPluginInterface(), Registry.class); + Assertions.assertEquals(config.getPluginClass(), PolarisRegistry.class); + Assertions.assertEquals(config.getProperties().get("address_list"), "10.235.25.48:8090"); + Assertions.assertEquals(config.getProperties().get("register_self"), false); List> services = (List>) config.getProperties() .get(ConfigConstants.SERVICE); - Assert.assertEquals(services.get(0).get("namespace"), "java-sdk-test-service1"); - Assert.assertEquals(services.get(0).get("token"), "xxxx"); - Assert.assertEquals(services.get(0).get("instance_id"), + Assertions.assertEquals(services.get(0).get("namespace"), "java-sdk-test-service1"); + Assertions.assertEquals(services.get(0).get("token"), "xxxx"); + Assertions.assertEquals(services.get(0).get("instance_id"), "feda4ceffed0b7b08cf5ec665dcd320e50434549"); - Assert.assertEquals(services.get(0).get("name"), "trpc.TestApp.TestServer.Greeter"); + Assertions.assertEquals(services.get(0).get("name"), "trpc.TestApp.TestServer.Greeter"); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java index 6e85f1fab..7553846fa 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java @@ -4,21 +4,20 @@ import com.tencent.trpc.core.common.config.PluginConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Map; -public class PluginConfigParserTest extends TestCase { +public class PluginConfigParserTest { @Test public void testParsePlugins() { PluginConfigParser pluginConfigParser = new PluginConfigParser(); - Assert.assertNotNull(pluginConfigParser); + Assertions.assertNotNull(pluginConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); - Assert.assertNotNull(classMapMap.getClass()); + Assertions.assertNotNull(classMapMap.getClass()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java index 5981abde0..9a394a38e 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.container.config.yaml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import com.tencent.trpc.container.config.YamlUtils; import com.tencent.trpc.container.container.DefaultServerListener; @@ -24,9 +24,9 @@ import java.util.HashMap; import java.util.List; 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; /** * ServerConfigParser test class @@ -37,7 +37,7 @@ public class ServerConfigParserTest { private List> serverListenerConfig; - @Before + @BeforeEach public void before() { this.yamlUtils = new YamlUtils(""); } @@ -45,14 +45,14 @@ public void before() { @Test public void testParseDefaultStartedListeners() { ServerConfigParser serverConfigParser = new ServerConfigParser(); - Assert.assertNotNull(serverConfigParser); + Assertions.assertNotNull(serverConfigParser); List serverListeners = ServerConfigParser.parseStartedListeners(yamlUtils, serverListenerConfig); assertNotNull(serverListeners); assertEquals(serverListeners.size(), 0); try { ServerConfig serverConfig = ServerConfigParser.parseServerConfig(null, null); - Assert.assertNotNull(serverConfig); + Assertions.assertNotNull(serverConfig); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java index 8b18eeda5..cdb0c3b91 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java @@ -5,25 +5,24 @@ import com.tencent.trpc.core.common.config.ServiceConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Arrays; import java.util.Map; -public class ServiceConfigParserTest extends TestCase { +public class ServiceConfigParserTest { @Test public void testParseServiceMapConfig() { ServiceConfigParser serviceConfigParser = new ServiceConfigParser(); - Assert.assertNotNull(serviceConfigParser); + Assertions.assertNotNull(serviceConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); Map stringServiceConfigMap = ServiceConfigParser.parseServiceMapConfig(Arrays.asList(yamlConfigMap), classMapMap); - Assert.assertEquals(1,stringServiceConfigMap.size()); + Assertions.assertEquals(1, stringServiceConfigMap.size()); } @Test @@ -33,6 +32,6 @@ public void testParseServiceConfig() { Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); ServiceConfig serviceConfig = ServiceConfigParser.parseServiceConfig(yamlConfigMap, classMapMap); - Assert.assertFalse(serviceConfig.isSetDefault()); + Assertions.assertFalse(serviceConfig.isSetDefault()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java index 8e56a9a0f..440889cfa 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.container.config.yaml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.common.TRpcSystemProperties; @@ -28,19 +28,19 @@ import com.tencent.trpc.core.utils.YamlParser; import java.util.Map; import org.apache.commons.collections4.MapUtils; -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; public class YamlApplicationConfigParserTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -276,7 +276,7 @@ public void testParseMap() { ConfigManager.stopTest(); String path = YamlParser.class.getClassLoader().getResource("trpc_java.yaml").getPath(); Map map = new YamlApplicationConfigParser().parseMap(path); - Assert.assertNotEquals(map.size(), 0); + Assertions.assertNotEquals(map.size(), 0); } @Test @@ -284,11 +284,11 @@ public void testParseMap_confPath() { ConfigManager.stopTest(); TRpcSystemProperties.setProperties(TRpcSystemProperties.CONFIG_PATH, ""); Map map1 = new YamlApplicationConfigParser().parseMap(""); - Assert.assertNotNull(map1); + Assertions.assertNotNull(map1); String path = YamlParser.class.getClassLoader().getResource("trpc_java.yaml").getPath(); TRpcSystemProperties.setProperties(TRpcSystemProperties.CONFIG_PATH, path); Map map = new YamlApplicationConfigParser().parseMap(""); - Assert.assertNotEquals(map.size(), 0); + Assertions.assertNotEquals(map.size(), 0); } @Test @@ -300,20 +300,20 @@ public void testParseImpls() { applicationConfig.setDefault(); ProviderConfig providerConfig1 = applicationConfig.getServerConfig().getServiceMap() .get("trpc.TestApp.TestServer.Greeter").getProviderConfigs().get(0); - Assert.assertEquals(providerConfig1.getRequestTimeout(), 2000); - Assert.assertEquals(providerConfig1.getWorkerPool(), "trpc_provider_biz_def"); - Assert.assertEquals(providerConfig1.getFilters().size(), 2); - Assert.assertEquals(providerConfig1.getFilters().get(0), "a"); - Assert.assertEquals(providerConfig1.getFilters().get(1), "b"); - Assert.assertFalse(providerConfig1.getEnableLinkTimeout()); + Assertions.assertEquals(providerConfig1.getRequestTimeout(), 2000); + Assertions.assertEquals(providerConfig1.getWorkerPool(), "trpc_provider_biz_def"); + Assertions.assertEquals(providerConfig1.getFilters().size(), 2); + Assertions.assertEquals(providerConfig1.getFilters().get(0), "a"); + Assertions.assertEquals(providerConfig1.getFilters().get(1), "b"); + Assertions.assertFalse(providerConfig1.getEnableLinkTimeout()); ProviderConfig providerConfig2 = applicationConfig.getServerConfig().getServiceMap() .get("trpc.TestApp.TestServer.Greeter").getProviderConfigs().get(1); - Assert.assertEquals(providerConfig2.getRequestTimeout(), Integer.MAX_VALUE); - Assert.assertEquals(providerConfig2.getWorkerPool(), "trpc_provider_biz_def"); - Assert.assertEquals(providerConfig2.getFilters().size(), 1); - Assert.assertEquals(providerConfig2.getFilters().get(0), "c"); - Assert.assertTrue(providerConfig2.getEnableLinkTimeout()); + Assertions.assertEquals(providerConfig2.getRequestTimeout(), Integer.MAX_VALUE); + Assertions.assertEquals(providerConfig2.getWorkerPool(), "trpc_provider_biz_def"); + Assertions.assertEquals(providerConfig2.getFilters().size(), 1); + Assertions.assertEquals(providerConfig2.getFilters().get(0), "c"); + Assertions.assertTrue(providerConfig2.getEnableLinkTimeout()); } @Test diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java index bb76a4c6e..b87cab833 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java @@ -11,8 +11,9 @@ package com.tencent.trpc.container.container; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Assertions; import com.google.protobuf.ByteString; import com.tencent.trpc.container.demo.HelloRequestProtocol.HelloRequest; import com.tencent.trpc.container.demo.HelloRequestProtocol.HelloResponse; @@ -22,15 +23,15 @@ import com.tencent.trpc.core.exception.TRpcException; import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.TRpcProxy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ConsumerProxyTest { Container container; - @Before + @BeforeEach public void before() throws Exception { ConfigManager.startTest(); container = new DefaultContainer(); @@ -38,7 +39,7 @@ public void before() throws Exception { container.start(); } - @After + @AfterEach public void after() { if (container != null) { container.stop(); @@ -60,13 +61,15 @@ public void getProxy() { System.out.println("namingOptions:>>>>>>>>>>>>>" + backendConfig.getNamingOptions()); } - @Test(expected = TRpcException.class) + @Test public void notConnect() { - String servcieId = "trpc.TestApp.TestServer.Notconnect"; - com.tencent.trpc.container.demo.GreeterClient service = TRpcProxy.getProxy(servcieId); - service.sayHello(new RpcClientContext(), HelloRequest.newBuilder() - .setMessage(ByteString.copyFrom("abc".getBytes())) - .build()); + Assertions.assertThrows(TRpcException.class, () -> { + String servcieId = "trpc.TestApp.TestServer.Notconnect"; + com.tencent.trpc.container.demo.GreeterClient service = TRpcProxy.getProxy(servcieId); + service.sayHello(new RpcClientContext(), HelloRequest.newBuilder() + .setMessage(ByteString.copyFrom("abc".getBytes())) + .build()); + }); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java index 08c359630..a2af534ef 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,23 +11,23 @@ package com.tencent.trpc.container.container; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.google.protobuf.ByteString; import com.tencent.trpc.container.demo.HelloRequestProtocol; import com.tencent.trpc.core.container.spi.Container; import com.tencent.trpc.core.extension.ExtensionLoader; import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.TRpcProxy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DefaultContainerTest { Container container; - @Before + @BeforeEach public void start() { container = ExtensionLoader.getExtensionLoader(Container.class).getExtension("default"); @@ -45,7 +45,7 @@ public void testStart() { assertEquals(sayHello.getMessage().toStringUtf8(), "abc-"); } - @After + @AfterEach public void testStop() throws InterruptedException { Thread.sleep(1000); container.stop(); diff --git a/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml b/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml index fae3432a6..37ae74f4f 100644 --- a/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml +++ b/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml @@ -20,7 +20,7 @@ server: impls: - com.tencent.trpc.container.demo.GreeterServiceImp ip: 127.0.0.1 - port: 12345 + port: 13345 network: tcp protocol: trpc @@ -29,7 +29,7 @@ client: service: - name: trpc.TestApp.TestServer.Greeter interface: com.tencent.trpc.container.demo.GreeterClient - naming_url: ip://127.0.0.1:12345 + naming_url: ip://127.0.0.1:13345 - name: trpc.TestApp.TestServer.Notconnect interface: com.tencent.trpc.container.demo.GreeterClient naming_url: ip://127.0.0.1:9999 From 8e6543c744700407e8e07c40ba7fb1da9b7497ee Mon Sep 17 00:00:00 2001 From: wardseptember Date: Mon, 19 Jan 2026 20:00:27 +0800 Subject: [PATCH 5/8] feat: optimize trpc-core test --- .../common/config/ProviderConfigTest.java | 82 +++++++++---------- .../trpc/core/utils/JsonUtilsTest.java | 74 +++++++++-------- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java index 635da2aa0..3b5ae8fc7 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,11 +11,11 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -34,29 +34,25 @@ import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool; import java.util.HashMap; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.ArgumentMatcher; 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; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ExtensionLoader.class, RpcServerManager.class, FilterManager.class}) -@PowerMockIgnore({"javax.management.*"}) +import org.mockito.MockedStatic; + +@ExtendWith(MockitoExtension.class) public class ProviderConfigTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -82,19 +78,19 @@ public void testInitServiceInterfaceConfig() { @Test public void testInit() { - PowerMockito.mockStatic(ExtensionLoader.class); - PowerMockito.mockStatic(RpcServerManager.class); - ExtensionLoader mock = PowerMockito.mock(ExtensionLoader.class); - PowerMockito.when(ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock); - PowerMockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true); - PowerMockito.when(ExtensionLoader.getPluginConfigMap()).then(v -> v.callRealMethod()); + Mockito.mockStatic(ExtensionLoader.class); + Mockito.mockStatic(RpcServerManager.class); + ExtensionLoader mock = Mockito.mock(ExtensionLoader.class); + Mockito.when(ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock); + Mockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true); + Mockito.when(ExtensionLoader.getPluginConfigMap()).then(v -> v.callRealMethod()); ThreadWorkerPool threadWorkerPool = new ThreadWorkerPool(); threadWorkerPool.setPluginConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_CONFIG); threadWorkerPool.init(); - PowerMockito.when(ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock); - PowerMockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool); - Filter mockFilter = PowerMockito.mock(Filter.class); - PowerMockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter); + Mockito.when(ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock); + Mockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool); + Filter mockFilter = Mockito.mock(Filter.class); + Mockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter); ExtensionLoader.getExtensionLoader(Filter.class); ServiceConfig serviceConfig = new ServiceConfig(); serviceConfig.setName("protoid"); @@ -111,21 +107,21 @@ public void testInit() { configMap.put("registyId", new PluginConfig("registyId", MockRegistry.class, extMap)); ConfigManager.getInstance().getPluginConfigMap().put(Registry.class, configMap); config.init(); - RpcServer rpcServerMock = PowerMockito.mock(RpcServer.class); - PowerMockito.when(RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid()))) + RpcServer rpcServerMock = Mockito.mock(RpcServer.class); + Mockito.when(RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid()))) .thenReturn(rpcServerMock); - PowerMockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig()); + Mockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig()); serviceConfig.export(); Mockito.verify(rpcServerMock, Mockito.times(1)).export(Mockito.any(ProviderInvoker.class)); Mockito.verify(rpcServerMock, Mockito.times(1)).open(); assertTrue(serviceConfig.isExported()); serviceConfig.unExport(); assertFalse(serviceConfig.isExported()); - ExtensionLoader mockRegistryLoader = PowerMockito.mock(ExtensionLoader.class); - PowerMockito.when(ExtensionLoader.getExtensionLoader(Registry.class)) + ExtensionLoader mockRegistryLoader = Mockito.mock(ExtensionLoader.class); + Mockito.when(ExtensionLoader.getExtensionLoader(Registry.class)) .thenReturn(mockRegistryLoader); - Registry registry = PowerMockito.mock(Registry.class); - PowerMockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry); + Registry registry = Mockito.mock(Registry.class); + Mockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry); } @Test @@ -226,12 +222,16 @@ public static class TRpcServiceInstance implements TRpcServiceInterface { } - private class IsValid extends ArgumentMatcher { + private class IsValid implements ArgumentMatcher { + + @Override + public boolean matches(ProtocolConfig protocolConfig) { + return protocolConfig.getIp().contentEquals("127.0.0.1"); + } @Override - public boolean matches(Object o) { - ProtocolConfig ox = (ProtocolConfig) o; - return ox.getIp().contentEquals("127.0.0.1"); + public Class type() { + return ProtocolConfig.class; } } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/JsonUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/JsonUtilsTest.java index 4a8636a23..c77a26d71 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/JsonUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/JsonUtilsTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -24,8 +24,8 @@ import java.util.List; import java.util.Map; import org.assertj.core.util.Strings; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JsonUtilsTest { @@ -37,75 +37,77 @@ public class JsonUtilsTest { @Test public void testCopy() { ObjectMapper objectMapper = JsonUtils.copy(); - Assert.assertNotNull(objectMapper); + Assertions.assertNotNull(objectMapper); } - @Test(expected = TRpcException.class) + @Test public void testFromInputStream() { - JsonUtils.fromInputStream(new InputStream() { - @Override - public int read() throws IOException { - return 0; - } - }, Object.class); + Assertions.assertThrows(TRpcException.class, () -> { + JsonUtils.fromInputStream(new InputStream() { + @Override + public int read() throws IOException { + return 0; + } + }, Object.class); + }); } @Test public void testFromJson() { TestObj obj = JsonUtils.fromJson(JSON, TestObj.class); - Assert.assertEquals(obj.getTest(), 123); + Assertions.assertEquals(obj.getTest(), 123); TestObj objRef = JsonUtils.fromJson(JSON, new TypeReference() { }); - Assert.assertEquals(objRef.getTest(), 123); + Assertions.assertEquals(objRef.getTest(), 123); List testObjs = JsonUtils.fromJson(JSON_LIST, JsonUtils.copy().getTypeFactory() .constructCollectionType(Collection.class, TestObj.class)); - Assert.assertEquals(testObjs.get(0).getTest(), 123); + Assertions.assertEquals(testObjs.get(0).getTest(), 123); try { JsonUtils.fromJson(ERROR_JSON, TestObj.class); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } try { JsonUtils.fromJson(ERROR_JSON, JsonUtils.copy().getTypeFactory().constructCollectionType( - Collection.class, TestObj.class)); + Collection.class, TestObj.class)); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } try { JsonUtils.fromJson(ERROR_JSON, new TypeReference() { }); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } } @Test public void testFromBytes() { TestObj obj = JsonUtils.fromBytes(JSON.getBytes(Charsets.UTF_8), TestObj.class); - Assert.assertEquals(obj.getTest(), 123); + Assertions.assertEquals(obj.getTest(), 123); TestObj objRef = JsonUtils.fromBytes(JSON.getBytes(Charsets.UTF_8), new TypeReference() { }); - Assert.assertEquals(objRef.getTest(), 123); + Assertions.assertEquals(objRef.getTest(), 123); objRef = JsonUtils.fromBytes(JSON, new TypeReference() { }); - Assert.assertEquals(objRef.getTest(), 123); + Assertions.assertEquals(objRef.getTest(), 123); try { JsonUtils.fromBytes(ERROR_JSON.getBytes(Charsets.UTF_8), TestObj.class); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } try { JsonUtils.fromBytes(ERROR_JSON.getBytes(Charsets.UTF_8), new TypeReference() { }); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } try { JsonUtils.fromBytes(ERROR_JSON, new TypeReference() { }); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } } @@ -114,15 +116,15 @@ public void testToJson() { TestObj obj = new TestObj(); obj.setTest(123); String json = JsonUtils.toJson(obj); - Assert.assertEquals(json, JSON); + Assertions.assertEquals(json, JSON); TestObj1 obj1 = new TestObj1(); obj1.setTest(123); try { JsonUtils.toJson(obj1); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } - Assert.assertFalse(Strings.isNullOrEmpty( + Assertions.assertFalse(Strings.isNullOrEmpty( JsonUtils.toJson(ProtoJsonConverter.messageToMap(HelloRequest.getDefaultInstance())))); } @@ -131,11 +133,11 @@ public void testToJsonWithDefaultValue() { TestObj obj = new TestObj(); obj.setTest(123); String json = JsonUtils.toJson(obj, "aaa"); - Assert.assertEquals(json, JSON); + Assertions.assertEquals(json, JSON); TestObj1 obj1 = new TestObj1(); obj1.setTest(123); String aaa = JsonUtils.toJson(obj1, "aaa"); - Assert.assertEquals(EMPTY_JSON, aaa); + Assertions.assertEquals(EMPTY_JSON, aaa); } @Test @@ -143,13 +145,13 @@ public void testToBytes() { TestObj obj = new TestObj(); obj.setTest(123); byte[] bytes = JsonUtils.toBytes(obj); - Assert.assertEquals(new String(bytes), JSON); + Assertions.assertEquals(new String(bytes), JSON); TestObj1 obj1 = new TestObj1(); obj1.setTest(123); try { JsonUtils.toBytes(obj1); } catch (TRpcException e) { - Assert.assertEquals(e.getCode(), 2001); + Assertions.assertEquals(e.getCode(), 2001); } } @@ -160,10 +162,10 @@ public void testGeneric() { testObj.setTest(11); obj.setData(testObj); String json = JsonUtils.toJson(obj); - Assert.assertEquals(json, "{\"data\":{\"test\":11}}"); + Assertions.assertEquals(json, "{\"data\":{\"test\":11}}"); TestObj2 obj2 = JsonUtils.fromJson(json, new TypeReference>() { }); - Assert.assertEquals(obj2.getData().getTest(), 11); + Assertions.assertEquals(obj2.getData().getTest(), 11); } @@ -174,14 +176,14 @@ public void testConvertValue() { mapValue.put("unknown", 111); mapValue.put("12", 12); TestConfigObject testConfigObject = JsonUtils.convertValue(mapValue, TestConfigObject.class); - Assert.assertEquals("123", testConfigObject.getData()); + Assertions.assertEquals("123", testConfigObject.getData()); try { JsonUtils.convertValue(mapValue, Discovery.class); } catch (Exception e) { - Assert.assertNotNull(e); + Assertions.assertNotNull(e); return; } - Assert.fail(); + Assertions.fail(); } From 146b627d844340c7c4f0cab5ba4eb0380a255a01 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Mon, 19 Jan 2026 20:22:36 +0800 Subject: [PATCH 6/8] feat: optimize trpc-core test --- .../core/admin/AdminServiceManagerTest.java | 4 +- .../core/admin/TRpcFrameOverviewTest.java | 8 +- .../ClusterInterceptorInvokerTest.java | 24 +-- .../ClusterInterceptorManagerTest.java | 14 +- .../cluster/RpcClusterClientManagerTest.java | 8 +- .../StandardRpcClusterClientFactoryTest.java | 8 +- .../def/DefClusterInvocationHandlerTest.java | 54 +++--- .../def/DefClusterInvokerMockWrapperTest.java | 26 +-- .../cluster/def/DefClusterInvokerTest.java | 50 +++--- .../cluster/def/DefRpcClusterClientTest.java | 20 +-- .../trpc/core/common/ConfigManagerTest.java | 42 ++--- .../trpc/core/common/LifeCycleTest.java | 13 +- .../core/common/NamedThreadFactoryTest.java | 12 +- .../core/common/TRpcPluginTypeAliasTest.java | 6 +- .../core/common/TRpcSystemPropertiesTest.java | 24 +-- .../tencent/trpc/core/common/VersionTest.java | 8 +- .../common/config/ApplicationConfigTest.java | 4 +- .../core/common/config/BackendConfigTest.java | 22 +-- .../common/config/BaseProtocolConfigTest.java | 110 ++++++------ .../core/common/config/ClientConfigTest.java | 8 +- .../common/config/ConfigCenterConfigTest.java | 2 +- .../trpc/core/common/config/ConfigTest.java | 2 +- .../common/config/ConsumerConfigTest.java | 20 +-- .../core/common/config/GlobalConfigTest.java | 36 ++-- .../core/common/config/NamingOptionsTest.java | 6 +- .../core/common/config/PluginConfigTest.java | 6 +- .../common/config/ProtocolConfigTest.java | 12 +- .../common/config/ProviderConfigTest.java | 1 - .../core/common/config/ServerConfigTest.java | 4 +- .../core/common/config/ServiceConfigTest.java | 10 +- .../builder/PluginConfigBuilderTest.java | 10 +- .../core/common/timer/HashWheelTimerTest.java | 24 +-- .../trpc/core/compressor/CompressorTest.java | 22 +-- .../configcenter/ConfigurationEventTest.java | 6 +- .../ConfigurationManagerTest.java | 20 +-- .../core/exception/ErrorCodeUtilsTest.java | 16 +- .../core/exception/ExceptionHelperTest.java | 61 +++---- .../LimiterBlockHandlerExceptionTest.java | 20 +-- .../LimiterDatasourceExceptionTest.java | 20 +-- .../core/exception/LimiterExceptionTest.java | 20 +-- .../LimiterFallbackExceptionTest.java | 20 +-- .../core/exception/TRpcExceptionTest.java | 52 +++--- .../core/extension/ExtensionLoaderTest.java | 158 +++++++++--------- .../filter/ConsumerFilterInvokerTest.java | 22 +-- .../filter/ProviderFilterInvokerTest.java | 24 +-- .../limiter/DefLimiterBlockHandlerTest.java | 8 +- .../core/limiter/DefLimiterFallbackTest.java | 10 +- .../DefLimiterResourceExtractorTest.java | 6 +- .../trpc/core/logger/LoggerFactoryTest.java | 30 ++-- .../core/logger/RemoteLoggerFilterTest.java | 16 +- .../logger/slf4j/Slf4jLoggerAdapterTest.java | 16 +- .../core/logger/slf4j/Slf4jLoggerTest.java | 51 +++--- .../ThreadPerTaskExecutorMXBeanTest.java | 22 +-- .../ThreadPerTaskExecutorWrapperTest.java | 26 +-- .../core/metrics/ActiveInvocationTest.java | 30 ++-- .../trpc/core/metrics/MetricNameTest.java | 26 +-- .../trpc/core/metrics/MetricsCustomTest.java | 6 +- .../trpc/core/metrics/MetricsTest.java | 32 ++-- .../core/metrics/PassiveInvocationTest.java | 30 ++-- .../spi/AbstractMetricsFactoryTest.java | 34 ++-- .../tencent/trpc/core/notify/NotifyTest.java | 4 +- .../support/ByteBuddyProxyFactoryTest.java | 6 +- .../proxy/support/JdkProxyFactoryTest.java | 6 +- .../trpc/core/registry/RegisterInfoTest.java | 18 +- .../trpc/core/rpc/AbstractRpcClientTest.java | 14 +- .../trpc/core/rpc/AbstractRpcServerTest.java | 14 +- .../tencent/trpc/core/rpc/CallInfoTest.java | 52 +++--- .../tencent/trpc/core/rpc/DefRequestTest.java | 12 +- .../trpc/core/rpc/DefResponseTest.java | 14 +- .../tencent/trpc/core/rpc/InvokeModeTest.java | 4 +- .../trpc/core/rpc/RequestMetaTest.java | 46 ++--- .../trpc/core/rpc/ResponseMetaTest.java | 12 +- .../tencent/trpc/core/rpc/RpcContextTest.java | 10 +- .../trpc/core/rpc/RpcContextUtilsTest.java | 4 +- .../trpc/core/rpc/RpcInvocationTest.java | 16 +- .../trpc/core/rpc/RpcServerContextTest.java | 8 +- .../trpc/core/rpc/RpcServerMapTest.java | 56 +++---- .../tencent/trpc/core/rpc/TRpcProxyTest.java | 51 +++--- .../core/rpc/common/MethodRouterKeyTest.java | 4 +- .../common/RpcMethodInfoAndInvokerTest.java | 8 +- .../core/rpc/common/RpcMethodInfoTest.java | 4 +- .../trpc/core/rpc/def/DecodableValueTest.java | 12 +- .../rpc/def/DefMethodInfoRegisterTest.java | 36 ++-- .../core/rpc/def/DefProviderInvokerTest.java | 20 +-- .../trpc/core/rpc/def/EncodableValueTest.java | 18 +- .../trpc/core/rpc/def/LeftTimeoutTest.java | 10 +- .../core/rpc/def/LinkInvokeTimeoutTest.java | 14 +- .../selector/AbstractCircuitBreakerTest.java | 2 +- .../AbstractDiscoveryFactoryTest.java | 4 +- .../selector/AbstractLoadBalanceTest.java | 6 +- .../trpc/core/selector/ClusterNamingTest.java | 30 ++-- .../trpc/core/selector/ListDiscoveryTest.java | 4 +- .../core/selector/NoneCircuitBreakerTest.java | 4 +- .../core/selector/RandomLoadBalanceTest.java | 4 +- .../trpc/core/selector/ServiceIdTest.java | 8 +- .../core/selector/ServiceInstanceTest.java | 29 ++-- .../def/AssembleSelectorConfigTest.java | 10 +- .../selector/support/ip/IpSelectorTest.java | 13 +- .../JavaPbSerializationTest.java | 54 +++--- .../serialization/JsonSerializationTest.java | 26 +-- .../serialization/PBSerializationTest.java | 32 ++-- .../SerializationSupportTest.java | 8 +- .../trpc/core/sign/SignSupportTest.java | 22 +-- .../stat/metrics/MetricStatFactoryTest.java | 4 +- .../trpc/core/stream/StreamCallTest.java | 24 +-- .../trpc/core/telemetry/SpanContextTest.java | 10 +- .../core/trace/TraceClientFilterTest.java | 18 +- .../core/trace/TraceServerFilterTest.java | 38 ++--- .../AbstractClientTransportTest.java | 4 +- .../AbstractServerTransportTest.java | 6 +- .../core/transport/ClientTransportTest.java | 16 +- .../transport/codec/AbstractCodecTest.java | 18 +- .../AbstractClientChannelHandlerTest.java | 8 +- .../handler/AcceptLimitHandlerTest.java | 6 +- .../trpc/core/utils/BinderUtilsTest.java | 116 ++++++------- .../tencent/trpc/core/utils/CharsetsTest.java | 4 +- .../trpc/core/utils/ClassLoaderUtilsTest.java | 12 +- .../trpc/core/utils/ClassUtilsTest.java | 42 ++--- .../trpc/core/utils/CollectionUtilsTest.java | 20 +-- .../core/utils/ConcurrentHashSetTest.java | 16 +- .../trpc/core/utils/FutureUtilsTest.java | 16 +- .../tencent/trpc/core/utils/IPUtilsTest.java | 38 ++--- .../tencent/trpc/core/utils/NetUtilsTest.java | 60 +++---- .../core/utils/PreconditionUtilsTest.java | 16 +- .../core/utils/ProtoJsonConverterTest.java | 14 +- .../trpc/core/utils/RpcContextUtilsTest.java | 18 +- .../tencent/trpc/core/utils/RpcUtilsTest.java | 156 +++++++++-------- .../tencent/trpc/core/utils/SeqUtilsTest.java | 6 +- .../trpc/core/utils/StringUtilsTest.java | 24 +-- .../tencent/trpc/core/utils/TimeUtilTest.java | 16 +- .../trpc/core/utils/TimerUtilTest.java | 14 +- .../trpc/core/utils/YamlParserTest.java | 12 +- .../core/worker/AbstractWorkerPoolTest.java | 57 +++---- .../core/worker/WorkerPoolManagerTest.java | 50 +++--- .../TrpcThreadExceptionHandlerTest.java | 10 +- .../thread/ForkJoinPoolConfigTest.java | 14 +- .../thread/ForkJoinWorkerPoolTest.java | 32 ++-- .../support/thread/ThreadPoolConfigTest.java | 18 +- .../support/thread/ThreadWorkerPoolTest.java | 44 ++--- .../java/org/slf4j/TrpcMDCAdapterTest.java | 6 +- 140 files changed, 1547 insertions(+), 1567 deletions(-) diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/admin/AdminServiceManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/admin/AdminServiceManagerTest.java index 326d2e9ca..2f24c3e3c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/admin/AdminServiceManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/admin/AdminServiceManagerTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.admin; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AdminServiceManagerTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/admin/TRpcFrameOverviewTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/admin/TRpcFrameOverviewTest.java index 91ae5204b..949da2324 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/admin/TRpcFrameOverviewTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/admin/TRpcFrameOverviewTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.admin; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TRpcFrameOverviewTest { @@ -22,7 +22,7 @@ public class TRpcFrameOverviewTest { public void test() { String trpcName = TRpcFrameOverview.getName(); assertEquals(trpcName, "trpc-java"); - Assert.assertNotNull(TRpcFrameOverview.getVersion()); + Assertions.assertNotNull(TRpcFrameOverview.getVersion()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorInvokerTest.java index eb64ecd8f..a54277ccd 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorInvokerTest.java @@ -21,9 +21,9 @@ import com.tencent.trpc.core.rpc.def.DefResponse; import com.tencent.trpc.core.utils.FutureUtils; import java.util.concurrent.CompletionStage; -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; public class ClusterInterceptorInvokerTest { @@ -33,7 +33,7 @@ public class ClusterInterceptorInvokerTest { /** * Init clusterInvoker & clusterInvokerNoInterceptors */ - @Before + @BeforeEach public void setUp() { ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setMock(false); @@ -80,20 +80,20 @@ public CompletionStage invoke(Request request) { public void testNew() { ClusterInterceptorInvoker invoker = new ClusterInterceptorInvoker<>(clusterInvoker); ConsumerConfig config = invoker.getConfig(); - Assert.assertNotNull(config); - Assert.assertFalse(config.getMock()); - Assert.assertTrue(invoker.getInterface().isAssignableFrom(BlankRpcServiceName.class)); - Assert.assertNotNull(invoker.getBackendConfig()); - Assert.assertEquals(invoker.getBackendConfig().getInterceptors().get(0), "log"); - Assert.assertNotNull(invoker.invoke(new DefRequest())); + Assertions.assertNotNull(config); + Assertions.assertFalse(config.getMock()); + Assertions.assertTrue(invoker.getInterface().isAssignableFrom(BlankRpcServiceName.class)); + Assertions.assertNotNull(invoker.getBackendConfig()); + Assertions.assertEquals(invoker.getBackendConfig().getInterceptors().get(0), "log"); + Assertions.assertNotNull(invoker.invoke(new DefRequest())); } @Test public void testNewNoInterceptor() { ClusterInterceptorInvoker invokerWithoutInterceptor = new ClusterInterceptorInvoker<>( clusterInvokerNoInterceptors); - Assert.assertNotNull(invokerWithoutInterceptor); - Assert.assertTrue(invokerWithoutInterceptor.getBackendConfig().getInterceptors().isEmpty()); + Assertions.assertNotNull(invokerWithoutInterceptor); + Assertions.assertTrue(invokerWithoutInterceptor.getBackendConfig().getInterceptors().isEmpty()); } @TRpcService diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorManagerTest.java index 31df27aef..b457c3d54 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/ClusterInterceptorManagerTest.java @@ -13,19 +13,21 @@ import com.tencent.trpc.core.cluster.spi.ClusterInterceptor; import com.tencent.trpc.core.cluster.spi.LogClusterInterceptor; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ClusterInterceptorManagerTest { @Test public void testGet() { ClusterInterceptor log = ClusterInterceptorManager.get("log"); - Assert.assertTrue(log instanceof LogClusterInterceptor); + Assertions.assertTrue(log instanceof LogClusterInterceptor); } - @Test(expected = IllegalArgumentException.class) + @Test public void testValidate() { - ClusterInterceptorManager.validate("log1"); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClusterInterceptorManager.validate("log1"); + }); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/RpcClusterClientManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/RpcClusterClientManagerTest.java index 1df2db4ed..ea3218d1a 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/RpcClusterClientManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/RpcClusterClientManagerTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.cluster; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.config.BackendConfig; import com.tencent.trpc.core.common.config.ConsumerConfig; @@ -22,8 +22,8 @@ import com.tencent.trpc.core.rpc.RpcClient; import java.lang.reflect.Field; 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 RpcClusterClientManagerTest { @@ -35,7 +35,7 @@ public void test() throws IllegalArgumentException, IllegalAccessException, NoSu backendConfig.setNamingUrl("ip://127.0.0.1"); ProtocolConfigTest config = new ProtocolConfigTest(); RpcClient rpcClient = RpcClusterClientManager.getOrCreateClient(backendConfig, config); - Assert.assertNotNull(rpcClient); + Assertions.assertNotNull(rpcClient); Field field = RpcClusterClientManager.class.getDeclaredField("CLUSTER_MAP"); field.setAccessible(true); Map clusterMap = (Map) field.get(null); diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/StandardRpcClusterClientFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/StandardRpcClusterClientFactoryTest.java index a7b2f0e3b..84626dd41 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/StandardRpcClusterClientFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/StandardRpcClusterClientFactoryTest.java @@ -13,8 +13,8 @@ import com.tencent.trpc.core.cluster.def.DefRpcClusterClient; import com.tencent.trpc.core.common.config.BackendConfig; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StandardRpcClusterClientFactoryTest { @@ -23,6 +23,6 @@ public void testCreate() { StandardRpcClusterClientFactory factory = new StandardRpcClusterClientFactory(); BackendConfig config = new BackendConfig(); RpcClusterClient standard = factory.create(config); - Assert.assertTrue(standard instanceof DefRpcClusterClient); + Assertions.assertTrue(standard instanceof DefRpcClusterClient); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvocationHandlerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvocationHandlerTest.java index b0c06ee80..edaf94348 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvocationHandlerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvocationHandlerTest.java @@ -39,16 +39,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.CompletionStage; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ClusterInvoker.class}) +@ExtendWith(MockitoExtension.class) public class DefClusterInvocationHandlerTest { private ClusterInvoker invoker; @@ -56,7 +54,7 @@ public class DefClusterInvocationHandlerTest { /** * Init invoker */ - @Before + @BeforeEach public void setUp() { ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setMock(false); @@ -106,13 +104,13 @@ public void testParseLeftTime() throws NoSuchMethodException, InvocationTargetEx method.setAccessible(true); LeftTimeout timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); - Assert.assertEquals(1000, timeout.getLeftTimeout()); - Assert.assertEquals(1000, timeout.getOriginTimeout()); + Assertions.assertEquals(1000, timeout.getLeftTimeout()); + Assertions.assertEquals(1000, timeout.getOriginTimeout()); rpcClientContext.setTimeoutMills(2000); timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); - Assert.assertEquals(2000, timeout.getLeftTimeout()); - Assert.assertEquals(2000, timeout.getOriginTimeout()); + Assertions.assertEquals(2000, timeout.getLeftTimeout()); + Assertions.assertEquals(2000, timeout.getOriginTimeout()); ConfigManager.getInstance().setDefault(); RpcContextUtils.putValueMapValue(rpcClientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, LinkInvokeTimeout.builder().startTime(System.currentTimeMillis() - 1) @@ -121,8 +119,8 @@ public void testParseLeftTime() throws NoSuchMethodException, InvocationTargetEx .serviceEnableLinkTimeout(false).build()); timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); - Assert.assertEquals(2000, timeout.getLeftTimeout()); - Assert.assertEquals(2000, timeout.getOriginTimeout()); + Assertions.assertEquals(2000, timeout.getLeftTimeout()); + Assertions.assertEquals(2000, timeout.getOriginTimeout()); // If the full-link timeout is enabled and the service itself has already taken 9500ms, // the remaining time will be based on the remaining time when it is less than the calling setting time. RpcContextUtils.putValueMapValue(rpcClientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, @@ -134,10 +132,10 @@ public void testParseLeftTime() throws NoSuchMethodException, InvocationTargetEx timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); // left time ms <= 10000 - 9500 - Assert.assertTrue(timeout.getLeftTimeout() > 0); - Assert.assertTrue(timeout.getLeftTimeout() <= 500); + Assertions.assertTrue(timeout.getLeftTimeout() > 0); + Assertions.assertTrue(timeout.getLeftTimeout() <= 500); // init time Math.min(10000,2000) - Assert.assertEquals(2000, timeout.getOriginTimeout()); + Assertions.assertEquals(2000, timeout.getOriginTimeout()); // If the full-link timeout is enabled and the service itself has taken 100ms, // the remaining time will be based on the calling setting time when it is greater than the remaining time. RpcContextUtils.putValueMapValue(rpcClientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, @@ -149,9 +147,9 @@ public void testParseLeftTime() throws NoSuchMethodException, InvocationTargetEx timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); //left time Math.min(3000-100,2000) - Assert.assertEquals(2000, timeout.getLeftTimeout()); + Assertions.assertEquals(2000, timeout.getLeftTimeout()); //init time Math.min(10000,2000) - Assert.assertEquals(2000, timeout.getOriginTimeout()); + Assertions.assertEquals(2000, timeout.getOriginTimeout()); // If the time in the context is null and the client has not configured a timeout, // the full-link timeout will be used as the standard. @@ -169,8 +167,8 @@ public void testParseLeftTime() throws NoSuchMethodException, InvocationTargetEx .serviceEnableLinkTimeout(true).build()); timeout = (LeftTimeout) method .invoke(defClusterInvocationHandler, rpcClientContext, "test"); - Assert.assertEquals(3000, timeout.getOriginTimeout()); - Assert.assertTrue(timeout.getLeftTimeout() <= 2999); + Assertions.assertEquals(3000, timeout.getOriginTimeout()); + Assertions.assertTrue(timeout.getLeftTimeout() <= 2999); } @Test @@ -183,7 +181,7 @@ public void testParseRpcServiceName() throws NoSuchMethodException, InvocationTa RpcClientContext rpcClientContext = new RpcClientContext(); String rpcServiceName = (String) method .invoke(defClusterInvocationHandler, BlankRpcServiceName.class, rpcClientContext); - Assert.assertEquals(rpcServiceName, "blank"); + Assertions.assertEquals(rpcServiceName, "blank"); } @Test @@ -195,21 +193,21 @@ public void testInvokeLocal() throws NoSuchMethodException, InvocationTargetExce method.setAccessible(true); String toString = (String) method.invoke(defClusterInvocationHandler, defClusterInvocationHandler.getClass().getMethod("toString"), null); - Assert.assertTrue(toString.contains("com.tencent.trpc.core.cluster.def.DefClusterInvocationHandler")); + Assertions.assertTrue(toString.contains("com.tencent.trpc.core.cluster.def.DefClusterInvocationHandler")); Integer hashCode = (Integer) method.invoke(defClusterInvocationHandler, defClusterInvocationHandler.getClass().getMethod("hashCode"), null); - Assert.assertNotNull(hashCode); + Assertions.assertNotNull(hashCode); boolean equal = (Boolean) method.invoke(defClusterInvocationHandler, defClusterInvocationHandler.getClass().getMethod("equals", Object.class), new String[]{"a"}); - Assert.assertFalse(equal); + Assertions.assertFalse(equal); try { method.invoke(defClusterInvocationHandler, AbstractClusterInvocationHandler.class.getDeclaredMethod( "isLocalMethod", Method.class), null); } catch (InvocationTargetException ex) { Throwable targetException = ex.getTargetException(); - Assert.assertTrue(targetException instanceof TRpcException); + Assertions.assertTrue(targetException instanceof TRpcException); TRpcException e = (TRpcException) targetException; - Assert.assertTrue(e.getMessage().contains("not allow invoke local method:isLocalMethod")); + Assertions.assertTrue(e.getMessage().contains("not allow invoke local method:isLocalMethod")); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerMockWrapperTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerMockWrapperTest.java index 3cb95d1e7..bc9b52ea7 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerMockWrapperTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerMockWrapperTest.java @@ -25,9 +25,9 @@ import com.tencent.trpc.core.utils.FutureUtils; import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; -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; public class DefClusterInvokerMockWrapperTest { @@ -38,7 +38,7 @@ public class DefClusterInvokerMockWrapperTest { /** * Init test ConsumerConfig & BackendConfig & invokerNotMock & invokerMock */ - @Before + @BeforeEach public void setUp() { ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setMock(false); @@ -104,7 +104,7 @@ public CompletionStage invoke(Request request) { @Test public void testGetInterface() { - Assert.assertEquals(BlankRpcServiceName.class, invokerNotMock.getInterface()); + Assertions.assertEquals(BlankRpcServiceName.class, invokerNotMock.getInterface()); } @Test @@ -118,7 +118,7 @@ public void testInvoke() throws NoSuchMethodException { Request request = new DefRequest(); request.setInvocation(invocation); CompletionStage invoke = invokerMock.invoke(request); - Assert.assertEquals("blank", invoke.toCompletableFuture().join().getValue()); + Assertions.assertEquals("blank", invoke.toCompletableFuture().join().getValue()); invokerNotMock.invoke(request); } @@ -134,23 +134,23 @@ public void testInvokeExceptionally() throws NoSuchMethodException { request.setInvocation(invocation); try { invokerMock.invoke(request).toCompletableFuture().join().getValue(); - Assert.fail(); + Assertions.fail(); } catch (CompletionException e) { - Assert.assertTrue(IllegalStateException.class.isAssignableFrom(e.getCause().getClass())); - Assert.assertEquals("boom", e.getCause().getMessage()); + Assertions.assertTrue(IllegalStateException.class.isAssignableFrom(e.getCause().getClass())); + Assertions.assertEquals("boom", e.getCause().getMessage()); } } @Test public void testGetConfig() { - Assert.assertFalse(invokerNotMock.getConfig().getMock()); - Assert.assertTrue(invokerMock.getConfig().getMock()); + Assertions.assertFalse(invokerNotMock.getConfig().getMock()); + Assertions.assertTrue(invokerMock.getConfig().getMock()); } @Test public void testGetBackendConfig() { - Assert.assertNotNull(invokerMock.getBackendConfig()); - Assert.assertNotNull(invokerNotMock.getBackendConfig()); + Assertions.assertNotNull(invokerMock.getBackendConfig()); + Assertions.assertNotNull(invokerNotMock.getBackendConfig()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java index 96afd9fac..ac2362fa1 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -40,18 +40,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -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; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({WorkerPoolManager.class}) -@PowerMockIgnore({"javax.management.*", "javax.security.*", "javax.ws.*"}) +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.Mockito; + +@ExtendWith(MockitoExtension.class) public class DefClusterInvokerTest { private DefClusterInvoker defClusterInvoker; @@ -60,7 +56,7 @@ public class DefClusterInvokerTest { /** * Create ConsumerConfig & create DefClusterInvoker & create ConsumerInvokerProxy */ - @Before + @BeforeEach public void setUp() { ConsumerConfig consumerConfig = getConsumerConfig(); this.defClusterInvoker = new DefClusterInvoker<>(consumerConfig); @@ -125,7 +121,7 @@ public ProtocolConfig getProtocolConfig() { } private ConsumerConfig getConsumerConfig() { - BackendConfig backendConfig = PowerMockito.mock(BackendConfig.class); + BackendConfig backendConfig = Mockito.mock(BackendConfig.class); backendConfig.setServiceInterface(GenericClient.class); backendConfig.setProxyType(ByteBuddyProxyFactory.NAME); backendConfig.setNamingUrl("ip://127.0.0.1:12345"); @@ -135,17 +131,17 @@ private ConsumerConfig getConsumerConfig() { NamingOptions options = new NamingOptions(); options.setSelectorId("ip"); options.setServiceNaming("127.0.0.1:12345"); - PowerMockito.when(backendConfig.getNamingOptions()).thenReturn(options); + Mockito.when(backendConfig.getNamingOptions()).thenReturn(options); // mock BackendConfig.getProxyType - PowerMockito.when(backendConfig.getProxyType()).thenReturn(ByteBuddyProxyFactory.NAME); + Mockito.when(backendConfig.getProxyType()).thenReturn(ByteBuddyProxyFactory.NAME); // mock workerPoolObj - WorkerPool workerPool = PowerMockito.mock(ThreadWorkerPool.class); + WorkerPool workerPool = Mockito.mock(ThreadWorkerPool.class); AtomicLong atomicLong = new AtomicLong(); - PowerMockito.when(workerPool.getUncaughtExceptionHandler()) + Mockito.when(workerPool.getUncaughtExceptionHandler()) .thenReturn(new TrpcThreadExceptionHandler(atomicLong, atomicLong, atomicLong)); - PowerMockito.when(backendConfig.getWorkerPoolObj()).thenReturn(workerPool); + Mockito.when(backendConfig.getWorkerPoolObj()).thenReturn(workerPool); ExecutorService executor = Executors.newSingleThreadExecutor(); - PowerMockito.when(workerPool.toExecutor()).thenReturn(executor); + Mockito.when(workerPool.toExecutor()).thenReturn(executor); backendConfig.setWorkerPool(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME); ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setBackendConfig(backendConfig); @@ -155,25 +151,25 @@ private ConsumerConfig getConsumerConfig() { @Test public void testTestToString() { - Assert.assertTrue(defClusterInvoker.toString().contains("NamingClusterInvoker")); + Assertions.assertTrue(defClusterInvoker.toString().contains("NamingClusterInvoker")); } @Test public void testGetConfig() { ConsumerConfig config = defClusterInvoker.getConfig(); - Assert.assertEquals(ByteBuddyProxyFactory.NAME, config.getBackendConfig().getProxyType()); + Assertions.assertEquals(ByteBuddyProxyFactory.NAME, config.getBackendConfig().getProxyType()); } @Test public void testGetInterface() { Class anInterface = defClusterInvoker.getInterface(); - Assert.assertNotNull(anInterface); + Assertions.assertNotNull(anInterface); } @Test public void testGetBackendConfig() { BackendConfig backendConfig = defClusterInvoker.getBackendConfig(); - Assert.assertEquals(ByteBuddyProxyFactory.NAME, backendConfig.getProxyType()); + Assertions.assertEquals(ByteBuddyProxyFactory.NAME, backendConfig.getProxyType()); } @Test @@ -185,7 +181,7 @@ public void testProxyInvoke() { consumerInvokerProxy.invoke(defRequest, new ServiceInstance()); invocation.setFunc("n"); consumerInvokerProxy.invoke(defRequest, new ServiceInstance()); - Assert.assertNotNull(consumerInvokerProxy.getInvoker()); + Assertions.assertNotNull(consumerInvokerProxy.getInvoker()); } @Test @@ -201,7 +197,7 @@ public void testDoInvoke() { + consumerConfig.getServiceInterface().getName() + ", naming=" + consumerConfig.getBackendConfig().getNamingOptions().getServiceNaming() + "), Client router error [found no available instance]"; - Assert.assertEquals(expect, exception.getMessage()); + Assertions.assertEquals(expect, exception.getMessage()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefRpcClusterClientTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefRpcClusterClientTest.java index dcbe08946..3fda20104 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefRpcClusterClientTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefRpcClusterClientTest.java @@ -14,9 +14,9 @@ import com.tencent.trpc.core.common.config.BackendConfig; import com.tencent.trpc.core.common.config.ConsumerConfig; import com.tencent.trpc.core.rpc.GenericClient; -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; public class DefRpcClusterClientTest { @@ -24,7 +24,7 @@ public class DefRpcClusterClientTest { private ConsumerConfig consumerConfig; - @Before + @BeforeEach public void setUp() { BackendConfig backendConfig = new BackendConfig(); backendConfig.setServiceInterface(GenericClient.class); @@ -39,20 +39,20 @@ public void setUp() { @Test public void testGetProxy() { GenericClient proxy = defRpcClusterClient.getProxy(consumerConfig); - Assert.assertNotNull(proxy); + Assertions.assertNotNull(proxy); } @Test public void testGetConfig() { BackendConfig config = defRpcClusterClient.getConfig(); - Assert.assertEquals("bytebuddy", config.getProxyType()); + Assertions.assertEquals("bytebuddy", config.getProxyType()); } @Test public void testStop() { - Assert.assertTrue(defRpcClusterClient.isAvailable()); - Assert.assertFalse(defRpcClusterClient.isClosed()); + Assertions.assertTrue(defRpcClusterClient.isAvailable()); + Assertions.assertFalse(defRpcClusterClient.isClosed()); defRpcClusterClient.stop(); - Assert.assertTrue(defRpcClusterClient.isClosed()); + Assertions.assertTrue(defRpcClusterClient.isClosed()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/ConfigManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/ConfigManagerTest.java index 3244a60c9..1c4e472f8 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/ConfigManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/ConfigManagerTest.java @@ -22,10 +22,10 @@ import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool; import java.util.HashMap; import org.assertj.core.util.Lists; -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; public class ConfigManagerTest { @@ -35,7 +35,7 @@ public class ConfigManagerTest { /** * ConfigManager start */ - @Before + @BeforeEach public void setUp() { ConfigManager.stopTest(); GlobalConfig globalConfig = new GlobalConfig(); @@ -66,7 +66,7 @@ public void starting() { ConfigManager.startTest(); } - @After + @AfterEach public void teardown() { ConfigManager.stopTest(); } @@ -80,7 +80,7 @@ public void testStart() { @Test public void testGetInstance() { ConfigManager instance = ConfigManager.getInstance(); - Assert.assertNotNull(instance); + Assertions.assertNotNull(instance); } @Test @@ -100,17 +100,17 @@ public void testRegisterPlugin() { @Test public void testGetGlobalConfig() { GlobalConfig globalConfig = ConfigManager.getInstance().getGlobalConfig(); - Assert.assertNotNull(globalConfig); - Assert.assertEquals("cn", globalConfig.getContainerName()); - Assert.assertEquals("en", globalConfig.getEnvName()); - Assert.assertEquals("prod", globalConfig.getNamespace()); - Assert.assertEquals("fsn", globalConfig.getFullSetName()); - Assert.assertTrue(globalConfig.isEnableSet()); + Assertions.assertNotNull(globalConfig); + Assertions.assertEquals("cn", globalConfig.getContainerName()); + Assertions.assertEquals("en", globalConfig.getEnvName()); + Assertions.assertEquals("prod", globalConfig.getNamespace()); + Assertions.assertEquals("fsn", globalConfig.getFullSetName()); + Assertions.assertTrue(globalConfig.isEnableSet()); } @Test public void testGetServerConfig() { - Assert.assertNotNull(ConfigManager.getInstance().getServerConfig()); + Assertions.assertNotNull(ConfigManager.getInstance().getServerConfig()); } @Test @@ -118,12 +118,12 @@ public void testSetServerConfig() { ServerConfig serverConfig = new ServerConfig(); serverConfig.setServer("aaa"); ConfigManager.getInstance().setServerConfig(serverConfig); - Assert.assertEquals("aaa", ConfigManager.getInstance().getServerConfig().getServer()); + Assertions.assertEquals("aaa", ConfigManager.getInstance().getServerConfig().getServer()); } @Test public void testGetClientConfig() { - Assert.assertNotNull(ConfigManager.getInstance().getClientConfig()); + Assertions.assertNotNull(ConfigManager.getInstance().getClientConfig()); } @Test @@ -131,23 +131,23 @@ public void testSetClientConfig() { ClientConfig clientConfig = new ClientConfig(); clientConfig.setCharset("aaa"); ConfigManager.getInstance().setClientConfig(clientConfig); - Assert.assertEquals("aaa", ConfigManager.getInstance().getClientConfig().getCharset()); + Assertions.assertEquals("aaa", ConfigManager.getInstance().getClientConfig().getCharset()); } @Test public void testGetPluginConfigMap() { - Assert.assertNotNull(ConfigManager.getInstance().getPluginConfigMap()); + Assertions.assertNotNull(ConfigManager.getInstance().getPluginConfigMap()); } @Test public void testSetPluginConfigMap() { ConfigManager.getInstance().setPluginConfigMap(new HashMap<>()); - Assert.assertNotNull(ConfigManager.getInstance().getPluginConfigMap()); + Assertions.assertNotNull(ConfigManager.getInstance().getPluginConfigMap()); } @Test public void testGetAppInitializer() { - Assert.assertNull(ConfigManager.getInstance().getAppInitializer()); + Assertions.assertNull(ConfigManager.getInstance().getAppInitializer()); } @Test @@ -177,4 +177,4 @@ public void testGracefulRestart() throws InterruptedException { Thread.sleep(WAIT_TIME); ConfigManager.getInstance().stop(); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/LifeCycleTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/LifeCycleTest.java index f72223f94..00f0788a8 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/LifeCycleTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/LifeCycleTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,8 +11,8 @@ package com.tencent.trpc.core.common; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.times; import com.tencent.trpc.core.common.Lifecycle.LifecycleListener; @@ -20,16 +20,15 @@ import com.tencent.trpc.core.exception.LifecycleException; import com.tencent.trpc.core.selector.ReflectionUtils; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; public class LifeCycleTest { @Test public void test() throws Exception { LifeCycleObj obj = new LifeCycleObj(); - LifecycleListener listenerMock = PowerMockito.mock(LifecycleListener.class); + LifecycleListener listenerMock = Mockito.mock(LifecycleListener.class); obj.addListener(listenerMock); assertSame(obj.getState(), LifecycleState.NEW); // init exception @@ -104,4 +103,4 @@ protected void initInternal() throws Exception { } } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/NamedThreadFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/NamedThreadFactoryTest.java index fe825859f..1a1395228 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/NamedThreadFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/NamedThreadFactoryTest.java @@ -11,15 +11,15 @@ package com.tencent.trpc.core.common; -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; public class NamedThreadFactoryTest { private NamedThreadFactory namedThreadFactory; - @Before + @BeforeEach public void setUp() { namedThreadFactory = new NamedThreadFactory(); } @@ -32,6 +32,6 @@ public void testNewThread() { @Test public void testGetThreadGroup() { - Assert.assertNotNull(namedThreadFactory.getThreadGroup()); + Assertions.assertNotNull(namedThreadFactory.getThreadGroup()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcPluginTypeAliasTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcPluginTypeAliasTest.java index 604c35dae..0c5802ad9 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcPluginTypeAliasTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcPluginTypeAliasTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.common; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.configcenter.spi.ConfigurationLoader; import com.tencent.trpc.core.filter.spi.Filter; @@ -26,7 +26,7 @@ import com.tencent.trpc.core.selector.spi.Selector; import com.tencent.trpc.core.trace.spi.TracerFactory; import com.tencent.trpc.core.worker.spi.WorkerPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TRpcPluginTypeAliasTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcSystemPropertiesTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcSystemPropertiesTest.java index ba3813b07..13e88cba0 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcSystemPropertiesTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/TRpcSystemPropertiesTest.java @@ -11,13 +11,13 @@ package com.tencent.trpc.core.common; -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; public class TRpcSystemPropertiesTest { - @Before + @BeforeEach public void setUp() { TRpcSystemProperties.setProperties("key", "value"); } @@ -25,34 +25,34 @@ public void setUp() { @Test public void testGetProperties() { String value = TRpcSystemProperties.getProperties("key"); - Assert.assertEquals("value", value); + Assertions.assertEquals("value", value); String value1 = TRpcSystemProperties.getProperties("key1"); - Assert.assertNull(value1); + Assertions.assertNull(value1); } @Test public void testGetPropertiesWithDef() { String value = TRpcSystemProperties.getProperties("key", "value1"); - Assert.assertEquals("value", value); + Assertions.assertEquals("value", value); String value1 = TRpcSystemProperties.getProperties("key1", "value1"); - Assert.assertEquals("value1", value1); + Assertions.assertEquals("value1", value1); } @Test public void testSetProperties() { TRpcSystemProperties.setProperties("key", "value2"); String value = TRpcSystemProperties.getProperties("key"); - Assert.assertEquals("value2", value); + Assertions.assertEquals("value2", value); } @Test public void testIsIgnoreSamePluginName() { - Assert.assertFalse(TRpcSystemProperties.isIgnoreSamePluginName()); + Assertions.assertFalse(TRpcSystemProperties.isIgnoreSamePluginName()); } @Test public void testSetIgnoreSamePluginName() { TRpcSystemProperties.setIgnoreSamePluginName(true); - Assert.assertTrue(TRpcSystemProperties.isIgnoreSamePluginName()); + Assertions.assertTrue(TRpcSystemProperties.isIgnoreSamePluginName()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/VersionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/VersionTest.java index f626acc4e..58e58665d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/VersionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/VersionTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class VersionTest { @@ -20,10 +20,10 @@ public class VersionTest { public void testVersion() { // FORMAL VERSION if (Version.IS_FORMAL_VERSION) { - Assert.assertEquals(Version.VERSION, Version.version()); + Assertions.assertEquals(Version.VERSION, Version.version()); return; } // SNAPSHOT VERSION - Assert.assertEquals(Version.SNAPSHOT_VERSION, Version.version()); + Assertions.assertEquals(Version.SNAPSHOT_VERSION, Version.version()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ApplicationConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ApplicationConfigTest.java index a75080679..54fd90fdb 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ApplicationConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ApplicationConfigTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.ConfigManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ApplicationConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BackendConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BackendConfigTest.java index 467a85e5f..31a228db4 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BackendConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BackendConfigTest.java @@ -11,12 +11,12 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -30,19 +30,19 @@ import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool; import java.util.HashMap; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BackendConfigTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BaseProtocolConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BaseProtocolConfigTest.java index dc64b5d5b..cf88c7c94 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BaseProtocolConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/BaseProtocolConfigTest.java @@ -12,9 +12,9 @@ package com.tencent.trpc.core.common.config; import java.util.HashMap; -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; public class BaseProtocolConfigTest { @@ -23,7 +23,7 @@ public class BaseProtocolConfigTest { /** * Init BaseProtocolConfig */ - @Before + @BeforeEach public void setUp() { this.bpc = new BaseProtocolConfig(); bpc.setProtocol("trpc"); @@ -55,283 +55,283 @@ public void setUp() { @Test public void testGetProtocol() { - Assert.assertEquals("trpc", bpc.getProtocol()); + Assertions.assertEquals("trpc", bpc.getProtocol()); } @Test public void testSetProtocol() { bpc.setProtocol("http"); - Assert.assertEquals("http", bpc.getProtocol()); + Assertions.assertEquals("http", bpc.getProtocol()); } @Test public void testGetSerialization() { - Assert.assertEquals("json", bpc.getSerialization()); + Assertions.assertEquals("json", bpc.getSerialization()); } @Test public void testSetSerialization() { bpc.setSerialization("pb"); - Assert.assertEquals("pb", bpc.getSerialization()); + Assertions.assertEquals("pb", bpc.getSerialization()); } @Test public void testGetCompressor() { - Assert.assertEquals("gzip", bpc.getCompressor()); + Assertions.assertEquals("gzip", bpc.getCompressor()); } @Test public void testSetCompressor() { bpc.setCompressor("snappy"); - Assert.assertEquals("snappy", bpc.getCompressor()); + Assertions.assertEquals("snappy", bpc.getCompressor()); } @Test public void testGetCompressMinBytes() { - Assert.assertEquals(10, bpc.getCompressMinBytes()); + Assertions.assertEquals(10, bpc.getCompressMinBytes()); } @Test public void testSetCompressMinBytes() { bpc.setCompressMinBytes(20); - Assert.assertEquals(20, bpc.getCompressMinBytes()); + Assertions.assertEquals(20, bpc.getCompressMinBytes()); } @Test public void testGetKeepAlive() { - Assert.assertTrue(bpc.getKeepAlive()); + Assertions.assertTrue(bpc.getKeepAlive()); } @Test public void testSetKeepAlive() { bpc.setKeepAlive(false); - Assert.assertFalse(bpc.getKeepAlive()); + Assertions.assertFalse(bpc.getKeepAlive()); } @Test public void testGetCharset() { - Assert.assertEquals("utf8", bpc.getCharset()); + Assertions.assertEquals("utf8", bpc.getCharset()); } @Test public void testSetCharset() { bpc.setCharset("gbk"); - Assert.assertEquals("gbk", bpc.getCharset()); + Assertions.assertEquals("gbk", bpc.getCharset()); } @Test public void testGetTransporter() { - Assert.assertEquals("netty", bpc.getTransporter()); + Assertions.assertEquals("netty", bpc.getTransporter()); } @Test public void testSetTransporter() { bpc.setTransporter("jetty"); - Assert.assertEquals("jetty", bpc.getTransporter()); + Assertions.assertEquals("jetty", bpc.getTransporter()); } @Test public void testGetMaxConns() { - Assert.assertEquals(10, bpc.getMaxConns()); + Assertions.assertEquals(10, bpc.getMaxConns()); } @Test public void testSetMaxConns() { bpc.setMaxConns(20); - Assert.assertEquals(20, bpc.getMaxConns()); + Assertions.assertEquals(20, bpc.getMaxConns()); } @Test public void testGetBacklog() { - Assert.assertEquals(10, bpc.getBacklog()); + Assertions.assertEquals(10, bpc.getBacklog()); } @Test public void testSetBacklog() { bpc.setBacklog(20); - Assert.assertEquals(20, bpc.getBacklog()); + Assertions.assertEquals(20, bpc.getBacklog()); } @Test public void testGetNetwork() { - Assert.assertEquals("tcp", bpc.getNetwork()); + Assertions.assertEquals("tcp", bpc.getNetwork()); } @Test public void testSetNetwork() { bpc.setNetwork("udp"); - Assert.assertEquals("udp", bpc.getNetwork()); + Assertions.assertEquals("udp", bpc.getNetwork()); } @Test public void testGetReceiveBuffer() { - Assert.assertEquals(10, bpc.getReceiveBuffer()); + Assertions.assertEquals(10, bpc.getReceiveBuffer()); } @Test public void testSetReceiveBuffer() { bpc.setReceiveBuffer(20); - Assert.assertEquals(20, bpc.getReceiveBuffer()); + Assertions.assertEquals(20, bpc.getReceiveBuffer()); } @Test public void testGetSendBuffer() { - Assert.assertEquals(10, bpc.getSendBuffer()); + Assertions.assertEquals(10, bpc.getSendBuffer()); } @Test public void testSetSendBuffer() { bpc.setSendBuffer(20); - Assert.assertEquals(20, bpc.getSendBuffer()); + Assertions.assertEquals(20, bpc.getSendBuffer()); } @Test public void testGetPayload() { - Assert.assertEquals(10, bpc.getPayload()); + Assertions.assertEquals(10, bpc.getPayload()); } @Test public void testSetPayload() { bpc.setPayload(20); - Assert.assertEquals(20, bpc.getPayload()); + Assertions.assertEquals(20, bpc.getPayload()); } @Test public void testGetIdleTimeout() { - Assert.assertEquals(10, bpc.getIdleTimeout().intValue()); + Assertions.assertEquals(10, bpc.getIdleTimeout().intValue()); } @Test public void testSetIdleTimeout() { bpc.setIdleTimeout(20); - Assert.assertEquals(20, bpc.getIdleTimeout().intValue()); + Assertions.assertEquals(20, bpc.getIdleTimeout().intValue()); } @Test public void testGetLazyinit() { - Assert.assertTrue(bpc.getLazyinit()); + Assertions.assertTrue(bpc.getLazyinit()); } @Test public void testSetLazyinit() { bpc.setLazyinit(false); - Assert.assertFalse(bpc.getLazyinit()); + Assertions.assertFalse(bpc.getLazyinit()); } @Test public void testGetConnsPerAddr() { - Assert.assertEquals(10, bpc.getConnsPerAddr()); + Assertions.assertEquals(10, bpc.getConnsPerAddr()); } @Test public void testSetConnsPerAddr() { bpc.setConnsPerAddr(20); - Assert.assertEquals(20, bpc.getConnsPerAddr()); + Assertions.assertEquals(20, bpc.getConnsPerAddr()); } @Test public void testGetConnTimeout() { - Assert.assertEquals(10, bpc.getConnTimeout()); + Assertions.assertEquals(10, bpc.getConnTimeout()); } @Test public void testSetConnTimeout() { bpc.setConnTimeout(20); - Assert.assertEquals(20, bpc.getConnTimeout()); + Assertions.assertEquals(20, bpc.getConnTimeout()); } @Test public void testGetIoMode() { - Assert.assertEquals("epoll", bpc.getIoMode()); + Assertions.assertEquals("epoll", bpc.getIoMode()); } @Test public void testSetIoMode() { bpc.setIoMode("poll"); - Assert.assertEquals("poll", bpc.getIoMode()); + Assertions.assertEquals("poll", bpc.getIoMode()); } @Test public void testGetIoThreadGroupShare() { - Assert.assertTrue(bpc.getIoThreadGroupShare()); + Assertions.assertTrue(bpc.getIoThreadGroupShare()); } @Test public void testSetIoThreadGroupShare() { bpc.setIoThreadGroupShare(false); - Assert.assertFalse(bpc.getIoThreadGroupShare()); + Assertions.assertFalse(bpc.getIoThreadGroupShare()); } @Test public void testGetIoThreads() { - Assert.assertEquals(10, bpc.getIoThreads()); + Assertions.assertEquals(10, bpc.getIoThreads()); } @Test public void testSetIoThreads() { bpc.setIoThreads(20); - Assert.assertEquals(20, bpc.getIoThreads()); + Assertions.assertEquals(20, bpc.getIoThreads()); } @Test public void testSetBossThreads() { bpc.setBossThreads(2); - Assert.assertEquals(2, bpc.getBossThreads()); + Assertions.assertEquals(2, bpc.getBossThreads()); } @Test public void testGetFlushConsolidation() { - Assert.assertTrue(bpc.getFlushConsolidation()); + Assertions.assertTrue(bpc.getFlushConsolidation()); } @Test public void testSetFlushConsolidation() { bpc.setFlushConsolidation(false); - Assert.assertFalse(bpc.getFlushConsolidation()); + Assertions.assertFalse(bpc.getFlushConsolidation()); } @Test public void testGetBatchDecoder() { - Assert.assertTrue(bpc.getBatchDecoder()); + Assertions.assertTrue(bpc.getBatchDecoder()); } @Test public void testSetBatchDecoder() { bpc.setBatchDecoder(false); - Assert.assertFalse(bpc.getBatchDecoder()); + Assertions.assertFalse(bpc.getBatchDecoder()); } @Test public void testGetExplicitFlushAfterFlushes() { - Assert.assertEquals(10, bpc.getExplicitFlushAfterFlushes()); + Assertions.assertEquals(10, bpc.getExplicitFlushAfterFlushes()); } @Test public void testSetExplicitFlushAfterFlushes() { bpc.setExplicitFlushAfterFlushes(20); - Assert.assertEquals(20, bpc.getExplicitFlushAfterFlushes()); + Assertions.assertEquals(20, bpc.getExplicitFlushAfterFlushes()); } @Test public void testGetReusePort() { - Assert.assertTrue(bpc.getReusePort()); + Assertions.assertTrue(bpc.getReusePort()); } @Test public void testSetReusePort() { bpc.setReusePort(false); - Assert.assertFalse(bpc.getReusePort()); + Assertions.assertFalse(bpc.getReusePort()); } @Test public void testGetExtMap() { - Assert.assertEquals(0, bpc.getExtMap().size()); + Assertions.assertEquals(0, bpc.getExtMap().size()); } @Test public void testSetExtMap() { bpc.setExtMap(null); - Assert.assertNull(bpc.getExtMap()); + Assertions.assertNull(bpc.getExtMap()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ClientConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ClientConfigTest.java index d9ba12865..8e51941cb 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ClientConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ClientConfigTest.java @@ -11,11 +11,11 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.Constants; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ClientConfigTest { @@ -227,4 +227,4 @@ public void testClientConfigNotEmptryBackendConfig() { assertEquals(false, backendConfig.isIoThreadGroupShare()); assertEquals(1000, backendConfig.getIoThreads()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigCenterConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigCenterConfigTest.java index 9e5ebf41f..e9085c2c5 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigCenterConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigCenterConfigTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.common.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigCenterConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigTest.java index 3077016c4..2abe3db90 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConfigTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.common.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConsumerConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConsumerConfigTest.java index 217870130..7ca299e90 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConsumerConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ConsumerConfigTest.java @@ -11,29 +11,29 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.common.config.BackendConfigTest.RemoteLoggerTest; import com.tencent.trpc.core.extension.ExtensionLoader; import com.tencent.trpc.core.filter.spi.Filter; import com.tencent.trpc.core.rpc.GenericClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ConsumerConfigTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -69,4 +69,4 @@ public void test() { assertNotNull(config.getProxyWithSourceSet("a")); assertNotNull(config.getProxyWithDestinationSet("b")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/GlobalConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/GlobalConfigTest.java index 2dc53a763..c7f3910a5 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/GlobalConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/GlobalConfigTest.java @@ -13,15 +13,15 @@ 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; public class GlobalConfigTest { private GlobalConfig globalConfig; - @Before + @BeforeEach public void testSetUp() { this.globalConfig = new GlobalConfig(); globalConfig.setEnableSet(true); @@ -34,7 +34,7 @@ public void testSetUp() { @Test public void testSetDefault() { globalConfig.setDefault(); - Assert.assertTrue(globalConfig.isSetDefault()); + Assertions.assertTrue(globalConfig.isSetDefault()); } @Test @@ -44,68 +44,68 @@ public void testCheckFiledModifyPrivilege() { @Test public void getNamespace() { - Assert.assertEquals(globalConfig.getNamespace(), "prod"); + Assertions.assertEquals(globalConfig.getNamespace(), "prod"); } @Test public void setNamespace() { globalConfig.setNamespace("dev"); - Assert.assertEquals(globalConfig.getNamespace(), "dev"); + Assertions.assertEquals(globalConfig.getNamespace(), "dev"); } @Test public void isSetDefault() { - Assert.assertFalse(globalConfig.isSetDefault()); + Assertions.assertFalse(globalConfig.isSetDefault()); } @Test public void getEnvName() { - Assert.assertEquals(globalConfig.getEnvName(), "env"); + Assertions.assertEquals(globalConfig.getEnvName(), "env"); } @Test public void setEnvName() { globalConfig.setEnvName("env-dev"); - Assert.assertEquals(globalConfig.getEnvName(), "env-dev"); + Assertions.assertEquals(globalConfig.getEnvName(), "env-dev"); } @Test public void isEnableSet() { - Assert.assertTrue(globalConfig.isEnableSet()); + Assertions.assertTrue(globalConfig.isEnableSet()); } @Test public void setEnableSet() { globalConfig.setEnableSet(false); - Assert.assertFalse(globalConfig.isEnableSet()); + Assertions.assertFalse(globalConfig.isEnableSet()); } @Test public void getSetDivision() { - Assert.assertEquals(globalConfig.getFullSetName(), "div"); + Assertions.assertEquals(globalConfig.getFullSetName(), "div"); } @Test public void setSetDivision() { globalConfig.setFullSetName("set-div"); - Assert.assertEquals(globalConfig.getFullSetName(), "set-div"); + Assertions.assertEquals(globalConfig.getFullSetName(), "set-div"); } @Test public void getContainerName() { - Assert.assertEquals(globalConfig.getContainerName(), "container"); + Assertions.assertEquals(globalConfig.getContainerName(), "container"); } @Test public void setContainerName() { globalConfig.setContainerName("c"); - Assert.assertEquals(globalConfig.getContainerName(), "c"); + Assertions.assertEquals(globalConfig.getContainerName(), "c"); } @Test public void testGetExt() { - Assert.assertTrue(globalConfig.getExt().isEmpty()); + Assertions.assertTrue(globalConfig.getExt().isEmpty()); } @Test @@ -113,6 +113,6 @@ public void testSetExt() { Map extMap = new HashMap<>(); extMap.put("ext", "ext"); globalConfig.setExt(extMap); - Assert.assertEquals(globalConfig.getExt().get("ext"), "ext"); + Assertions.assertEquals(globalConfig.getExt().get("ext"), "ext"); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/NamingOptionsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/NamingOptionsTest.java index a02089644..df3067ae3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/NamingOptionsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/NamingOptionsTest.java @@ -11,11 +11,11 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.HashMap; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NamingOptionsTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/PluginConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/PluginConfigTest.java index 7807071d3..771af7a55 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/PluginConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/PluginConfigTest.java @@ -11,13 +11,13 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import com.tencent.trpc.core.worker.spi.WorkerPool; import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PluginConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProtocolConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProtocolConfigTest.java index 9be8ebb66..b01ee0262 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProtocolConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProtocolConfigTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import com.tencent.trpc.core.common.Constants; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ProtocolConfigTest { @@ -125,4 +125,4 @@ public void testConfig() { assertEquals(10, config.getCompressMinBytes()); assertTrue(config.isSetDefault()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java index 3b5ae8fc7..70a374598 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java @@ -41,7 +41,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; -import org.mockito.MockedStatic; @ExtendWith(MockitoExtension.class) public class ProviderConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServerConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServerConfigTest.java index f449217ae..dc51f35c4 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServerConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServerConfigTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.common.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ServerConfigTest { @@ -31,4 +31,4 @@ public void testNic() { serverConfig.getServiceMap().put("server1", new ServiceConfig()); serverConfig.setDefault(); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServiceConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServiceConfigTest.java index 47e5b9fd3..030c4be3e 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServiceConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ServiceConfigTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.common.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletionStage; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ServiceConfigTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/builder/PluginConfigBuilderTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/builder/PluginConfigBuilderTest.java index e7a2d13cf..d547595b3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/builder/PluginConfigBuilderTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/builder/PluginConfigBuilderTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.common.config.builder; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.config.PluginConfig; import com.tencent.trpc.core.rpc.GenericClient; @@ -19,8 +19,8 @@ import com.tencent.trpc.core.worker.support.thread.ForkJoinWorkerPool; import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool; import java.util.HashMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PluginConfigBuilderTest { @@ -41,8 +41,8 @@ public void test() { builder.setPluginClass(ForkJoinWorkerPool.class); assertEquals(ForkJoinWorkerPool.class, builder.getPluginClass()); builder.addPropertie("a", "a"); - Assert.assertEquals("a", builder.getProperties().get("a")); + Assertions.assertEquals("a", builder.getProperties().get("a")); builder.setProperties(new HashMap<>()); - Assert.assertEquals(0, builder.getProperties().size()); + Assertions.assertEquals(0, builder.getProperties().size()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/timer/HashWheelTimerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/timer/HashWheelTimerTest.java index c30dc5a53..20b64dc9d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/timer/HashWheelTimerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/timer/HashWheelTimerTest.java @@ -11,27 +11,27 @@ package com.tencent.trpc.core.common.timer; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.NamedThreadFactory; import java.util.concurrent.TimeUnit; -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; public class HashWheelTimerTest { HashedWheelTimer timer; - @Before + @BeforeEach public void before() { NamedThreadFactory threadFactory = new NamedThreadFactory("Test-Scheduler", true); timer = new HashedWheelTimer(threadFactory, 10, TimeUnit.MILLISECONDS); timer.start(); } - @After + @AfterEach public void after() { if (timer != null) { timer.stop(); @@ -41,16 +41,16 @@ public void after() { @Test public void testInit() { HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(); - Assert.assertNotNull(hashedWheelTimer); + Assertions.assertNotNull(hashedWheelTimer); hashedWheelTimer.stop(); hashedWheelTimer = new HashedWheelTimer(1L, TimeUnit.MINUTES); - Assert.assertNotNull(hashedWheelTimer); + Assertions.assertNotNull(hashedWheelTimer); hashedWheelTimer.stop(); hashedWheelTimer = new HashedWheelTimer(1L, TimeUnit.MINUTES, 1); - Assert.assertNotNull(hashedWheelTimer); + Assertions.assertNotNull(hashedWheelTimer); hashedWheelTimer.stop(); hashedWheelTimer = new HashedWheelTimer(new NamedThreadFactory()); - Assert.assertNotNull(hashedWheelTimer); + Assertions.assertNotNull(hashedWheelTimer); hashedWheelTimer.stop(); } @@ -68,4 +68,4 @@ public void test() { newTimeout.cancel(); assertTrue(newTimeout.isCancelled()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/compressor/CompressorTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/compressor/CompressorTest.java index 942a00d51..2532ee6c8 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/compressor/CompressorTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/compressor/CompressorTest.java @@ -16,8 +16,8 @@ import com.tencent.trpc.core.extension.ExtensionClass; import com.tencent.trpc.core.extension.ExtensionLoader; import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CompressorTest { @@ -28,17 +28,17 @@ public void testCompress() { .getAllExtensionClass()) { Compressor c = CompressorSupport.ofName(each.getName()); Compressor c2 = CompressorSupport.ofType(c.type()); - Assert.assertEquals(c.type(), c2.type()); - Assert.assertEquals(c.name(), each.getName()); + Assertions.assertEquals(c.type(), c2.type()); + Assertions.assertEquals(c.name(), each.getName()); String s = "中英文压测数据ABC123"; try { byte[] data = c.compress(s.getBytes()); byte[] result = c.decompress(data); - Assert.assertEquals(new String(result), s); - Assert.assertNull(c.compress(null)); - Assert.assertNull(c.decompress(null)); + Assertions.assertEquals(new String(result), s); + Assertions.assertNull(c.compress(null)); + Assertions.assertNull(c.decompress(null)); } catch (IOException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } } @@ -50,9 +50,9 @@ public void testGzip() { try { byte[] data = c.compress(s.getBytes()); byte[] result = c.decompress(data); - Assert.assertEquals(new String(result), s); + Assertions.assertEquals(new String(result), s); } catch (IOException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationEventTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationEventTest.java index 0d4855ecd..78ff4c407 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationEventTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationEventTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.configcenter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigurationEventTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationManagerTest.java index c465c178c..9b1ba16f4 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/configcenter/ConfigurationManagerTest.java @@ -13,20 +13,16 @@ import com.tencent.trpc.core.configcenter.spi.ConfigurationLoader; import com.tencent.trpc.core.exception.TRpcExtensionException; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ConfigurationManagerTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test - public void testGetConfigurationLoader() { - expectedEx.expect(TRpcExtensionException.class); - expectedEx.expectMessage("Cannot get extension of type"); - Assert.assertNotNull(ConfigurationManager.getConfigurationLoader("rainbow")); + public void testGetConfigLoader() { + TRpcExtensionException exception = Assertions.assertThrows(TRpcExtensionException.class, () -> { + ConfigurationManager.getConfigurationLoader("rainbow"); + }); + Assertions.assertTrue(exception.getMessage().contains("Cannot get extension of type")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/ErrorCodeUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/ErrorCodeUtilsTest.java index 1aaa4ac12..806d4eaf8 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/ErrorCodeUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/ErrorCodeUtilsTest.java @@ -11,17 +11,17 @@ package com.tencent.trpc.core.exception; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ErrorCodeUtilsTest { @Test public void testNeedCircuitBreaker() { - Assert.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR)); - Assert.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_CONNECT_ERR)); - Assert.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_NETWORK_ERR)); - Assert.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_SERVER_OVERLOAD_ERR)); - Assert.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_SERVER_TIMEOUT_ERR)); + Assertions.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR)); + Assertions.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_CONNECT_ERR)); + Assertions.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_CLIENT_NETWORK_ERR)); + Assertions.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_SERVER_OVERLOAD_ERR)); + Assertions.assertTrue(ErrorCodeUtils.needCircuitBreaker(ErrorCode.TRPC_SERVER_TIMEOUT_ERR)); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/ExceptionHelperTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/ExceptionHelperTest.java index 8c24b3ba9..75543d83f 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/ExceptionHelperTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/ExceptionHelperTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -12,47 +12,48 @@ package com.tencent.trpc.core.exception; import java.util.concurrent.CompletionException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ExceptionHelperTest { @Test public void testIsTRpcException() { - Assert.assertTrue(ExceptionHelper.isTRpcException(new TRpcException())); - Assert.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newException(1, 1, "1"))); - Assert.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newException(1, 1, "1", new Throwable()))); - Assert.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newBizException(1, "1", new Throwable()))); - Assert.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newBizException(1, "%s", "s"))); - Assert.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newFrameException(1, "%s", "s"))); - Assert.assertFalse(ExceptionHelper.isTRpcException(new BinderException())); - Assert.assertFalse(ExceptionHelper.isTRpcException(new TRpcExtensionException())); - Assert.assertFalse(ExceptionHelper.isTRpcException(new ConfigCenterException())); - Assert.assertFalse(ExceptionHelper.isTRpcException(new LifecycleException())); - Assert.assertFalse(ExceptionHelper.isTRpcException(new IllegalAccessError())); + Assertions.assertTrue(ExceptionHelper.isTRpcException(new TRpcException())); + Assertions.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newException(1, 1, "1"))); + Assertions.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newException(1, 1, "1", new Throwable()))); + Assertions.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newBizException(1, "1", new Throwable()))); + Assertions.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newBizException(1, "%s", "s"))); + Assertions.assertTrue(ExceptionHelper.isTRpcException(TRpcException.newFrameException(1, "%s", "s"))); + Assertions.assertFalse(ExceptionHelper.isTRpcException(new BinderException())); + Assertions.assertFalse(ExceptionHelper.isTRpcException(new TRpcExtensionException())); + Assertions.assertFalse(ExceptionHelper.isTRpcException(new ConfigCenterException())); + Assertions.assertFalse(ExceptionHelper.isTRpcException(new LifecycleException())); + Assertions.assertFalse(ExceptionHelper.isTRpcException(new IllegalAccessError())); } @Test public void testUnwrapCompletionException() { - Assert.assertNotNull(ExceptionHelper.parseResponseException(null, new Throwable())); - Assert.assertNull(ExceptionHelper.unwrapCompletionException(null)); + Assertions.assertNotNull(ExceptionHelper.parseResponseException(null, new Throwable())); + Assertions.assertNull(ExceptionHelper.unwrapCompletionException(null)); TRpcException exception = new TRpcException(); - Assert.assertEquals(exception, ExceptionHelper.unwrapCompletionException(new CompletionException(exception))); - Assert.assertEquals(exception, ExceptionHelper.unwrapCompletionException(exception)); + Assertions.assertEquals(exception, + ExceptionHelper.unwrapCompletionException(new CompletionException(exception))); + Assertions.assertEquals(exception, ExceptionHelper.unwrapCompletionException(exception)); } @Test public void testIsBizException() { - Assert.assertTrue(ExceptionHelper.isBizException(TRpcException.newBizException(111, "hello"))); - Assert.assertFalse(ExceptionHelper.isBizException(new BinderException("binder"))); - Assert.assertFalse(ExceptionHelper.isBizException(new BinderException("binder", null))); - Assert.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException("cce"))); - Assert.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException("cce", null))); - Assert.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException(new Throwable()))); - Assert.assertFalse(ExceptionHelper.isBizException(new LifecycleException(new Throwable()))); - Assert.assertFalse(ExceptionHelper.isBizException(new TransportException(new Throwable()))); - Assert.assertFalse(ExceptionHelper.isBizException(new TRpcExtensionException(new Throwable()))); - Assert.assertFalse(ExceptionHelper.isBizException(TransportException.trans(new Throwable()))); - Assert.assertFalse(ExceptionHelper.isBizException(new IllegalAccessError())); + Assertions.assertTrue(ExceptionHelper.isBizException(TRpcException.newBizException(111, "hello"))); + Assertions.assertFalse(ExceptionHelper.isBizException(new BinderException("binder"))); + Assertions.assertFalse(ExceptionHelper.isBizException(new BinderException("binder", null))); + Assertions.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException("cce"))); + Assertions.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException("cce", null))); + Assertions.assertFalse(ExceptionHelper.isBizException(new ConfigCenterException(new Throwable()))); + Assertions.assertFalse(ExceptionHelper.isBizException(new LifecycleException(new Throwable()))); + Assertions.assertFalse(ExceptionHelper.isBizException(new TransportException(new Throwable()))); + Assertions.assertFalse(ExceptionHelper.isBizException(new TRpcExtensionException(new Throwable()))); + Assertions.assertFalse(ExceptionHelper.isBizException(TransportException.trans(new Throwable()))); + Assertions.assertFalse(ExceptionHelper.isBizException(new IllegalAccessError())); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterBlockHandlerExceptionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterBlockHandlerExceptionTest.java index f98e98083..fcbc68c72 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterBlockHandlerExceptionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterBlockHandlerExceptionTest.java @@ -12,40 +12,40 @@ package com.tencent.trpc.core.exception; import com.tencent.trpc.core.utils.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class LimiterBlockHandlerExceptionTest { @Test public void test() { LimiterBlockException exception = new LimiterBlockException("exception"); - Assert.assertTrue(exception.getMessage().equals("exception")); + Assertions.assertTrue(exception.getMessage().equals("exception")); } @Test public void test2() { LimiterBlockException exception = new LimiterBlockException(new NullPointerException("msg")); - Assert.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); } @Test public void test3() { LimiterBlockException exception = new LimiterBlockException("msg2", new NullPointerException("msg1")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); - Assert.assertTrue(exception.getMessage().equals("msg2")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("msg2")); } @Test public void test4() { LimiterBlockException exception = new LimiterBlockException(); - Assert.assertTrue(StringUtils.isEmpty(exception.getMessage())); + Assertions.assertTrue(StringUtils.isEmpty(exception.getMessage())); } @Test public void test5() { LimiterBlockException exception = new LimiterBlockException("msg3", new NullPointerException(), false, false); - Assert.assertTrue(exception.getMessage().equals("msg3")); + Assertions.assertTrue(exception.getMessage().equals("msg3")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterDatasourceExceptionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterDatasourceExceptionTest.java index 47ee7afae..fbc5096e7 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterDatasourceExceptionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterDatasourceExceptionTest.java @@ -12,41 +12,41 @@ package com.tencent.trpc.core.exception; import com.tencent.trpc.core.utils.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class LimiterDatasourceExceptionTest { @Test public void test() { LimiterDataSourceException exception = new LimiterDataSourceException("exception"); - Assert.assertTrue(exception.getMessage().equals("exception")); + Assertions.assertTrue(exception.getMessage().equals("exception")); } @Test public void test2() { LimiterDataSourceException exception = new LimiterDataSourceException(new NullPointerException("msg")); - Assert.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); } @Test public void test3() { LimiterDataSourceException exception = new LimiterDataSourceException("msg2", new NullPointerException("msg1")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); - Assert.assertTrue(exception.getMessage().equals("msg2")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("msg2")); } @Test public void test4() { LimiterDataSourceException exception = new LimiterDataSourceException(); - Assert.assertTrue(StringUtils.isEmpty(exception.getMessage())); + Assertions.assertTrue(StringUtils.isEmpty(exception.getMessage())); } @Test public void test5() { LimiterDataSourceException exception = new LimiterDataSourceException("msg3", new NullPointerException(), false, false); - Assert.assertTrue(exception.getMessage().equals("msg3")); + Assertions.assertTrue(exception.getMessage().equals("msg3")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterExceptionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterExceptionTest.java index e412aa42b..6fdabfa9d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterExceptionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterExceptionTest.java @@ -12,40 +12,40 @@ package com.tencent.trpc.core.exception; import com.tencent.trpc.core.utils.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class LimiterExceptionTest { @Test public void test() { LimiterException limiterException = new LimiterException("limiter exception"); - Assert.assertTrue(limiterException.getMessage().equals("limiter exception")); + Assertions.assertTrue(limiterException.getMessage().equals("limiter exception")); } @Test public void test2() { LimiterException limiterException = new LimiterException(new NullPointerException("msg")); - Assert.assertTrue(limiterException.getMessage().equals("java.lang.NullPointerException: msg")); - Assert.assertTrue(limiterException.getCause() instanceof NullPointerException); + Assertions.assertTrue(limiterException.getMessage().equals("java.lang.NullPointerException: msg")); + Assertions.assertTrue(limiterException.getCause() instanceof NullPointerException); } @Test public void test3() { LimiterException exception = new LimiterException("msg2", new NullPointerException("msg1")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); - Assert.assertTrue(exception.getMessage().equals("msg2")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("msg2")); } @Test public void test4() { LimiterException limiterException = new LimiterException(); - Assert.assertTrue(StringUtils.isEmpty(limiterException.getMessage())); + Assertions.assertTrue(StringUtils.isEmpty(limiterException.getMessage())); } @Test public void test5() { LimiterException limiterException = new LimiterException("msg3", new NullPointerException(), false, false); - Assert.assertTrue(limiterException.getMessage().equals("msg3")); + Assertions.assertTrue(limiterException.getMessage().equals("msg3")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterFallbackExceptionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterFallbackExceptionTest.java index 74b373ec1..5ec5d582b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterFallbackExceptionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/LimiterFallbackExceptionTest.java @@ -12,41 +12,41 @@ package com.tencent.trpc.core.exception; import com.tencent.trpc.core.utils.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class LimiterFallbackExceptionTest { @Test public void test() { LimiterFallbackException exception = new LimiterFallbackException("exception"); - Assert.assertTrue(exception.getMessage().equals("exception")); + Assertions.assertTrue(exception.getMessage().equals("exception")); } @Test public void test2() { LimiterFallbackException exception = new LimiterFallbackException(new NullPointerException("msg")); - Assert.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("java.lang.NullPointerException: msg")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); } @Test public void test3() { LimiterFallbackException exception = new LimiterFallbackException("msg2", new NullPointerException("msg1")); - Assert.assertTrue(exception.getCause() instanceof NullPointerException); - Assert.assertTrue(exception.getMessage().equals("msg2")); + Assertions.assertTrue(exception.getCause() instanceof NullPointerException); + Assertions.assertTrue(exception.getMessage().equals("msg2")); } @Test public void test4() { LimiterFallbackException exception = new LimiterFallbackException(); - Assert.assertTrue(StringUtils.isEmpty(exception.getMessage())); + Assertions.assertTrue(StringUtils.isEmpty(exception.getMessage())); } @Test public void test5() { LimiterFallbackException exception = new LimiterFallbackException("msg3", new NullPointerException(), false, false); - Assert.assertTrue(exception.getMessage().equals("msg3")); + Assertions.assertTrue(exception.getMessage().equals("msg3")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/exception/TRpcExceptionTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/exception/TRpcExceptionTest.java index b118c8776..f9a58f050 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/exception/TRpcExceptionTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/exception/TRpcExceptionTest.java @@ -11,53 +11,51 @@ package com.tencent.trpc.core.exception; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TRpcExceptionTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void testCheckArgument() { - expectedEx.expect(TRpcException.class); - expectedEx.expectMessage("error"); - TRpcException.checkArgument(Boolean.FALSE, 1, 1, "%s", "error"); + TRpcException exception = Assertions.assertThrows(TRpcException.class, () -> { + TRpcException.checkArgument(Boolean.FALSE, 1, 1, "%s", "error"); + }); + Assertions.assertTrue(exception.getMessage().contains("error")); } @Test - public void testCheckBizArgument() { - expectedEx.expect(TRpcException.class); - expectedEx.expectMessage("error"); - TRpcException.checkBizArgument(Boolean.FALSE, 1, "%s", "error"); + public void testCheckBizArg() { + TRpcException exception = Assertions.assertThrows(TRpcException.class, () -> { + TRpcException.checkBizArgument(Boolean.FALSE, 1, "%s", "error"); + }); + Assertions.assertTrue(exception.getMessage().contains("error")); } @Test - public void testCheckFrameArgument() { - expectedEx.expect(TRpcException.class); - expectedEx.expectMessage("error"); - TRpcException.checkFrameArgument(Boolean.FALSE, 1, 1, "%s", "error"); + public void testCheckFrameArg() { + TRpcException exception = Assertions.assertThrows(TRpcException.class, () -> { + TRpcException.checkFrameArgument(Boolean.FALSE, 1, 1, "%s", "error"); + }); + Assertions.assertTrue(exception.getMessage().contains("error")); } @Test public void testTrans() { - Assert.assertTrue(TRpcException.trans(new TRpcException()) instanceof TRpcException); - Assert.assertTrue(TRpcException.trans(new TransportException("a")) instanceof TRpcException); + Assertions.assertTrue(TRpcException.trans(new TRpcException()) instanceof TRpcException); + Assertions.assertTrue(TRpcException.trans(new TransportException("a")) instanceof TRpcException); } @Test public void testIsFrameException() { TRpcException frameEx = TRpcException.newFrameException(1, "frameex"); - Assert.assertTrue(frameEx.isFrameException()); - Assert.assertFalse(frameEx.isBizException()); - Assert.assertEquals(1, frameEx.getCode()); - Assert.assertEquals(0, frameEx.getBizCode()); + Assertions.assertTrue(frameEx.isFrameException()); + Assertions.assertFalse(frameEx.isBizException()); + Assertions.assertEquals(1, frameEx.getCode()); + Assertions.assertEquals(0, frameEx.getBizCode()); frameEx.setCode(2); frameEx.setBizCode(2); - Assert.assertEquals(2, frameEx.getCode()); - Assert.assertEquals(2, frameEx.getBizCode()); + Assertions.assertEquals(2, frameEx.getCode()); + Assertions.assertEquals(2, frameEx.getBizCode()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/extension/ExtensionLoaderTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/extension/ExtensionLoaderTest.java index 8b49c0788..27159ab79 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/extension/ExtensionLoaderTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/extension/ExtensionLoaderTest.java @@ -40,31 +40,23 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -/** - * NOTE: Due to the fact that ExtensionLoader is cached through static variables, - * it is important to be careful not to interfere with each other during testing. - */ public class ExtensionLoaderTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test - public void testGetExtensionLoaderNoExtensibleAnnotation() { - expectedEx.expect(TRpcExtensionException.class); - expectedEx.expectMessage("does not annotated with"); - ExtensionLoader.getExtensionLoader(NoAnnotationExt.class); + public void testGetExtNoAnnot() { + TRpcExtensionException exception = Assertions.assertThrows(TRpcExtensionException.class, () -> { + ExtensionLoader.getExtensionLoader(NoAnnotationExt.class); + }); + Assertions.assertTrue(exception.getMessage().contains("does not annotated with")); } @Test public void testGetAllExtension() { List allExtensions = ExtensionLoader.getExtensionLoader(Ext1.class).getAllExtensions(); - Assert.assertNotNull(allExtensions); + Assertions.assertNotNull(allExtensions); } @Test @@ -74,22 +66,23 @@ public void testAddExtension() { extensionLoader1.addExtension("impl2", Ext1Impl2.class); Ext1 impl1 = extensionLoader1.getExtension("impl1"); Ext1 impl2 = extensionLoader1.getExtension("impl2"); - Assert.assertTrue(impl1 instanceof Ext1Impl1); - Assert.assertTrue(impl2 instanceof Ext1Impl2); + Assertions.assertTrue(impl1 instanceof Ext1Impl1); + Assertions.assertTrue(impl2 instanceof Ext1Impl2); ExtensionLoader extensionLoader2 = ExtensionLoader.getExtensionLoader(Ext1.class); - Assert.assertSame(extensionLoader1, extensionLoader2); - Assert.assertSame(impl1, extensionLoader2.getExtension("impl1")); - Assert.assertSame(impl2, extensionLoader2.getExtension("impl2")); + Assertions.assertSame(extensionLoader1, extensionLoader2); + Assertions.assertSame(impl1, extensionLoader2.getExtension("impl1")); + Assertions.assertSame(impl2, extensionLoader2.getExtension("impl2")); } @Test - public void testAddExtensionExist() { - expectedEx.expect(TRpcExtensionException.class); - expectedEx.expectMessage("duplicate extension name"); - TRpcSystemProperties.setIgnoreSamePluginName(Boolean.FALSE); - ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext1.class); - extensionLoader.addExtension("implExist", Ext1Impl1.class); - extensionLoader.addExtension("implExist", Ext1Impl2.class); + public void testAddExtExist() { + TRpcExtensionException exception = Assertions.assertThrows(TRpcExtensionException.class, () -> { + TRpcSystemProperties.setIgnoreSamePluginName(Boolean.FALSE); + ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext1.class); + extensionLoader.addExtension("implExist", Ext1Impl1.class); + extensionLoader.addExtension("implExist", Ext1Impl2.class); + }); + Assertions.assertTrue(exception.getMessage().contains("duplicate extension name")); } @Test @@ -97,30 +90,31 @@ public void testExtensionManager() { ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext1.class); extensionLoader.addExtension("implExist", Ext1Impl1.class); ExtensionManager ext1ExtensionManager = new ExtensionManager<>(Ext1.class); - Assert.assertNull(ext1ExtensionManager.getDefaultExtension()); - Assert.assertNull(ext1ExtensionManager.getConfig("implExist")); + Assertions.assertNull(ext1ExtensionManager.getDefaultExtension()); + Assertions.assertNull(ext1ExtensionManager.getConfig("implExist")); } @Test - public void testAddExtensionSpecify2Names() { + public void testAddExt2Names() { Extension annotation = Ext1Impl3.class.getAnnotation(Extension.class); - Assert.assertNotNull(annotation); + Assertions.assertNotNull(annotation); String name = "implDuplicate"; String nameOnClass = annotation.value(); - Assert.assertNotEquals(name, nameOnClass); + Assertions.assertNotEquals(name, nameOnClass); ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext1.class); extensionLoader.addExtension(name, Ext1Impl3.class); - Assert.assertNotNull(extensionLoader.getExtension(name)); - expectedEx.expect(TRpcExtensionException.class); - expectedEx.expectMessage("Cannot get extension"); - extensionLoader.getExtension(nameOnClass); + Assertions.assertNotNull(extensionLoader.getExtension(name)); + TRpcExtensionException exception = Assertions.assertThrows(TRpcExtensionException.class, () -> { + extensionLoader.getExtension(nameOnClass); + }); + Assertions.assertTrue(exception.getMessage().contains("Cannot get extension")); } @Test public void testRemoveExtension() { ExtensionLoader extensionLoader1 = ExtensionLoader.getExtensionLoader(Ext1.class); extensionLoader1.addExtension("impl1", Ext1Impl1.class); - Assert.assertNotNull(extensionLoader1.getExtension("impl1")); + Assertions.assertNotNull(extensionLoader1.getExtension("impl1")); extensionLoader1.removeExtension("impl1"); try { extensionLoader1.getExtension("impl1"); @@ -141,11 +135,11 @@ public void testHasExtension() { loaders.remove(Selector.class); } catch (Exception e) { e.printStackTrace(); - Assert.fail("clean extensions cache failed"); + Assertions.fail("clean extensions cache failed"); } - Assert.assertFalse(ExtensionLoader.hasExtensionLoader(Selector.class)); + Assertions.assertFalse(ExtensionLoader.hasExtensionLoader(Selector.class)); ExtensionLoader.getExtensionLoader(Selector.class); - Assert.assertTrue(ExtensionLoader.hasExtensionLoader(Selector.class)); + Assertions.assertTrue(ExtensionLoader.hasExtensionLoader(Selector.class)); } @Test @@ -153,9 +147,9 @@ public void testReplaceExtension() { ExtensionLoader extensionLoader = ExtensionLoader .getExtensionLoader(Selector.class); extensionLoader.addExtension("selector", IpSelector.class); - Assert.assertTrue(extensionLoader.getExtension("selector") instanceof IpSelector); + Assertions.assertTrue(extensionLoader.getExtension("selector") instanceof IpSelector); extensionLoader.replaceExtension("selector", MockSelector.class); - Assert.assertTrue(extensionLoader.getExtension("selector") instanceof MockSelector); + Assertions.assertTrue(extensionLoader.getExtension("selector") instanceof MockSelector); } @Test @@ -163,12 +157,12 @@ public void testRefreshExtension() { ExtensionLoader extensionLoader = ExtensionLoader .getExtensionLoader(Selector.class); extensionLoader.addExtension("selector1", IpSelector.class); - Assert.assertTrue(extensionLoader.getExtension("selector1") instanceof IpSelector); + Assertions.assertTrue(extensionLoader.getExtension("selector1") instanceof IpSelector); PluginConfig pluginConfig = new PluginConfig("selector1", MockSelector.class); try { extensionLoader.refresh("selector1", pluginConfig); } catch (Exception e) { - Assert.assertTrue(e instanceof TRpcExtensionException); + Assertions.assertTrue(e instanceof TRpcExtensionException); } ExtensionClass selector = extensionLoader.getExtensionClass("selector1"); selector.refresh(pluginConfig); @@ -177,48 +171,48 @@ public void testRefreshExtension() { @Test public void testGetDefaultExtension() { ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext2.class); - Assert.assertNotNull(extensionLoader.getDefaultExtension()); + Assertions.assertNotNull(extensionLoader.getDefaultExtension()); } @Test public void testGetDefaultExtensionNotExist() { // default plugins have been not configured. ExtensionLoader extensionLoader1 = ExtensionLoader.getExtensionLoader(Ext1.class); - Assert.assertNull(extensionLoader1.getDefaultExtension()); + Assertions.assertNull(extensionLoader1.getDefaultExtension()); // The default plugin configured does not exist. ExtensionLoader extensionLoader2 = ExtensionLoader.getExtensionLoader(DefaultNotExistExt.class); - Assert.assertNull(extensionLoader2.getDefaultExtension()); + Assertions.assertNull(extensionLoader2.getDefaultExtension()); } @Test public void testGetExtensionWithConfigFile() { ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext3.class); - Assert.assertNotNull(extensionLoader.getExtension("impl1")); - Assert.assertNotNull(extensionLoader.getExtension("impl2")); - Assert.assertNotNull(extensionLoader.getExtension("impl3")); - Assert.assertNotNull(extensionLoader.getExtension("impl4")); - Assert.assertNotNull(extensionLoader.getExtension("impl5")); - Assert.assertNotNull(extensionLoader.getExtension("impl6")); - Assert.assertNotNull(extensionLoader.getExtension("impl7")); - Assert.assertNotNull(extensionLoader.getExtension("impl8")); - Assert.assertNotNull(extensionLoader.getExtension("impl9")); + Assertions.assertNotNull(extensionLoader.getExtension("impl1")); + Assertions.assertNotNull(extensionLoader.getExtension("impl2")); + Assertions.assertNotNull(extensionLoader.getExtension("impl3")); + Assertions.assertNotNull(extensionLoader.getExtension("impl4")); + Assertions.assertNotNull(extensionLoader.getExtension("impl5")); + Assertions.assertNotNull(extensionLoader.getExtension("impl6")); + Assertions.assertNotNull(extensionLoader.getExtension("impl7")); + Assertions.assertNotNull(extensionLoader.getExtension("impl8")); + Assertions.assertNotNull(extensionLoader.getExtension("impl9")); try { extensionLoader.getExtension("impl10"); } catch (Exception e) { - Assert.assertTrue(e instanceof TRpcExtensionException); + Assertions.assertTrue(e instanceof TRpcExtensionException); } - Assert.assertSame(extensionLoader.getExtension("impl1"), + Assertions.assertSame(extensionLoader.getExtension("impl1"), extensionLoader.getExtension("impl1")); - Assert.assertSame(extensionLoader.getExtension("impl3"), + Assertions.assertSame(extensionLoader.getExtension("impl3"), extensionLoader.getExtension("impl3")); - Assert.assertSame(extensionLoader.getExtension("impl5"), + Assertions.assertSame(extensionLoader.getExtension("impl5"), extensionLoader.getExtension("impl5")); - Assert.assertSame(extensionLoader.getExtension("impl6"), + Assertions.assertSame(extensionLoader.getExtension("impl6"), extensionLoader.getExtension("impl6")); - Assert.assertSame(extensionLoader.getExtension("impl7"), + Assertions.assertSame(extensionLoader.getExtension("impl7"), extensionLoader.getExtension("impl7")); - Assert.assertSame(extensionLoader.getExtension("impl9"), + Assertions.assertSame(extensionLoader.getExtension("impl9"), extensionLoader.getExtension("impl9")); } @@ -228,7 +222,7 @@ public void testGetExtensionWithPluginConfig() { try { extensionLoader.getExtension("impl10"); } catch (Exception ex) { - Assert.assertEquals(ex.getCause().getClass(), IllegalArgumentException.class); + Assertions.assertEquals(ex.getCause().getClass(), IllegalArgumentException.class); } } @@ -249,30 +243,30 @@ public void testGetActivateExtensions() { private void assertExtensionClassesEqual(List extensions, List> extensionClasses) { - Assert.assertNotNull(extensions); - Assert.assertNotNull(extensionClasses); + Assertions.assertNotNull(extensions); + Assertions.assertNotNull(extensionClasses); Iterator extIter = extensions.iterator(); Iterator> extClassIter = extensionClasses.iterator(); while (extIter.hasNext() && extClassIter.hasNext()) { T ext = extIter.next(); Class extClass = extClassIter.next(); - Assert.assertNotNull(ext); - Assert.assertNotNull(extClass); - Assert.assertSame(ext.getClass(), extClass); + Assertions.assertNotNull(ext); + Assertions.assertNotNull(extClass); + Assertions.assertSame(ext.getClass(), extClass); } - Assert.assertFalse(extIter.hasNext()); - Assert.assertFalse(extClassIter.hasNext()); + Assertions.assertFalse(extIter.hasNext()); + Assertions.assertFalse(extClassIter.hasNext()); } @Test public void testGetActivateExtensionsNotExist() { ExtensionLoader extensionLoader1 = ExtensionLoader.getExtensionLoader(DefaultNotExistExt.class); - Assert.assertTrue(extensionLoader1.getActivateExtensions(ActivationGroup.PROVIDER).isEmpty()); - Assert.assertTrue(extensionLoader1.getActivateExtensions(ActivationGroup.CONSUMER).isEmpty()); + Assertions.assertTrue(extensionLoader1.getActivateExtensions(ActivationGroup.PROVIDER).isEmpty()); + Assertions.assertTrue(extensionLoader1.getActivateExtensions(ActivationGroup.CONSUMER).isEmpty()); ExtensionLoader extensionLoader2 = ExtensionLoader.getExtensionLoader(Ext2.class); - Assert.assertTrue(extensionLoader2.getActivateExtensions(ActivationGroup.PROVIDER).isEmpty()); - Assert.assertTrue(extensionLoader2.getActivateExtensions(ActivationGroup.CONSUMER).isEmpty()); + Assertions.assertTrue(extensionLoader2.getActivateExtensions(ActivationGroup.PROVIDER).isEmpty()); + Assertions.assertTrue(extensionLoader2.getActivateExtensions(ActivationGroup.CONSUMER).isEmpty()); } @Test @@ -281,9 +275,9 @@ public void testGetActivateExtensionsUseFilter() { Set extNames = new HashSet<>(Arrays.asList("impl8", "impl7", "impl1")); ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Ext3.class); List exts = extensionLoader.getExtensions(extClass -> extNames.contains(extClass.getName())); - Assert.assertTrue(exts.get(0) instanceof Ext3Impl1); - Assert.assertTrue(exts.get(1) instanceof Ext3Impl7); - Assert.assertTrue(exts.get(2) instanceof Ext3Impl8); + Assertions.assertTrue(exts.get(0) instanceof Ext3Impl1); + Assertions.assertTrue(exts.get(1) instanceof Ext3Impl7); + Assertions.assertTrue(exts.get(2) instanceof Ext3Impl8); List> extClasses = Arrays.asList(Ext3Impl1.class, Ext3Impl7.class, Ext3Impl8.class); assertExtensionClassesEqual(exts, extClasses); @@ -325,8 +319,8 @@ public void testMultiThread() { ext.echo(); for (int i = 0; i < workerNum; i++) { ExtensionLoader loader = loaders[i]; - Assert.assertSame(extensionLoader, loader); - Assert.assertSame(ext, exts[i]); + Assertions.assertSame(extensionLoader, loader); + Assertions.assertSame(ext, exts[i]); } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/filter/ConsumerFilterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/filter/ConsumerFilterInvokerTest.java index 69fef47ef..eadfd9a3c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/filter/ConsumerFilterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/filter/ConsumerFilterInvokerTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.filter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Lists; import com.tencent.trpc.core.common.ConfigManager; @@ -32,14 +32,14 @@ import com.tencent.trpc.core.rpc.def.DefResponse; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -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; public class ConsumerFilterInvokerTest { - @Before + @BeforeEach public void before() { ServerConfig serverConfig = new ServerConfig(); serverConfig.setLocalIp("127.0.1.1"); @@ -52,7 +52,7 @@ public void before() { ConfigManager.getInstance().setGlobalConfig(globalConfig); } - @After + @AfterEach public void after() { ConfigManager.getInstance().stopTest(); } @@ -68,9 +68,9 @@ public void buildNormalTest() { ProtocolConfig protoConfig = createProtoConfig(); ConsumerInvoker buildConsumerChain = FilterChain .buildConsumerChain(config, new ConsumerInvokerMock<>(config, protoConfig)); - Assert.assertEquals(config, buildConsumerChain.getConfig()); - Assert.assertEquals(protoConfig, buildConsumerChain.getProtocolConfig()); - Assert.assertNull(buildConsumerChain.getInterface()); + Assertions.assertEquals(config, buildConsumerChain.getConfig()); + Assertions.assertEquals(protoConfig, buildConsumerChain.getProtocolConfig()); + Assertions.assertNull(buildConsumerChain.getInterface()); CompletionStage invoke = buildConsumerChain.invoke(createRequest()); Response r = invoke.toCompletableFuture().join(); assertEquals(r.getValue(), 20); @@ -218,4 +218,4 @@ public ProtocolConfig getProtocolConfig() { return protoConfig; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/filter/ProviderFilterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/filter/ProviderFilterInvokerTest.java index fcedeef2b..243575022 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/filter/ProviderFilterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/filter/ProviderFilterInvokerTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.filter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Lists; import com.tencent.trpc.core.common.ConfigManager; @@ -30,19 +30,19 @@ import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -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; public class ProviderFilterInvokerTest { - @Before + @BeforeEach public void before() { ConfigManager.getInstance().stopTest(); } - @After + @AfterEach public void after() { ConfigManager.getInstance().stopTest(); } @@ -58,10 +58,10 @@ public void buildNormalTest() { ProtocolConfig protoConfig = createProtoConfig(); ProviderInvoker buildProviderChain = FilterChain.buildProviderChain(config, new ProviderInvokerMock(config, protoConfig)); - Assert.assertEquals(config, buildProviderChain.getConfig()); - Assert.assertEquals(protoConfig, buildProviderChain.getProtocolConfig()); - Assert.assertNull(buildProviderChain.getImpl()); - Assert.assertNull(buildProviderChain.getInterface()); + Assertions.assertEquals(config, buildProviderChain.getConfig()); + Assertions.assertEquals(protoConfig, buildProviderChain.getProtocolConfig()); + Assertions.assertNull(buildProviderChain.getImpl()); + Assertions.assertNull(buildProviderChain.getInterface()); CompletionStage invoke = buildProviderChain.invoke(createRequest()); Response r = (Response) (invoke.toCompletableFuture().join()); assertEquals(r.getValue(), 20); @@ -217,4 +217,4 @@ public ProtocolConfig getProtocolConfig() { return protoConfig; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterBlockHandlerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterBlockHandlerTest.java index b03c7eb86..c483ae88d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterBlockHandlerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterBlockHandlerTest.java @@ -20,8 +20,8 @@ import com.tencent.trpc.core.rpc.def.DefRequest; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DefLimiterBlockHandlerTest { @@ -43,8 +43,8 @@ public void testFallback() { exception.printStackTrace(); } catch (ExecutionException executionException) { Throwable cause = executionException.getCause(); - Assert.assertTrue(cause instanceof LimiterBlockException); - Assert.assertTrue("test call block handler".equals(cause.getMessage())); + Assertions.assertTrue(cause instanceof LimiterBlockException); + Assertions.assertTrue("test call block handler".equals(cause.getMessage())); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterFallbackTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterFallbackTest.java index 480d814a4..d21bf0507 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterFallbackTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterFallbackTest.java @@ -20,8 +20,8 @@ import com.tencent.trpc.core.rpc.def.DefRequest; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DefLimiterFallbackTest { @@ -43,9 +43,9 @@ public void testFallback() { exception.printStackTrace(); } catch (ExecutionException executionException) { Throwable cause = executionException.getCause(); - Assert.assertTrue(cause instanceof LimiterFallbackException); - Assert.assertTrue(cause.getCause() instanceof NullPointerException); - Assert.assertTrue("test call fallback as null pointer".equals(cause.getCause().getMessage())); + Assertions.assertTrue(cause instanceof LimiterFallbackException); + Assertions.assertTrue(cause.getCause() instanceof NullPointerException); + Assertions.assertTrue("test call fallback as null pointer".equals(cause.getCause().getMessage())); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterResourceExtractorTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterResourceExtractorTest.java index 0f5bec9f5..7f52e4a69 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterResourceExtractorTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/limiter/DefLimiterResourceExtractorTest.java @@ -15,8 +15,8 @@ import com.tencent.trpc.core.limiter.spi.LimiterResourceExtractor; import com.tencent.trpc.core.rpc.RpcInvocation; import com.tencent.trpc.core.rpc.def.DefRequest; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DefLimiterResourceExtractorTest { @@ -31,7 +31,7 @@ public void testExtractor() { request.setInvocation(rpcInvocation); String resource = extractor.extract(null, request); - Assert.assertEquals("/test/func", resource); + Assertions.assertEquals("/test/func", resource); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/logger/LoggerFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/logger/LoggerFactoryTest.java index 0fa8dce88..5a11fc42d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/logger/LoggerFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/logger/LoggerFactoryTest.java @@ -12,20 +12,20 @@ package com.tencent.trpc.core.logger; import com.tencent.trpc.core.common.ConfigManager; -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; public class LoggerFactoryTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -56,12 +56,12 @@ public void buildNormalTest() { logger.error("hello world %s", e); logger.error("hello world", e); - Assert.assertTrue(logger.isDebugEnabled()); - Assert.assertTrue(logger.isTraceEnabled()); - Assert.assertTrue(logger.isInfoEnabled()); - Assert.assertTrue(logger.isWarnEnabled()); - Assert.assertTrue(logger.isErrorEnabled()); - Assert.assertNotNull(logger.getName()); + Assertions.assertTrue(logger.isDebugEnabled()); + Assertions.assertTrue(logger.isTraceEnabled()); + Assertions.assertTrue(logger.isInfoEnabled()); + Assertions.assertTrue(logger.isWarnEnabled()); + Assertions.assertTrue(logger.isErrorEnabled()); + Assertions.assertNotNull(logger.getName()); LoggerFactory.getLoggerLevel(); LoggerFactory.setLoggerLevel(LoggerLevel.DEBUG); @@ -70,13 +70,13 @@ public void buildNormalTest() { @Test public void testGetLogger() { Logger logger = LoggerFactory.getLogger("logger"); - Assert.assertNotNull(logger); + Assertions.assertNotNull(logger); } @Test public void testGetRemoteLogger() { RemoteLogger test = LoggerFactory.getRemoteLogger("test"); - Assert.assertNotNull(test); - Assert.assertTrue(test instanceof TestRemoteLogger); + Assertions.assertNotNull(test); + Assertions.assertTrue(test instanceof TestRemoteLogger); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/logger/RemoteLoggerFilterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/logger/RemoteLoggerFilterTest.java index 12212162e..79e43e143 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/logger/RemoteLoggerFilterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/logger/RemoteLoggerFilterTest.java @@ -27,20 +27,20 @@ import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -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; public class RemoteLoggerFilterTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -52,8 +52,8 @@ public void testRemoteLoggerFilter() throws NoSuchMethodException { ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(Filter.class); TestRemoteLoggerFilter filter = (TestRemoteLoggerFilter) extensionLoader.getExtension("test"); - Assert.assertNotNull(filter); - Assert.assertEquals("test", filter.getPluginName()); + Assertions.assertNotNull(filter); + Assertions.assertEquals("test", filter.getPluginName()); RpcInvocation rpcInvocation = new RpcInvocation(); rpcInvocation.setRpcServiceName("a"); rpcInvocation.setRpcMethodName("b"); diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerAdapterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerAdapterTest.java index 170326617..839ec2c5b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerAdapterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerAdapterTest.java @@ -14,16 +14,16 @@ import com.tencent.trpc.core.common.config.PluginConfig; import com.tencent.trpc.core.logger.LoggerAdapter; import com.tencent.trpc.core.logger.LoggerLevel; -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; public class Slf4jLoggerAdapterTest { private Slf4jLoggerAdapter slf4jLoggerAdapter; private PluginConfig pluginConfig; - @Before + @BeforeEach public void setUp() { this.slf4jLoggerAdapter = new Slf4jLoggerAdapter(); this.pluginConfig = new PluginConfig("slf4j", LoggerAdapter.class, Slf4jLoggerAdapter.class); @@ -37,25 +37,25 @@ public void testInit() { @Test public void testGetLoggerWithName() { - Assert.assertNotNull(slf4jLoggerAdapter.getLogger("a")); + Assertions.assertNotNull(slf4jLoggerAdapter.getLogger("a")); } @Test public void testGetLoggerWithClass() { - Assert.assertNotNull(slf4jLoggerAdapter.getLogger(Slf4jLoggerAdapterTest.class)); + Assertions.assertNotNull(slf4jLoggerAdapter.getLogger(Slf4jLoggerAdapterTest.class)); } @Test public void testGetLoggerLevel() { LoggerLevel loggerLevel = slf4jLoggerAdapter.getLoggerLevel(); - Assert.assertNull(loggerLevel); + Assertions.assertNull(loggerLevel); } @Test public void testSetLoggerLevel() { this.slf4jLoggerAdapter.setLoggerLevel(LoggerLevel.ALL); LoggerLevel loggerLevel = slf4jLoggerAdapter.getLoggerLevel(); - Assert.assertNull(loggerLevel); + Assertions.assertNull(loggerLevel); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerTest.java index 601d2870d..e76e794a3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/logger/slf4j/Slf4jLoggerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -16,33 +16,38 @@ import com.tencent.trpc.core.logger.LoggerFactory; import com.tencent.trpc.core.logger.LoggerFactoryTest; import com.tencent.trpc.core.logger.LoggerLevel; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + import org.slf4j.helpers.NOPLogger; -@RunWith(PowerMockRunner.class) -@PrepareForTest({LoggerFactory.class}) +@ExtendWith(MockitoExtension.class) public class Slf4jLoggerTest { - @Before + private MockedStatic mockedStatic; + + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); - PowerMockito.mockStatic(LoggerFactory.class); - PowerMockito.when(LoggerFactory.getLogger(LoggerFactoryTest.class)) + mockedStatic = Mockito.mockStatic(LoggerFactory.class); + mockedStatic.when(() -> LoggerFactory.getLogger(LoggerFactoryTest.class)) .thenReturn(new Slf4jLogger(NOPLogger.NOP_LOGGER)); - PowerMockito.when(LoggerFactory.getLogger("logger")) + mockedStatic.when(() -> LoggerFactory.getLogger("logger")) .thenReturn(new Slf4jLogger(NOPLogger.NOP_LOGGER)); } - @After + @AfterEach public void after() { + if (mockedStatic != null) { + mockedStatic.close(); + } ConfigManager.stopTest(); } @@ -72,12 +77,12 @@ public void buildNormalTest() { logger.error("hello world %s", e); logger.error("hello world", e); - Assert.assertFalse(logger.isDebugEnabled()); - Assert.assertFalse(logger.isTraceEnabled()); - Assert.assertFalse(logger.isInfoEnabled()); - Assert.assertFalse(logger.isWarnEnabled()); - Assert.assertFalse(logger.isErrorEnabled()); - Assert.assertNotNull(logger.getName()); + Assertions.assertFalse(logger.isDebugEnabled()); + Assertions.assertFalse(logger.isTraceEnabled()); + Assertions.assertFalse(logger.isInfoEnabled()); + Assertions.assertFalse(logger.isWarnEnabled()); + Assertions.assertFalse(logger.isErrorEnabled()); + Assertions.assertNotNull(logger.getName()); LoggerFactory.getLoggerLevel(); LoggerFactory.setLoggerLevel(LoggerLevel.DEBUG); @@ -86,7 +91,7 @@ public void buildNormalTest() { @Test public void testGetLogger() { Logger logger = LoggerFactory.getLogger("logger"); - Assert.assertNotNull(logger); + Assertions.assertNotNull(logger); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorMXBeanTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorMXBeanTest.java index d5c6072f6..8d8ac0a3f 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorMXBeanTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorMXBeanTest.java @@ -12,23 +12,23 @@ package com.tencent.trpc.core.management; import java.util.concurrent.ExecutorService; -import org.junit.Assert; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class ThreadPerTaskExecutorMXBeanTest { @Test public void testThreadPerTaskExecutorMXBean() { - ExecutorService executorService = PowerMockito.mock(ExecutorService.class); + ExecutorService executorService = Mockito.mock(ExecutorService.class); ThreadPerTaskExecutorWrapper wrapper = ThreadPerTaskExecutorWrapper.wrap(executorService); ThreadPoolMXBean mxBean = new ThreadPerTaskExecutorMXBeanImpl(wrapper); - Assert.assertEquals(0, mxBean.getPoolSize()); - Assert.assertEquals(0, mxBean.getActiveThreadCount()); - Assert.assertEquals(0, mxBean.getTaskCount()); - Assert.assertEquals(0, mxBean.getCompletedTaskCount()); - Assert.assertEquals(0, mxBean.getCorePoolSize()); - Assert.assertEquals(Integer.MAX_VALUE, mxBean.getMaximumPoolSize()); + Assertions.assertEquals(0, mxBean.getPoolSize()); + Assertions.assertEquals(0, mxBean.getActiveThreadCount()); + Assertions.assertEquals(0, mxBean.getTaskCount()); + Assertions.assertEquals(0, mxBean.getCompletedTaskCount()); + Assertions.assertEquals(0, mxBean.getCorePoolSize()); + Assertions.assertEquals(Integer.MAX_VALUE, mxBean.getMaximumPoolSize()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorWrapperTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorWrapperTest.java index 1c20521f1..a82074ec4 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorWrapperTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/management/ThreadPerTaskExecutorWrapperTest.java @@ -21,9 +21,9 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.Assert; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class ThreadPerTaskExecutorWrapperTest { @@ -34,26 +34,26 @@ public void testThreadPerTaskExecutorWrapper() throws ExecutionException, Interr Callable callable = () -> "mock"; Future submit = wrapper.submit(callable); submit.get(); - Assert.assertEquals(1, wrapper.getSubmittedTaskCount()); - Assert.assertEquals(1, wrapper.getCompletedTaskCount()); + Assertions.assertEquals(1, wrapper.getSubmittedTaskCount()); + Assertions.assertEquals(1, wrapper.getCompletedTaskCount()); List> callables = Arrays.asList(callable, callable, callable); List> futures = wrapper.invokeAll(callables); for (Future future : futures) { future.get(); } - Assert.assertEquals(4, wrapper.getSubmittedTaskCount()); - Assert.assertEquals(4, wrapper.getCompletedTaskCount()); + Assertions.assertEquals(4, wrapper.getSubmittedTaskCount()); + Assertions.assertEquals(4, wrapper.getCompletedTaskCount()); Runnable runnable = () -> { }; Future future = wrapper.submit(runnable); future.get(); - Assert.assertEquals(5, wrapper.getSubmittedTaskCount()); - Assert.assertEquals(5, wrapper.getCompletedTaskCount()); + Assertions.assertEquals(5, wrapper.getSubmittedTaskCount()); + Assertions.assertEquals(5, wrapper.getCompletedTaskCount()); } @Test public void testThreadPerTaskExecutorWrapper2() throws ExecutionException, InterruptedException, TimeoutException { - ExecutorService executorService = PowerMockito.mock(ExecutorService.class); + ExecutorService executorService = Mockito.mock(ExecutorService.class); ThreadPerTaskExecutorWrapper wrapper = ThreadPerTaskExecutorWrapper.wrap(executorService); Runnable runnable = () -> { }; @@ -72,8 +72,8 @@ public void testThreadPerTaskExecutorWrapper2() throws ExecutionException, Inter wrapper.isShutdown(); wrapper.isTerminated(); wrapper.awaitTermination(1, TimeUnit.SECONDS); - Assert.assertEquals(0, wrapper.getSubmittedTaskCount()); - Assert.assertEquals(0, wrapper.getCompletedTaskCount()); + Assertions.assertEquals(0, wrapper.getSubmittedTaskCount()); + Assertions.assertEquals(0, wrapper.getCompletedTaskCount()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/ActiveInvocationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/ActiveInvocationTest.java index 6b48a0578..97c448708 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/ActiveInvocationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/ActiveInvocationTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.metrics; -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; /** * ActiveInvocation test @@ -22,7 +22,7 @@ public class ActiveInvocationTest { private ActiveInvocation activeInvocation; - @Before + @BeforeEach public void setUp() throws Exception { MetricsCallInfo passiveCallInfo = new MetricsCallInfo("passiveApp", "passiveServer", "passiveService", "passiveInterface", "passiveIp", @@ -33,51 +33,51 @@ public void setUp() throws Exception { @Test public void testGetActiveService() { - Assert.assertEquals("activeService", activeInvocation.getActiveService()); + Assertions.assertEquals("activeService", activeInvocation.getActiveService()); } @Test public void testGetActiveInterface() { - Assert.assertEquals("activeInterface", activeInvocation.getActiveMethodName()); + Assertions.assertEquals("activeInterface", activeInvocation.getActiveMethodName()); } @Test public void testGetPassiveApp() { - Assert.assertEquals("passiveApp", activeInvocation.getPassiveCallInfo().getApp()); + Assertions.assertEquals("passiveApp", activeInvocation.getPassiveCallInfo().getApp()); } @Test public void testGetPassiveServer() { - Assert.assertEquals("passiveServer", activeInvocation.getPassiveCallInfo().getServer()); + Assertions.assertEquals("passiveServer", activeInvocation.getPassiveCallInfo().getServer()); } @Test public void testGetPassiveService() { - Assert.assertEquals("passiveService", activeInvocation.getPassiveCallInfo().getService()); + Assertions.assertEquals("passiveService", activeInvocation.getPassiveCallInfo().getService()); } @Test public void testGetPassiveInterface() { - Assert.assertEquals("passiveInterface", activeInvocation.getPassiveCallInfo().getMethodName()); + Assertions.assertEquals("passiveInterface", activeInvocation.getPassiveCallInfo().getMethodName()); } @Test public void testGetPassiveIp() { - Assert.assertEquals("passiveIp", activeInvocation.getPassiveCallInfo().getIp()); + Assertions.assertEquals("passiveIp", activeInvocation.getPassiveCallInfo().getIp()); } @Test public void testGetPassiveContainer() { - Assert.assertEquals("passiveContainer", activeInvocation.getPassiveCallInfo().getContainer()); + Assertions.assertEquals("passiveContainer", activeInvocation.getPassiveCallInfo().getContainer()); } @Test public void testGetPassiveConSetId() { - Assert.assertEquals("passiveConSetId", activeInvocation.getPassiveCallInfo().getContainerSetId()); + Assertions.assertEquals("passiveConSetId", activeInvocation.getPassiveCallInfo().getContainerSetId()); } @Test public void testTestToString() { - Assert.assertNotNull(activeInvocation.toString()); + Assertions.assertNotNull(activeInvocation.toString()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricNameTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricNameTest.java index 8f17ebf9c..1680dcc1d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricNameTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricNameTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,8 +11,8 @@ package com.tencent.trpc.core.metrics; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * MetricNameTest @@ -22,26 +22,26 @@ public class MetricNameTest { @Test public void testTestEquals() { MetricName labelName = MetricName.build("test", null); - Assert.assertNotNull(labelName.getLabels()); + Assertions.assertNotNull(labelName.getLabels()); MetricName name = MetricName.build("test"); MetricName name1 = MetricName.build("test"); - Assert.assertEquals(name, name1); + Assertions.assertEquals(name, name1); name = MetricName.build("test", "1", "2"); name1 = MetricName.build("test", "1", "2"); - Assert.assertEquals(name, name1); + Assertions.assertEquals(name, name1); name = MetricName.build("test", "1"); name1 = MetricName.build("test", "1", "2"); - Assert.assertNotEquals(name, name1); + Assertions.assertNotEquals(name, name1); - Assert.assertEquals(name.getName(), name1.getName()); - Assert.assertNotEquals(name.getLabels().length, name1.getLabels().length); - Assert.assertNotSame(name.hashCode(),name.hashCode()); + Assertions.assertEquals(name.getName(), name1.getName()); + Assertions.assertNotEquals(name.getLabels().length, name1.getLabels().length); + Assertions.assertNotSame(name.hashCode(), name.hashCode()); - Assert.assertNotSame("", name.toString()); - Assert.assertNotSame(MetricName.build("test", "1").hashCode(), + Assertions.assertNotSame("", name.toString()); + Assertions.assertNotSame(MetricName.build("test", "1").hashCode(), MetricName.build("test", "1").hashCode()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsCustomTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsCustomTest.java index 5a0d1c8be..843ff2937 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsCustomTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsCustomTest.java @@ -11,11 +11,11 @@ package com.tencent.trpc.core.metrics; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.metrics.MetricsCustom.StatPolicy; import com.tencent.trpc.core.metrics.MetricsCustom.StatValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetricsCustomTest { @@ -27,4 +27,4 @@ public void testStatValue() { assertEquals(100.0d, statValue2.value, 0.0); assertEquals(10, statValue2.count); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsTest.java index cf2e032fb..30c543d83 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/MetricsTest.java @@ -19,8 +19,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; 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; public class MetricsTest { @@ -61,18 +61,18 @@ public void testLoad() { COUNTER.set(0); Metrics.counter("a").incr(); - Assert.assertEquals(1, COUNTER.get()); + Assertions.assertEquals(1, COUNTER.get()); Metrics.gauge("b").set(100); - Assert.assertEquals(100, GAUGE.get()); + Assertions.assertEquals(100, GAUGE.get()); COUNTER.set(0); Metrics.histogram("c").record(100); - Assert.assertEquals(1, COUNTER.get()); + Assertions.assertEquals(1, COUNTER.get()); COUNTER.set(0); Metrics.histogram("c", new double[]{0}, "1").record(100, "1"); - Assert.assertEquals(1, COUNTER.get()); + Assertions.assertEquals(1, COUNTER.get()); } @Test @@ -104,8 +104,8 @@ public void set(String attrName, int value) { metricsFactory.counter("counter").incr(value); metricsFactory.gauge("gauge").set(value); } - Assert.assertEquals(5050, count.get()); - Assert.assertEquals(count1, gauge.get()); + Assertions.assertEquals(5050, count.get()); + Assertions.assertEquals(count1, gauge.get()); // test histogram count.set(0); @@ -113,34 +113,34 @@ public void set(String attrName, int value) { int value = i + 1; metricsFactory.histogram("counter").record(value); } - Assert.assertEquals(count1, count.get()); + Assertions.assertEquals(count1, count.get()); // test normal counter count.set(0); for (int i = 0; i < count1; i++) { metricsFactory.counter("counter").incr(); } - Assert.assertEquals(count1, count.get()); + Assertions.assertEquals(count1, count.get()); try { metricsFactory.getActiveStat(null); - Assert.fail("not supported by default"); + Assertions.fail("not supported by default"); } catch (Exception e) { - Assert.assertTrue(e instanceof UnsupportedOperationException); + Assertions.assertTrue(e instanceof UnsupportedOperationException); } try { metricsFactory.getCustomData(null, null); - Assert.fail("not supported by default"); + Assertions.fail("not supported by default"); } catch (Exception e) { - Assert.assertTrue(e instanceof UnsupportedOperationException); + Assertions.assertTrue(e instanceof UnsupportedOperationException); } try { metricsFactory.getPassiveStat(null); - Assert.fail("not supported by default"); + Assertions.fail("not supported by default"); } catch (Exception e) { - Assert.assertTrue(e instanceof UnsupportedOperationException); + Assertions.assertTrue(e instanceof UnsupportedOperationException); } } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/PassiveInvocationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/PassiveInvocationTest.java index f51b485b3..1eae07c37 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/PassiveInvocationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/PassiveInvocationTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.metrics; -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; /** * PassiveInvocation test @@ -22,7 +22,7 @@ public class PassiveInvocationTest { private PassiveInvocation passiveInvocation; - @Before + @BeforeEach public void setUp() throws Exception { MetricsCallInfo activeCallInfo = new MetricsCallInfo("ActiveApp", "ActiveServer", "ActiveService", "ActiveInterface", "ActiveIp", @@ -33,51 +33,51 @@ public void setUp() throws Exception { @Test public void testGetActiveApp() { - Assert.assertEquals("ActiveApp", passiveInvocation.getActiveCallInfo().getApp()); + Assertions.assertEquals("ActiveApp", passiveInvocation.getActiveCallInfo().getApp()); } @Test public void testGetActiveServer() { - Assert.assertEquals("ActiveServer", passiveInvocation.getActiveCallInfo().getServer()); + Assertions.assertEquals("ActiveServer", passiveInvocation.getActiveCallInfo().getServer()); } @Test public void testGetActiveService() { - Assert.assertEquals("ActiveService", passiveInvocation.getActiveCallInfo().getService()); + Assertions.assertEquals("ActiveService", passiveInvocation.getActiveCallInfo().getService()); } @Test public void testGetActiveInterface() { - Assert.assertEquals("ActiveInterface", passiveInvocation.getActiveCallInfo().getMethodName()); + Assertions.assertEquals("ActiveInterface", passiveInvocation.getActiveCallInfo().getMethodName()); } @Test public void testGetActiveIp() { - Assert.assertEquals("ActiveIp", passiveInvocation.getActiveCallInfo().getIp()); + Assertions.assertEquals("ActiveIp", passiveInvocation.getActiveCallInfo().getIp()); } @Test public void testGetActiveContainer() { - Assert.assertEquals("ActiveContainer", passiveInvocation.getActiveCallInfo().getContainer()); + Assertions.assertEquals("ActiveContainer", passiveInvocation.getActiveCallInfo().getContainer()); } @Test public void testGetActiveConSetId() { - Assert.assertEquals("ActiveConSetId", passiveInvocation.getActiveCallInfo().getContainerSetId()); + Assertions.assertEquals("ActiveConSetId", passiveInvocation.getActiveCallInfo().getContainerSetId()); } @Test public void testGetPassiveService() { - Assert.assertEquals("PassiveService", passiveInvocation.getPassiveService()); + Assertions.assertEquals("PassiveService", passiveInvocation.getPassiveService()); } @Test public void testGetPassiveInterface() { - Assert.assertEquals("PassiveInterface", passiveInvocation.getPassiveMethodName()); + Assertions.assertEquals("PassiveInterface", passiveInvocation.getPassiveMethodName()); } @Test public void testTestToString() { - Assert.assertNotNull(passiveInvocation.toString()); + Assertions.assertNotNull(passiveInvocation.toString()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/spi/AbstractMetricsFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/spi/AbstractMetricsFactoryTest.java index d7698b311..3412bcbc5 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/metrics/spi/AbstractMetricsFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/metrics/spi/AbstractMetricsFactoryTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -13,13 +13,13 @@ import com.tencent.trpc.core.metrics.MetricsAttr; import com.tencent.trpc.core.metrics.MetricsCustom; -import junit.framework.TestCase; -import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -public class AbstractMetricsFactoryTest extends TestCase { +public class AbstractMetricsFactoryTest { public void testCounter() { AtomicInteger count = new AtomicInteger(); @@ -52,14 +52,14 @@ public MetricsCustom getCustomData(String name, List dimensions) { }; factory.counter("a").incr(); - Assert.assertEquals(1, count.get()); + Assertions.assertEquals(1, count.get()); String label = "1"; factory.counter("a", "label").incr(2); - Assert.assertNull(report.get()); + Assertions.assertNull(report.get()); factory.counter("a", "label").incr(2, label); - Assert.assertEquals(label, report.get().get(0)); - Assert.assertEquals(2, statValues.get().get(0).value, 0.0); + Assertions.assertEquals(label, report.get().get(0)); + Assertions.assertEquals(2, statValues.get().get(0).value, 0.0); } public void testGauge() { @@ -93,15 +93,15 @@ public MetricsCustom getCustomData(String name, List dimensions) { }; factory.gauge("a").set(100); - Assert.assertEquals(100, gauge.get()); + Assertions.assertEquals(100, gauge.get()); String label = "1"; factory.gauge("a", "label").set(200); - Assert.assertNull(report.get()); + Assertions.assertNull(report.get()); factory.gauge("a", "label").set(200, label); - Assert.assertEquals(label, report.get().get(0)); - Assert.assertEquals(200, statValues.get().get(0).value, 0.0); + Assertions.assertEquals(label, report.get().get(0)); + Assertions.assertEquals(200, statValues.get().get(0).value, 0.0); } public void testHistogram() { @@ -135,14 +135,14 @@ public MetricsCustom getCustomData(String name, List dimensions) { }; factory.histogram("a").record(1); - Assert.assertEquals(1, gauge.get()); + Assertions.assertEquals(1, gauge.get()); String label = "1"; factory.histogram("a").record(1, ""); - Assert.assertNull(report.get()); + Assertions.assertNull(report.get()); factory.histogram("a", new double[]{0}, "label").record(1, label); - Assert.assertEquals(label, report.get().get(0)); - Assert.assertEquals(1, statValues.get().get(0).value, 0.0); + Assertions.assertEquals(label, report.get().get(0)); + Assertions.assertEquals(1, statValues.get().get(0).value, 0.0); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/notify/NotifyTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/notify/NotifyTest.java index 508dd1b70..afc2e2b35 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/notify/NotifyTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/notify/NotifyTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.notify; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NotifyTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/ByteBuddyProxyFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/ByteBuddyProxyFactoryTest.java index ee614b030..b6d79896d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/ByteBuddyProxyFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/ByteBuddyProxyFactoryTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.proxy.support; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import com.tencent.trpc.core.cluster.ClusterInvoker; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * ByteBuddyProxyFactory 测试类 @@ -32,4 +32,4 @@ public void testGetProxy() { assertNotNull(clusterInvokerProxy); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/JdkProxyFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/JdkProxyFactoryTest.java index ec171f582..2417a5d8b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/JdkProxyFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/proxy/support/JdkProxyFactoryTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.proxy.support; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import com.tencent.trpc.core.cluster.ClusterInvoker; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JdkProxyFactoryTest { @@ -29,4 +29,4 @@ public void testGetProxy() { assertNotNull(clusterInvokerProxy); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/registry/RegisterInfoTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/registry/RegisterInfoTest.java index 26689bda8..4dd01830f 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/registry/RegisterInfoTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/registry/RegisterInfoTest.java @@ -11,15 +11,15 @@ package com.tencent.trpc.core.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; 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; public class RegisterInfoTest { @@ -80,14 +80,14 @@ public void test() { assertEquals("proto://host:80/servicename", registerInfo.toIdentityString()); RegisterInfo registerInfoClone = new RegisterInfo("proto", "host", 80, "servicename", "group", "v1", map); - Assert.assertTrue(registerInfo.hashCode() > 0); + Assertions.assertTrue(registerInfo.hashCode() > 0); String[] strings = new String[]{"20"}; assertEquals(strings[0], registerInfo.getParameter("20", strings)[0]); assertEquals(registerInfo, registerInfoClone); registerInfo.compareTo(registerInfoClone); registerInfo.toString(); registerInfo.getIdentity(); - Assert.assertNotNull(registerInfo.clone()); + Assertions.assertNotNull(registerInfo.clone()); registerInfo.buildString(true, true, true, "a", "b"); assertEquals(80, registerInfo.getPort(10)); assertEquals(80, registerInfo.getPort(10)); @@ -110,7 +110,7 @@ public void testEncodeAndDecode() { "test.server1", "group", "v1", map); String url = RegisterInfo.encode(registerInfo); - Assert.assertEquals( + Assertions.assertEquals( "trpc%3A%2F%2F127.0.0.1%3A80%2Ftest.server1%3Fboolean%3Dfalse%26byte" + "%3D1%26double%3D1.0%26float%3D2.0%26int%3D1%26long%3D10%26short%3D1%26" + "string%3Dstring", diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcClientTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcClientTest.java index 31754af93..c7ce1f8d1 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcClientTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcClientTest.java @@ -11,20 +11,20 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ConsumerConfig; import com.tencent.trpc.core.common.config.ProtocolConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AbstractRpcClientTest { private AbstractRpcClient abstractRpcClient; - @Before + @BeforeEach public void setUp() throws Exception { abstractRpcClient = new AbstractRpcClient() { @Override @@ -83,4 +83,4 @@ public void testGetProtocolConfig() { public void testTestToString() { assertNotNull(abstractRpcClient.toString()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcServerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcServerTest.java index 55b1d8b7a..fe094c560 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcServerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/AbstractRpcServerTest.java @@ -11,16 +11,16 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.common.config.ProviderConfig; import com.tencent.trpc.core.rpc.def.DefProviderInvoker; import java.util.concurrent.CompletionStage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AbstractRpcServerTest { @@ -28,7 +28,7 @@ public class AbstractRpcServerTest { private ProtocolConfig protocolConfig; - @Before + @BeforeEach public void setUp() { abstractRpcServer = new AbstractRpcServer() { @Override @@ -105,4 +105,4 @@ public void testCloseFuture() { public void testGetProtocolConfig() { assertNotNull(abstractRpcServer.getProtocolConfig()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/CallInfoTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/CallInfoTest.java index ef6a3a971..d67920410 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/CallInfoTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/CallInfoTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.rpc; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CallInfoTest { @@ -31,31 +31,31 @@ public void test() { callInfo.setCallerService("callerservice"); callInfo.setCalleeContainerName("calleeContainerName"); callInfo.setCalleeSetName("calleeSetName"); - Assert.assertEquals("callee", callInfo.getCallee()); - Assert.assertEquals("calleeapp", callInfo.getCalleeApp()); - Assert.assertEquals("calleeserver", callInfo.getCalleeServer()); - Assert.assertEquals("calleemethod", callInfo.getCalleeMethod()); - Assert.assertEquals("calleeservice", callInfo.getCalleeService()); - Assert.assertEquals("caller", callInfo.getCaller()); - Assert.assertEquals("callerapp", callInfo.getCallerApp()); - Assert.assertEquals("callerserver", callInfo.getCallerServer()); - Assert.assertEquals("callermethod", callInfo.getCallerMethod()); - Assert.assertEquals("callerservice", callInfo.getCallerService()); - Assert.assertEquals("calleeContainerName", callInfo.getCalleeContainerName()); - Assert.assertEquals("calleeSetName", callInfo.getCalleeSetName()); + Assertions.assertEquals("callee", callInfo.getCallee()); + Assertions.assertEquals("calleeapp", callInfo.getCalleeApp()); + Assertions.assertEquals("calleeserver", callInfo.getCalleeServer()); + Assertions.assertEquals("calleemethod", callInfo.getCalleeMethod()); + Assertions.assertEquals("calleeservice", callInfo.getCalleeService()); + Assertions.assertEquals("caller", callInfo.getCaller()); + Assertions.assertEquals("callerapp", callInfo.getCallerApp()); + Assertions.assertEquals("callerserver", callInfo.getCallerServer()); + Assertions.assertEquals("callermethod", callInfo.getCallerMethod()); + Assertions.assertEquals("callerservice", callInfo.getCallerService()); + Assertions.assertEquals("calleeContainerName", callInfo.getCalleeContainerName()); + Assertions.assertEquals("calleeSetName", callInfo.getCalleeSetName()); CallInfo newCallInfo = callInfo.clone(); - Assert.assertEquals("callee", newCallInfo.getCallee()); - Assert.assertEquals("calleeapp", newCallInfo.getCalleeApp()); - Assert.assertEquals("calleeserver", newCallInfo.getCalleeServer()); - Assert.assertEquals("calleemethod", newCallInfo.getCalleeMethod()); - Assert.assertEquals("calleeservice", newCallInfo.getCalleeService()); - Assert.assertEquals("caller", newCallInfo.getCaller()); - Assert.assertEquals("callerapp", newCallInfo.getCallerApp()); - Assert.assertEquals("callerserver", newCallInfo.getCallerServer()); - Assert.assertEquals("callermethod", newCallInfo.getCallerMethod()); - Assert.assertEquals("callerservice", newCallInfo.getCallerService()); - Assert.assertEquals("calleeContainerName", callInfo.getCalleeContainerName()); - Assert.assertEquals("calleeSetName", callInfo.getCalleeSetName()); + Assertions.assertEquals("callee", newCallInfo.getCallee()); + Assertions.assertEquals("calleeapp", newCallInfo.getCalleeApp()); + Assertions.assertEquals("calleeserver", newCallInfo.getCalleeServer()); + Assertions.assertEquals("calleemethod", newCallInfo.getCalleeMethod()); + Assertions.assertEquals("calleeservice", newCallInfo.getCalleeService()); + Assertions.assertEquals("caller", newCallInfo.getCaller()); + Assertions.assertEquals("callerapp", newCallInfo.getCallerApp()); + Assertions.assertEquals("callerserver", newCallInfo.getCallerServer()); + Assertions.assertEquals("callermethod", newCallInfo.getCallerMethod()); + Assertions.assertEquals("callerservice", newCallInfo.getCallerService()); + Assertions.assertEquals("calleeContainerName", callInfo.getCalleeContainerName()); + Assertions.assertEquals("calleeSetName", callInfo.getCalleeSetName()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefRequestTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefRequestTest.java index 2e4177cc4..0bda8b566 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefRequestTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefRequestTest.java @@ -11,16 +11,16 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import com.google.common.collect.Maps; import com.tencent.trpc.core.logger.Logger; import com.tencent.trpc.core.logger.LoggerFactory; import com.tencent.trpc.core.rpc.def.DefRequest; import java.util.concurrent.ConcurrentMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DefRequestTest { @@ -41,9 +41,9 @@ public void test() { assertNull(request.getAttachment("aa")); assertNull(request.getAttachReqHead()); DefRequest defRequest = (DefRequest) request.clone(); - Assert.assertEquals(request.getAttachments().get("a"), + Assertions.assertEquals(request.getAttachments().get("a"), defRequest.getAttachments().get("a")); - Assert.assertEquals(request.getRequestId(), defRequest.getRequestId()); + Assertions.assertEquals(request.getRequestId(), defRequest.getRequestId()); RpcInvocation rpcInvocation = new RpcInvocation(); rpcInvocation.setRpcServiceName("/trpc.a"); rpcInvocation.setRpcMethodName("/b"); diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefResponseTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefResponseTest.java index 7a82310df..019fe775d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefResponseTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/DefResponseTest.java @@ -11,16 +11,16 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.google.common.collect.Maps; import com.tencent.trpc.core.rpc.def.DefRequest; import com.tencent.trpc.core.rpc.def.DefResponse; import java.util.concurrent.ConcurrentMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DefResponseTest { @@ -51,7 +51,7 @@ public void test() { assertNotNull(rsp.getMeta()); DefResponse defResponse = (DefResponse) rsp.clone(); - Assert.assertEquals(rsp.getAttachments().get("a"), defResponse.getAttachments().get("a")); - Assert.assertEquals(rsp.getException(), defResponse.getException()); + Assertions.assertEquals(rsp.getAttachments().get("a"), defResponse.getAttachments().get("a")); + Assertions.assertEquals(rsp.getException(), defResponse.getException()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/InvokeModeTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/InvokeModeTest.java index f9c17fee6..f5e885b52 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/InvokeModeTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/InvokeModeTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InvokeModeTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RequestMetaTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RequestMetaTest.java index 3584e8abc..4763186ab 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RequestMetaTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RequestMetaTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ConsumerConfig; import com.tencent.trpc.core.common.config.ProviderConfig; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RequestMetaTest { @@ -64,27 +64,27 @@ public void test() { meta.addMessageType(1); assertTrue(meta.hasMessageType(100)); RequestMeta copy = meta.clone(); - Assert.assertEquals(100, copy.getMessageType()); + Assertions.assertEquals(100, copy.getMessageType()); assertNotSame(copy, meta); assertEquals(copy.getDyeingKey(), "dyeingkey"); assertEquals(copy.getHashVal(), "hashval"); - Assert.assertEquals(cconfig, copy.getConsumerConfig()); - Assert.assertEquals(pconfig, copy.getProviderConfig()); - Assert.assertTrue(copy.getCreateTime() != 0 && copy.getCreateTime() > meta.getCreateTime()); + Assertions.assertEquals(cconfig, copy.getConsumerConfig()); + Assertions.assertEquals(pconfig, copy.getProviderConfig()); + Assertions.assertTrue(copy.getCreateTime() != 0 && copy.getCreateTime() > meta.getCreateTime()); assertNotSame(copy.getCallInfo(), meta.getCallInfo()); - Assert.assertEquals("callee", copy.getCallInfo().getCallee()); - Assert.assertEquals("calleeapp", copy.getCallInfo().getCalleeApp()); - Assert.assertEquals("calleeserver", copy.getCallInfo().getCalleeServer()); - Assert.assertEquals("calleemethod", copy.getCallInfo().getCalleeMethod()); - Assert.assertEquals("calleeservice", copy.getCallInfo().getCalleeService()); - Assert.assertEquals("caller", copy.getCallInfo().getCaller()); - Assert.assertEquals("callerapp", copy.getCallInfo().getCallerApp()); - Assert.assertEquals("callerserver", copy.getCallInfo().getCallerServer()); - Assert.assertEquals("callermethod", copy.getCallInfo().getCallerMethod()); - Assert.assertEquals("callerservice", copy.getCallInfo().getCallerService()); - Assert.assertEquals(pconfig, copy.getProviderConfig()); - Assert.assertEquals(cconfig, copy.getConsumerConfig()); - Assert.assertEquals("b", copy.getMap().get("a")); - Assert.assertTrue(copy.getMap() != meta.getMap()); + Assertions.assertEquals("callee", copy.getCallInfo().getCallee()); + Assertions.assertEquals("calleeapp", copy.getCallInfo().getCalleeApp()); + Assertions.assertEquals("calleeserver", copy.getCallInfo().getCalleeServer()); + Assertions.assertEquals("calleemethod", copy.getCallInfo().getCalleeMethod()); + Assertions.assertEquals("calleeservice", copy.getCallInfo().getCalleeService()); + Assertions.assertEquals("caller", copy.getCallInfo().getCaller()); + Assertions.assertEquals("callerapp", copy.getCallInfo().getCallerApp()); + Assertions.assertEquals("callerserver", copy.getCallInfo().getCallerServer()); + Assertions.assertEquals("callermethod", copy.getCallInfo().getCallerMethod()); + Assertions.assertEquals("callerservice", copy.getCallInfo().getCallerService()); + Assertions.assertEquals(pconfig, copy.getProviderConfig()); + Assertions.assertEquals(cconfig, copy.getConsumerConfig()); + Assertions.assertEquals("b", copy.getMap().get("a")); + Assertions.assertTrue(copy.getMap() != meta.getMap()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/ResponseMetaTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/ResponseMetaTest.java index 2f3614666..69eed28e3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/ResponseMetaTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/ResponseMetaTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.rpc; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ResponseMetaTest { @@ -24,9 +24,9 @@ public void test() { meta.getMap().put("a", "b"); meta.setSize(20); ResponseMeta copy = meta.clone(); - Assert.assertEquals(101, copy.getMessageType()); - Assert.assertEquals("b", copy.getMap().get("a")); - Assert.assertNotSame(copy.getMap(), meta.getMap()); - Assert.assertEquals(20, meta.getSize()); + Assertions.assertEquals(101, copy.getMessageType()); + Assertions.assertEquals("b", copy.getMap().get("a")); + Assertions.assertNotSame(copy.getMap(), meta.getMap()); + Assertions.assertEquals(20, meta.getSize()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextTest.java index 3c2f798b2..a00767cdf 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import java.util.concurrent.ConcurrentHashMap; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RpcContextTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextUtilsTest.java index b8fd9dff4..f2ec9ac69 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcContextUtilsTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.rpc.def.DefRequest; import com.tencent.trpc.core.rpc.def.DefResponse; @@ -19,7 +19,7 @@ import com.tencent.trpc.core.utils.Charsets; import com.tencent.trpc.core.utils.RpcContextUtils; import io.opentracing.noop.NoopSpan; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RpcContextUtilsTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcInvocationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcInvocationTest.java index d16503b15..0d4882923 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcInvocationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcInvocationTest.java @@ -13,8 +13,8 @@ import com.tencent.trpc.core.rpc.common.RpcMethodInfo; import com.tencent.trpc.core.utils.RpcUtilsTest.SimpleGenericClient; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Created by youngwwang on 2020/6/2. @@ -27,21 +27,21 @@ public void testIsGeneric() throws NoSuchMethodException { RpcInvocation invocation = new RpcInvocation(); invocation.setFirstArgument(new Object()); invocation.setFunc("/a/b"); - Assert.assertNotNull(invocation.getFirstArgument()); - Assert.assertNull(invocation.getInvokeMode()); - Assert.assertEquals("/a/b", invocation.getFunc()); - Assert.assertFalse(invocation.isGeneric()); + Assertions.assertNotNull(invocation.getFirstArgument()); + Assertions.assertNull(invocation.getInvokeMode()); + Assertions.assertEquals("/a/b", invocation.getFunc()); + Assertions.assertFalse(invocation.isGeneric()); invocation.setRpcMethodInfo( new RpcMethodInfo(Request.class, Request.class.getMethod("getRequestId"))); - Assert.assertFalse(invocation.isGeneric()); + Assertions.assertFalse(invocation.isGeneric()); invocation.setRpcMethodInfo(new RpcMethodInfo(SimpleGenericClient.class, SimpleGenericClient.class .getMethod("asyncInvoke", RpcClientContext.class, byte[].class))); - Assert.assertTrue(invocation.isGeneric()); + Assertions.assertTrue(invocation.isGeneric()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerContextTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerContextTest.java index 9e3167030..a4edab83c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerContextTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerContextTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import com.tencent.trpc.core.rpc.RpcServerContext.NewClientContextOptions; import com.tencent.trpc.core.utils.RpcContextUtils; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RpcServerContextTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java index 92a9f912a..70a68dbac 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java @@ -11,45 +11,39 @@ package com.tencent.trpc.core.rpc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.extension.ExtensionLoader; import com.tencent.trpc.core.rpc.spi.RpcServerFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.MockedStatic; +import org.mockito.Mockito; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ExtensionLoader.class}) +@ExtendWith(MockitoExtension.class) public class RpcServerMapTest { - @Before - public void init() { - PowerMockito.mockStatic(ExtensionLoader.class);// 3 - } - @Test public void test() { - ProtocolConfig config = new ProtocolConfig(); - config.setProtocol("trpc"); - ExtensionLoader extensionLoader = PowerMockito - .mock(ExtensionLoader.class); - PowerMockito.when(ExtensionLoader.getExtensionLoader(RpcServerFactory.class)) - .thenReturn(extensionLoader); - RpcServerFactory rpcServerFactory = PowerMockito.mock(RpcServerFactory.class); - PowerMockito.when(extensionLoader.getExtension("trpc")).thenReturn(rpcServerFactory); - RpcServer rpcServer = PowerMockito.mock(RpcServer.class); - PowerMockito.when(rpcServer.getProtocolConfig()).thenReturn(new ProtocolConfig()); - PowerMockito.when(rpcServerFactory.createRpcServer(config)).thenReturn(rpcServer); - assertEquals(RpcServerManager.getOrCreateRpcServer(config), rpcServer); - RpcServerManager.remove(config); - RpcServerManager.shutdown(); - RpcServerManager.reset(); - assertEquals(RpcServerManager.getOrCreateRpcServer(config), rpcServer); - RpcServerManager.shutdown(); + try (MockedStatic mockedStatic = Mockito.mockStatic(ExtensionLoader.class)) { + ProtocolConfig config = new ProtocolConfig(); + config.setProtocol("trpc"); + ExtensionLoader extensionLoader = Mockito.mock(ExtensionLoader.class); + mockedStatic.when(() -> ExtensionLoader.getExtensionLoader(RpcServerFactory.class)) + .thenReturn(extensionLoader); + RpcServerFactory rpcServerFactory = Mockito.mock(RpcServerFactory.class); + Mockito.when(extensionLoader.getExtension("trpc")).thenReturn(rpcServerFactory); + RpcServer rpcServer = Mockito.mock(RpcServer.class); + Mockito.when(rpcServer.getProtocolConfig()).thenReturn(new ProtocolConfig()); + Mockito.when(rpcServerFactory.createRpcServer(config)).thenReturn(rpcServer); + assertEquals(RpcServerManager.getOrCreateRpcServer(config), rpcServer); + RpcServerManager.remove(config); + RpcServerManager.shutdown(); + RpcServerManager.reset(); + assertEquals(RpcServerManager.getOrCreateRpcServer(config), rpcServer); + RpcServerManager.shutdown(); + } } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/TRpcProxyTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/TRpcProxyTest.java index 7c314879e..112269c04 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/TRpcProxyTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/TRpcProxyTest.java @@ -24,10 +24,10 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletionStage; -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; public class TRpcProxyTest { @@ -35,7 +35,7 @@ public class TRpcProxyTest { private static final String POLARIS_CLIENT_NAME = "polarisClient"; private static final String SET_NAME = "aa.bb.cc"; - @Before + @BeforeEach public void setUp() throws Exception { ConfigManager.stopTest(); ConfigManager.startTest(); @@ -47,45 +47,45 @@ public void setUp() throws Exception { .put("client", backendConfig); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @Test public void testGetProxy() { - Assert.assertNotNull(TRpcProxy.getProxy("client")); - Assert.assertNull(TRpcProxy.getProxy("client1")); + Assertions.assertNotNull(TRpcProxy.getProxy("client")); + Assertions.assertNull(TRpcProxy.getProxy("client1")); } @Test public void testGetProxyWithClass() { - Assert.assertNotNull(TRpcProxy.getProxy("client", GenericClient.class)); - Assert.assertNull(TRpcProxy.getProxy("client1", GenericClient.class)); + Assertions.assertNotNull(TRpcProxy.getProxy("client", GenericClient.class)); + Assertions.assertNull(TRpcProxy.getProxy("client1", GenericClient.class)); } @Test public void testGetProxyWithSourceSet() { - Assert.assertNotNull(TRpcProxy.getProxyWithSourceSet("client", SET_NAME)); - Assert.assertNull(TRpcProxy.getProxyWithSourceSet("client1", SET_NAME)); + Assertions.assertNotNull(TRpcProxy.getProxyWithSourceSet("client", SET_NAME)); + Assertions.assertNull(TRpcProxy.getProxyWithSourceSet("client1", SET_NAME)); } @Test public void testGetProxyWithSourceSetWithClass() { - Assert.assertNotNull(TRpcProxy.getProxyWithSourceSet("client", GenericClient.class, SET_NAME)); - Assert.assertNull(TRpcProxy.getProxyWithSourceSet("client1", GenericClient.class, SET_NAME)); + Assertions.assertNotNull(TRpcProxy.getProxyWithSourceSet("client", GenericClient.class, SET_NAME)); + Assertions.assertNull(TRpcProxy.getProxyWithSourceSet("client1", GenericClient.class, SET_NAME)); } @Test public void testGetProxyWithDestinationSet() { - Assert.assertNotNull(TRpcProxy.getProxyWithDestinationSet("client", SET_NAME)); - Assert.assertNull(TRpcProxy.getProxyWithDestinationSet("client1", SET_NAME)); + Assertions.assertNotNull(TRpcProxy.getProxyWithDestinationSet("client", SET_NAME)); + Assertions.assertNull(TRpcProxy.getProxyWithDestinationSet("client1", SET_NAME)); } @Test public void testGetProxyWithDestSet() { - Assert.assertNotNull(TRpcProxy.getProxyWithDestinationSet("client", GenericClient.class, SET_NAME)); - Assert.assertNull(TRpcProxy.getProxyWithDestinationSet("client1", GenericClient.class, SET_NAME)); + Assertions.assertNotNull(TRpcProxy.getProxyWithDestinationSet("client", GenericClient.class, SET_NAME)); + Assertions.assertNull(TRpcProxy.getProxyWithDestinationSet("client1", GenericClient.class, SET_NAME)); } @Test @@ -96,9 +96,9 @@ public void testAssembleDestinationSet() { backendConfig.setNamingUrl("assemble://test"); ConfigManager.getInstance().getClientConfig().getBackendConfigMap() .put(ASSEMBLE_CLIENT_NAME, backendConfig); - Assert.assertNotNull( + Assertions.assertNotNull( TRpcProxy.getProxyWithDestinationSet(ASSEMBLE_CLIENT_NAME, GenericClient.class, SET_NAME)); - Assert.assertEquals(SET_NAME, backendConfig.getExtMap().get(NamingOptions.DESTINATION_SET)); + Assertions.assertEquals(SET_NAME, backendConfig.getExtMap().get(NamingOptions.DESTINATION_SET)); } @Test @@ -127,14 +127,15 @@ public void report(ServiceInstance serviceInstance, int code, long costMs) throw } }; ExtensionLoader.getExtensionLoader(Selector.class).addExtension("polaris", simpleSelector.getClass()); - Assert.assertNotNull( + Assertions.assertNotNull( TRpcProxy.getProxyWithDestinationSet(POLARIS_CLIENT_NAME, GenericClient.class, SET_NAME)); Object metadataObj = Optional.ofNullable(backendConfig.getNamingMap()) .map(namingMap -> namingMap.get(Constants.METADATA)) .orElse(null); - Assert.assertTrue(metadataObj instanceof Map); + Assertions.assertTrue(metadataObj instanceof Map); Map metadata = (Map) metadataObj; - Assert.assertEquals(SET_NAME, metadata.get(Constants.POLARIS_PLUGIN_SET_NAME_KEY)); - Assert.assertEquals(Constants.POLARIS_PLUGIN_ENABLE_SET, metadata.get(Constants.POLARIS_PLUGIN_ENABLE_SET_KEY)); + Assertions.assertEquals(SET_NAME, metadata.get(Constants.POLARIS_PLUGIN_SET_NAME_KEY)); + Assertions.assertEquals(Constants.POLARIS_PLUGIN_ENABLE_SET, + metadata.get(Constants.POLARIS_PLUGIN_ENABLE_SET_KEY)); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/MethodRouterKeyTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/MethodRouterKeyTest.java index 525cf39ec..3f18e5c73 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/MethodRouterKeyTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/MethodRouterKeyTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.core.rpc.common; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MethodRouterKeyTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoAndInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoAndInvokerTest.java index a8e8dd694..62fc9411b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoAndInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoAndInvokerTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.rpc.common; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.tencent.trpc.core.rpc.GenericClient; import com.tencent.trpc.core.rpc.RpcClientContext; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RpcMethodInfoAndInvokerTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoTest.java index da938717d..c614ce495 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/common/RpcMethodInfoTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.rpc.common; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.RpcResult; import com.tencent.trpc.core.rpc.GenericClient; import com.tencent.trpc.core.rpc.InvokeMode; import com.tencent.trpc.core.rpc.RpcClientContext; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RpcMethodInfoTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DecodableValueTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DecodableValueTest.java index f3e3b0c89..fa8f1a123 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DecodableValueTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DecodableValueTest.java @@ -11,22 +11,22 @@ package com.tencent.trpc.core.rpc.def; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import com.tencent.trpc.core.compressor.CompressType; import com.tencent.trpc.core.serialization.SerializationType; import com.tencent.trpc.core.serialization.User; import com.tencent.trpc.core.utils.JsonUtils; import java.lang.reflect.Type; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DecodableValueTest { private DecodableValue decodableValue; - @Before + @BeforeEach public void setUp() { this.decodableValue = new DecodableValue(CompressType.NONE, SerializationType.JSON, null); } @@ -59,4 +59,4 @@ public void testGetSerializeType() { assertEquals(SerializationType.JSON, decodableValue.getSerializeType()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefMethodInfoRegisterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefMethodInfoRegisterTest.java index 33f0189cb..79adbb366 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefMethodInfoRegisterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefMethodInfoRegisterTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -18,8 +18,8 @@ import com.tencent.trpc.core.rpc.anno.TRpcMethod; import com.tencent.trpc.core.rpc.anno.TRpcService; import com.tencent.trpc.core.rpc.common.RpcMethodInfoAndInvoker; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Created by youngwwang on 2020/5/20. @@ -50,23 +50,25 @@ public void testRegister() { DEF_METHOD_INFO_REGISTER.register(INVOKER); RpcMethodInfoAndInvoker sayHello = DEF_METHOD_INFO_REGISTER .route("trpc.test.rpc.Hello", "sayHello"); - Assert.assertNotNull(sayHello); + Assertions.assertNotNull(sayHello); sayHello = DEF_METHOD_INFO_REGISTER.route("/trpc_test1_rpc/sayHello"); - Assert.assertNotNull(sayHello); - Assert.assertEquals(sayHello.getInvoker(), INVOKER); + Assertions.assertNotNull(sayHello); + Assertions.assertEquals(sayHello.getInvoker(), INVOKER); DEF_METHOD_INFO_REGISTER.unregister(INVOKER.getConfig()); sayHello = DEF_METHOD_INFO_REGISTER .route("trpc.test.rpc.Hello", "sayHello"); - Assert.assertNull(sayHello); + Assertions.assertNull(sayHello); DEF_METHOD_INFO_REGISTER.register(INVOKER_WITH_BASEPATH); RpcMethodInfoAndInvoker sayHelloWithBasePath = DEF_METHOD_INFO_REGISTER .route("trpc.test.rpc.Hello", "sayHello"); - Assert.assertEquals(sayHelloWithBasePath.getInvoker().getConfig().getServiceConfig().getBasePath(), "/hello"); - Assert.assertTrue(DEF_METHOD_INFO_REGISTER.validateNativeHttpPath("/hello")); - Assert.assertEquals(DEF_METHOD_INFO_REGISTER.getNativeHttpFunc("/hello"), "/hello"); - Assert.assertEquals(sayHelloWithBasePath.getMethodRouterKey().getSlashFunc(), "/trpc/test/rpc/Hello/sayHello"); + Assertions.assertEquals(sayHelloWithBasePath.getInvoker().getConfig().getServiceConfig().getBasePath(), + "/hello"); + Assertions.assertTrue(DEF_METHOD_INFO_REGISTER.validateNativeHttpPath("/hello")); + Assertions.assertEquals(DEF_METHOD_INFO_REGISTER.getNativeHttpFunc("/hello"), "/hello"); + Assertions.assertEquals(sayHelloWithBasePath.getMethodRouterKey().getSlashFunc(), + "/trpc/test/rpc/Hello/sayHello"); DEF_METHOD_INFO_REGISTER.unregister(INVOKER_WITH_BASEPATH.getConfig()); } @@ -75,11 +77,11 @@ public void testDefaultRegister() { DEF_METHOD_INFO_REGISTER.register(INVOKER); RpcMethodInfoAndInvoker defaultMethod = DEF_METHOD_INFO_REGISTER .getDefaultRouter("trpc.test.rpc.Hello"); - Assert.assertNotNull(defaultMethod); + Assertions.assertNotNull(defaultMethod); DEF_METHOD_INFO_REGISTER.unregister(INVOKER.getConfig()); defaultMethod = DEF_METHOD_INFO_REGISTER.getDefaultRouter("trpc.test.rpc.Hello"); - Assert.assertNull(defaultMethod); + Assertions.assertNull(defaultMethod); } @Test @@ -87,13 +89,13 @@ public void testClear() { DEF_METHOD_INFO_REGISTER.register(INVOKER); RpcMethodInfoAndInvoker sayHello = DEF_METHOD_INFO_REGISTER .route("trpc.test.rpc.Hello", "sayHello"); - Assert.assertNotNull(sayHello); + Assertions.assertNotNull(sayHello); DEF_METHOD_INFO_REGISTER.clear(); sayHello = DEF_METHOD_INFO_REGISTER .route("trpc.test.rpc.Hello", "sayHello"); - Assert.assertNull(sayHello); + Assertions.assertNull(sayHello); sayHello = DEF_METHOD_INFO_REGISTER.route("/trpc_test1_rpc/sayHello"); - Assert.assertNull(sayHello); + Assertions.assertNull(sayHello); } @@ -126,4 +128,4 @@ public String defaultMethod() { return "default"; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefProviderInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefProviderInvokerTest.java index 1dce0b45a..1fed3d71b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefProviderInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/DefProviderInvokerTest.java @@ -18,9 +18,9 @@ import com.tencent.trpc.core.common.config.ServiceConfig; import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.RpcInvocation; -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; public class DefProviderInvokerTest { @@ -28,7 +28,7 @@ public class DefProviderInvokerTest { private BlankRpcServiceName impl; - @Before + @BeforeEach public void setUp() { ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setIp("127.0.0.1"); @@ -57,22 +57,22 @@ public void testInvoke() { @Test public void testGetInterface() { - Assert.assertEquals(BlankRpcServiceName.class, providerInvoker.getInterface()); + Assertions.assertEquals(BlankRpcServiceName.class, providerInvoker.getInterface()); } @Test public void testGetProtocolConfig() { - Assert.assertEquals("127.0.0.1", providerInvoker.getProtocolConfig().getIp()); - Assert.assertEquals(12345, providerInvoker.getProtocolConfig().getPort()); + Assertions.assertEquals("127.0.0.1", providerInvoker.getProtocolConfig().getIp()); + Assertions.assertEquals(12345, providerInvoker.getProtocolConfig().getPort()); } @Test public void testGetImpl() { - Assert.assertEquals(impl, providerInvoker.getImpl()); + Assertions.assertEquals(impl, providerInvoker.getImpl()); } @Test public void testGetConfig() { - Assert.assertEquals(impl, providerInvoker.getConfig().getRef()); + Assertions.assertEquals(impl, providerInvoker.getConfig().getRef()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/EncodableValueTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/EncodableValueTest.java index 0121febd8..ae64bac86 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/EncodableValueTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/EncodableValueTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.rpc.def; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.tencent.trpc.core.compressor.spi.Compressor; import com.tencent.trpc.core.compressor.support.NoneCompressor; @@ -20,15 +20,15 @@ import com.tencent.trpc.core.serialization.User; import com.tencent.trpc.core.serialization.support.JSONSerialization; import com.tencent.trpc.core.utils.JsonUtils; -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; public class EncodableValueTest { private EncodableValue encodableValue; - @Before + @BeforeEach public void setUp() throws Exception { encodableValue = new EncodableValue(new NoneCompressor(), 20, new JSONSerialization(), false, null); @@ -50,12 +50,12 @@ public void testEncode() { @Test public void testGetRawValue() { - Assert.assertNull(encodableValue.getRawValue()); + Assertions.assertNull(encodableValue.getRawValue()); } @Test public void testGetCompressed() { - Assert.assertFalse(encodableValue.getCompressed()); + Assertions.assertFalse(encodableValue.getCompressed()); } @Test @@ -63,4 +63,4 @@ public void testGetCompressor() { Compressor compressor = encodableValue.getCompressor(); assertNotNull(compressor); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LeftTimeoutTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LeftTimeoutTest.java index 3dbf79a1b..1cb411862 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LeftTimeoutTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LeftTimeoutTest.java @@ -11,16 +11,16 @@ package com.tencent.trpc.core.rpc.def; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class LeftTimeoutTest { private LeftTimeout leftTimeout; - @Before + @BeforeEach public void setUp() throws Exception { leftTimeout = new LeftTimeout(2000, 100); } @@ -48,4 +48,4 @@ public void testSetLeftTimeout() { assertEquals(200, leftTimeout.getLeftTimeout()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LinkInvokeTimeoutTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LinkInvokeTimeoutTest.java index cf63481d7..1d16dd611 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LinkInvokeTimeoutTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/def/LinkInvokeTimeoutTest.java @@ -11,18 +11,18 @@ package com.tencent.trpc.core.rpc.def; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class LinkInvokeTimeoutTest { private LinkInvokeTimeout linkInvokeTimeout; - @Before + @BeforeEach public void setUp() throws Exception { linkInvokeTimeout = LinkInvokeTimeout.builder() .startTime(0) @@ -56,4 +56,4 @@ public void testIsServiceEnableLinkTimeout() { public void testTestToString() { assertNotNull(linkInvokeTimeout.toString()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractCircuitBreakerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractCircuitBreakerTest.java index b0d835755..9bddc60cf 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractCircuitBreakerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractCircuitBreakerTest.java @@ -12,7 +12,7 @@ package com.tencent.trpc.core.selector; import com.tencent.trpc.core.selector.circuitbreaker.AbstractCircuitBreaker; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AbstractCircuitBreakerTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractDiscoveryFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractDiscoveryFactoryTest.java index f47a6d8f2..562f0d122 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractDiscoveryFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractDiscoveryFactoryTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Lists; import com.tencent.trpc.core.selector.spi.Discovery; @@ -19,7 +19,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.Executor; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AbstractDiscoveryFactoryTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractLoadBalanceTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractLoadBalanceTest.java index 3b86da91c..d13c6b43c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractLoadBalanceTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/AbstractLoadBalanceTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import com.google.common.collect.Lists; import com.tencent.trpc.core.exception.TRpcException; @@ -21,7 +21,7 @@ import com.tencent.trpc.core.selector.loadbalance.AbstractLoadBalance; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AbstractLoadBalanceTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ClusterNamingTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ClusterNamingTest.java index 7910adef1..77800a98b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ClusterNamingTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ClusterNamingTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -18,10 +18,8 @@ import com.tencent.trpc.core.extension.ExtensionLoader; import com.tencent.trpc.core.rpc.Request; import com.tencent.trpc.core.rpc.RpcClientContext; -import com.tencent.trpc.core.selector.circuitbreaker.CircuitBreakerManager; import com.tencent.trpc.core.selector.discovery.DiscoveryManager; import com.tencent.trpc.core.selector.loadbalance.AbstractLoadBalance; -import com.tencent.trpc.core.selector.loadbalance.LoadBalanceManager; import com.tencent.trpc.core.selector.mock.MockDiscovery; import com.tencent.trpc.core.selector.spi.CircuitBreaker; import com.tencent.trpc.core.selector.spi.Discovery; @@ -36,22 +34,18 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicReference; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -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.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.Mockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * assemble selector Polaris Service Discovery Test */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({DiscoveryManager.class, LoadBalanceManager.class, CircuitBreakerManager.class}) -@PowerMockIgnore({"javax.management.*"}) +@ExtendWith(MockitoExtension.class) public class ClusterNamingTest { private static final String HOST_PREFIX = "127.0.0."; @@ -66,7 +60,7 @@ public class ClusterNamingTest { /** * 运行测试函数之前执行初始化 */ - @Before + @BeforeEach public void init() { ConfigManager.stopTest(); @@ -88,7 +82,7 @@ public void init() { ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -125,7 +119,7 @@ public void testOneFuture() { if (clusterNaming instanceof Lifecycle) { ((Lifecycle) clusterNaming).stop(); } - Assert.assertNull(errorRef.get()); + Assertions.assertNull(errorRef.get()); } @@ -147,7 +141,7 @@ public void testListFuture() { }); CompletableFuture.allOf(stage.toCompletableFuture()).join(); - Assert.assertNull(errorRef.get()); + Assertions.assertNull(errorRef.get()); } private void sleep(long milliMs) { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ListDiscoveryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ListDiscoveryTest.java index 8481a7b23..7ba903ce0 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ListDiscoveryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ListDiscoveryTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.selector.discovery.ListDiscovery; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ListDiscoveryTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/NoneCircuitBreakerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/NoneCircuitBreakerTest.java index 9a99ea48b..c11a5d0a0 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/NoneCircuitBreakerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/NoneCircuitBreakerTest.java @@ -11,12 +11,12 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.selector.circuitbreaker.support.NoneCircuitBreaker; import com.tencent.trpc.core.selector.spi.CircuitBreaker; import java.util.HashMap; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NoneCircuitBreakerTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/RandomLoadBalanceTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/RandomLoadBalanceTest.java index e9ad6ac8d..2428cfc23 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/RandomLoadBalanceTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/RandomLoadBalanceTest.java @@ -11,11 +11,11 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.Lists; import com.tencent.trpc.core.selector.loadbalance.support.RandomLoadBalance; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RandomLoadBalanceTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceIdTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceIdTest.java index a249b4a74..e16d3e5ef 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceIdTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceIdTest.java @@ -11,12 +11,12 @@ package com.tencent.trpc.core.selector; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ServiceIdTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceInstanceTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceInstanceTest.java index 6120dacdd..d22f2c532 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceInstanceTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/ServiceInstanceTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,11 +11,10 @@ package com.tencent.trpc.core.selector; - 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; public class ServiceInstanceTest { @@ -23,20 +22,20 @@ public class ServiceInstanceTest { public void test() { ServiceInstance serviceInstance = new ServiceInstance("127.0.0.1", 12000); ServiceInstance serviceInstance1 = new ServiceInstance("127.0.0.1", 12000); - Assert.assertEquals(serviceInstance, serviceInstance1); - Assert.assertNotNull(serviceInstance.hashCode()); - Assert.assertEquals(serviceInstance.toFullString(), serviceInstance1.toFullString()); + Assertions.assertEquals(serviceInstance, serviceInstance1); + Assertions.assertNotNull(serviceInstance.hashCode()); + Assertions.assertEquals(serviceInstance.toFullString(), serviceInstance1.toFullString()); - Assert.assertNull(serviceInstance.getObject("a")); - Assert.assertNull(serviceInstance.getParameter("a")); - Assert.assertTrue(serviceInstance.getParameters().isEmpty()); + Assertions.assertNull(serviceInstance.getObject("a")); + Assertions.assertNull(serviceInstance.getParameter("a")); + Assertions.assertTrue(serviceInstance.getParameters().isEmpty()); serviceInstance = new ServiceInstance("127.0.0.1", 12000, false); serviceInstance1 = new ServiceInstance("127.0.0.1", 12000, false); - Assert.assertEquals(serviceInstance, serviceInstance1); + Assertions.assertEquals(serviceInstance, serviceInstance1); serviceInstance = new ServiceInstance("127.0.0.1", 12000, true); serviceInstance1 = new ServiceInstance("127.0.0.1", 12000, false); - Assert.assertNotEquals(serviceInstance, serviceInstance1); + Assertions.assertNotEquals(serviceInstance, serviceInstance1); Map map = new HashMap(); map.put("int", 1); @@ -60,15 +59,15 @@ public void test() { serviceInstance = new ServiceInstance("127.0.0.1", 12000, map); serviceInstance1 = new ServiceInstance("127.0.0.1", 12000, map1); - Assert.assertEquals(serviceInstance, serviceInstance1); + Assertions.assertEquals(serviceInstance, serviceInstance1); serviceInstance = new ServiceInstance("127.0.0.1", 12000, true, map); serviceInstance1 = new ServiceInstance("127.0.0.1", 12000, true, map1); - Assert.assertEquals(serviceInstance, serviceInstance1); + Assertions.assertEquals(serviceInstance, serviceInstance1); serviceInstance = new ServiceInstance("127.0.0.1", 12000, true, map); serviceInstance1 = new ServiceInstance("127.0.0.1", 12000, false, map1); - Assert.assertNotEquals(serviceInstance, serviceInstance1); + Assertions.assertNotEquals(serviceInstance, serviceInstance1); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/def/AssembleSelectorConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/def/AssembleSelectorConfigTest.java index 9fdb0b3bf..74d2f8736 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/def/AssembleSelectorConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/def/AssembleSelectorConfigTest.java @@ -11,15 +11,15 @@ package com.tencent.trpc.core.selector.support.def; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.config.PluginConfig; import com.tencent.trpc.core.extension.MockSelector; import com.tencent.trpc.core.selector.spi.Selector; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AssembleSelectorConfigTest { @@ -27,7 +27,7 @@ public class AssembleSelectorConfigTest { private PluginConfig pluginConfig; - @Before + @BeforeEach public void setUp() throws Exception { Map config = new HashMap<>(); config.put("discovery", "discovery"); @@ -109,4 +109,4 @@ public void testGetMethodLoadBalance() { assertEquals("loadBalance", assembleSelectorConfig.getMethodLoadBalance("1")); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/ip/IpSelectorTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/ip/IpSelectorTest.java index facb00563..679a8bb10 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/ip/IpSelectorTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/selector/support/ip/IpSelectorTest.java @@ -13,21 +13,16 @@ import com.tencent.trpc.core.rpc.def.DefRequest; import com.tencent.trpc.core.selector.ServiceId; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class IpSelectorTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - private IpSelector ipSelector; private ServiceId serviceId; - @Before + @BeforeEach public void setUp() { this.ipSelector = new IpSelector(); ipSelector.init(); @@ -66,4 +61,4 @@ public void testSelectAll() { public void testReport() { ipSelector.report(null, 0, 0); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JavaPbSerializationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JavaPbSerializationTest.java index 9e2edaaae..29f34bc4a 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JavaPbSerializationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JavaPbSerializationTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.serialization; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import com.baidu.bjf.remoting.protobuf.Codec; import com.tencent.trpc.core.serialization.support.JavaPBSerialization; @@ -24,8 +24,8 @@ import java.util.Map; import org.apache.commons.collections4.MapUtils; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JavaPbSerializationTest { @@ -42,13 +42,13 @@ public void test() { byte[] javaPBBytes = javaPBSerialization.serialize(user); System.out.println("javapb bytes:" + Arrays.toString(javaPBBytes)); User user1 = javaPBSerialization.deserialize(javaPBBytes, User.class); - Assert.assertEquals(user.toString(), user1.toString()); + Assertions.assertEquals(user.toString(), user1.toString()); PBSerialization pbSerialization = new PBSerialization(); try { User user2 = pbSerialization.deserialize(javaPBBytes, User.class); - Assert.assertEquals(user.toString(), user2.toString()); + Assertions.assertEquals(user.toString(), user2.toString()); } catch (IOException ioException) { - Assert.fail(); + Assertions.fail(); } } @@ -75,32 +75,36 @@ public void testExtend() { try { byte[] b = javaPBSerialization.serialize(userExtend); UserExtend userExtend1 = javaPBSerialization.deserialize(b, UserExtend.class); - Assert.assertEquals(Arrays.toString(userExtend.getArr()), Arrays.toString(userExtend1.getArr())); - Assert.assertEquals(userExtend.getId(), userExtend1.getId()); - Assert.assertNull(userExtend1.getDesc()); - Assert.assertNull(userExtend1.getName()); - Assert.assertTrue(MapUtils.isEmpty(userExtend1.getMembers())); + Assertions.assertEquals(Arrays.toString(userExtend.getArr()), Arrays.toString(userExtend1.getArr())); + Assertions.assertEquals(userExtend.getId(), userExtend1.getId()); + Assertions.assertNull(userExtend1.getDesc()); + Assertions.assertNull(userExtend1.getName()); + Assertions.assertTrue(MapUtils.isEmpty(userExtend1.getMembers())); UserExtend userExtend2 = pbSerialization.deserialize(b, UserExtend.class); - Assert.assertEquals(Arrays.toString(userExtend.getArr()), Arrays.toString(userExtend2.getArr())); - Assert.assertEquals(userExtend.getId(), userExtend2.getId()); - Assert.assertNull(userExtend2.getDesc()); - Assert.assertNull(userExtend2.getName()); - Assert.assertTrue(MapUtils.isEmpty(userExtend2.getMembers())); + Assertions.assertEquals(Arrays.toString(userExtend.getArr()), Arrays.toString(userExtend2.getArr())); + Assertions.assertEquals(userExtend.getId(), userExtend2.getId()); + Assertions.assertNull(userExtend2.getDesc()); + Assertions.assertNull(userExtend2.getName()); + Assertions.assertTrue(MapUtils.isEmpty(userExtend2.getMembers())); } catch (Exception e) { - Assert.fail(); + Assertions.fail(); } } - @Test(expected = RuntimeException.class) + @Test public void testException1() { - JavaPBSerialization javaPBSerialization = new JavaPBSerialization(); - javaPBSerialization.serialize(Object.class); + Assertions.assertThrows(RuntimeException.class, () -> { + JavaPBSerialization javaPBSerialization = new JavaPBSerialization(); + javaPBSerialization.serialize(Object.class); + }); } - @Test(expected = RuntimeException.class) + @Test public void testException2() { - JavaPBSerialization javaPBSerialization = new JavaPBSerialization(); - javaPBSerialization.deserialize(new byte[0], Object.class); + Assertions.assertThrows(RuntimeException.class, () -> { + JavaPBSerialization javaPBSerialization = new JavaPBSerialization(); + javaPBSerialization.deserialize(new byte[0], Object.class); + }); } @Test @@ -115,4 +119,4 @@ public void test1() { Codec codec1 = ProtoCodecManager.getCodec(User.class); assertSame(codec, codec1); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JsonSerializationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JsonSerializationTest.java index 1de3c3176..67f4d6237 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JsonSerializationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/JsonSerializationTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -11,19 +11,18 @@ package com.tencent.trpc.core.serialization; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.trpc.core.serialization.support.JSONSerialization; import com.tencent.trpc.core.utils.HelloRequestProtocol.HelloRequest; import com.tencent.trpc.core.utils.JsonUtils; -import com.tencent.trpc.core.utils.JsonUtilsTest; import java.io.IOException; import java.util.List; import org.assertj.core.util.Lists; -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; public class JsonSerializationTest { @@ -33,7 +32,7 @@ public class JsonSerializationTest { private Obj obj; - @Before + @BeforeEach public void setUp() { serial = new JSONSerialization(); genericsObj = new GenericsObj<>(); @@ -64,17 +63,17 @@ public void testJson2PojoEx() { try { byte[] bytes = serial.serialize(obj); GenericsObj deserialize = serial.deserialize(bytes, GenericsObj.class); - Assert.assertNull(deserialize.getData()); + Assertions.assertNull(deserialize.getData()); } catch (IOException ioe) { - Assert.assertTrue(ioe.getMessage().contains("json deserialize exception:")); + Assertions.assertTrue(ioe.getMessage().contains("json deserialize exception:")); } try { byte[] bytes = serial.serialize(obj); TestObj1 deserialize = serial.deserialize(bytes, new TypeReference() { }.getType()); - Assert.assertEquals(0, deserialize.test); + Assertions.assertEquals(0, deserialize.test); } catch (IOException ioe) { - Assert.assertTrue(ioe.getMessage().contains("json deserialize exception:")); + Assertions.assertTrue(ioe.getMessage().contains("json deserialize exception:")); } } @@ -120,7 +119,8 @@ public void testJson2PojoByTypeReference() throws IOException { testObjList.setData(objs); byte[] serializeList = serial.serialize(testObjList); GenericsObj> deserializeList = - serial.deserialize(serializeList, new TypeReference>>() {}.getType()); + serial.deserialize(serializeList, new TypeReference>>() { + }.getType()); assertEquals(20, deserializeList.getIntField()); assertEquals("a", deserializeList.getData().get(0).getName()); byte[] bytes = serial.serialize(obj); @@ -196,4 +196,4 @@ public void setTest(int test) { this.test = test; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/PBSerializationTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/PBSerializationTest.java index b0ad908fc..d7e6cea85 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/PBSerializationTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/PBSerializationTest.java @@ -20,8 +20,8 @@ import com.tencent.trpc.core.utils.HelloRequestProtocol; import com.tencent.trpc.core.utils.HelloRequestProtocol.HelloRequest; import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PBSerializationTest { @@ -42,14 +42,14 @@ public void testPBSerialize() throws IOException { .build(); byte[] serialBytes = serial.serialize(request); HelloRequest deserialize = serial.deserialize(serialBytes, HelloRequest.class); - Assert.assertEquals(request.getIntField(), deserialize.getIntField()); - Assert.assertEquals(request.getStringField(), deserialize.getStringField()); - Assert.assertEquals(request.getBooleanField(), deserialize.getBooleanField()); - Assert.assertEquals(request.getLongField(), deserialize.getLongField()); - Assert.assertEquals(request.getByteStringField(), deserialize.getByteStringField()); - Assert.assertEquals(request.getOther().getIntField(), deserialize.getOther().getIntField()); - Assert.assertEquals(serial.name(), PBSerialization.NAME); - Assert.assertEquals(serial.type(), SerializationType.PB); + Assertions.assertEquals(request.getIntField(), deserialize.getIntField()); + Assertions.assertEquals(request.getStringField(), deserialize.getStringField()); + Assertions.assertEquals(request.getBooleanField(), deserialize.getBooleanField()); + Assertions.assertEquals(request.getLongField(), deserialize.getLongField()); + Assertions.assertEquals(request.getByteStringField(), deserialize.getByteStringField()); + Assertions.assertEquals(request.getOther().getIntField(), deserialize.getOther().getIntField()); + Assertions.assertEquals(serial.name(), PBSerialization.NAME); + Assertions.assertEquals(serial.type(), SerializationType.PB); PBSerializationTest.TestObj testObj = new PBSerializationTest.TestObj(); testObj.setIntField(10); testObj.setStringField("string"); @@ -71,11 +71,11 @@ public void testPBSerialize() throws IOException { JavaPBSerialization javaPBSerialization = new JavaPBSerialization(); byte[] serialize = javaPBSerialization.serialize(testObj); HelloRequest helloRequest = HelloRequest.parseFrom(serialize); - Assert.assertEquals(10, helloRequest.getIntField()); - Assert.assertEquals("string", helloRequest.getStringField()); - Assert.assertFalse(helloRequest.getBooleanField()); - Assert.assertEquals(200L, helloRequest.getLongField()); - Assert.assertEquals(1, helloRequest.getOther().getIntField()); + Assertions.assertEquals(10, helloRequest.getIntField()); + Assertions.assertEquals("string", helloRequest.getStringField()); + Assertions.assertFalse(helloRequest.getBooleanField()); + Assertions.assertEquals(200L, helloRequest.getLongField()); + Assertions.assertEquals(1, helloRequest.getOther().getIntField()); } public static class TestObj { @@ -166,4 +166,4 @@ public void setIntField(Integer intField) { this.intField = intField; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/SerializationSupportTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/SerializationSupportTest.java index 7342c2093..7e9d7a102 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/serialization/SerializationSupportTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/serialization/SerializationSupportTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.serialization; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SerializationSupportTest { @@ -24,4 +24,4 @@ public void test() { assertEquals(SerializationType.PB, SerializationSupport.ofName("pb").type()); assertSame("pb", SerializationSupport.ofType(SerializationType.PB).name()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/sign/SignSupportTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/sign/SignSupportTest.java index c8f9eeeb2..c8d072e4d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/sign/SignSupportTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/sign/SignSupportTest.java @@ -12,29 +12,29 @@ package com.tencent.trpc.core.sign; import com.tencent.trpc.core.sign.spi.Sign; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SignSupportTest { @Test public void testOfName() { Sign sign = SignSupport.ofName("test"); - Assert.assertNotNull(sign); - Assert.assertNull(SignSupport.ofName("test1")); + Assertions.assertNotNull(sign); + Assertions.assertNull(SignSupport.ofName("test1")); } @Test public void testIsVerify() { - Assert.assertFalse(SignSupport.isVerify("test", null)); - Assert.assertFalse(SignSupport.isVerify(null, new byte[0])); - Assert.assertTrue(SignSupport.isVerify("test", new byte[0])); + Assertions.assertFalse(SignSupport.isVerify("test", null)); + Assertions.assertFalse(SignSupport.isVerify(null, new byte[0])); + Assertions.assertTrue(SignSupport.isVerify("test", new byte[0])); } @Test public void testIsNotVerify() { - Assert.assertTrue(SignSupport.isNotVerify("test", null)); - Assert.assertTrue(SignSupport.isNotVerify("", new byte[0])); - Assert.assertFalse(SignSupport.isNotVerify("test", new byte[0])); + Assertions.assertTrue(SignSupport.isNotVerify("test", null)); + Assertions.assertTrue(SignSupport.isNotVerify("", new byte[0])); + Assertions.assertFalse(SignSupport.isNotVerify("test", new byte[0])); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/stat/metrics/MetricStatFactoryTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/stat/metrics/MetricStatFactoryTest.java index 0b9ab8ea4..997cfc949 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/stat/metrics/MetricStatFactoryTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/stat/metrics/MetricStatFactoryTest.java @@ -28,7 +28,7 @@ import com.tencent.trpc.core.stat.spi.Stat; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetricStatFactoryTest { @@ -98,4 +98,4 @@ public void stat() { new double[]{1.0}, "testlabelname4").record(1, "testlabelval4"); } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/stream/StreamCallTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/stream/StreamCallTest.java index 7e9c986e2..1e6abb18b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/stream/StreamCallTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/stream/StreamCallTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -13,10 +13,10 @@ import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.RpcContext; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.reactivestreams.Publisher; import reactor.core.CoreSubscriber; import reactor.core.publisher.Flux; @@ -31,9 +31,9 @@ public class StreamCallTest { /** * Init streamCall & receiverFlux */ - @Before + @BeforeEach public void setUp() { - streamCall = PowerMockito.spy(new StreamCall() { + streamCall = Mockito.spy(new StreamCall() { @Override public Flux serverStream(RpcContext ctx, ReqT request) { @@ -78,27 +78,27 @@ public void subscribe(CoreSubscriber coreSubscriber) { public void testServerStream() { RpcContext ctx = new RpcClientContext(); Publisher resp = streamCall.serverStream(ctx, receiverFlux); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test public void testClientStream() { RpcContext ctx = new RpcClientContext(); Publisher resp = streamCall.clientStream(ctx, receiverFlux); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test public void testDuplexStream() { RpcContext ctx = new RpcClientContext(); Publisher resp = streamCall.duplexStream(ctx, receiverFlux); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test public void testOnClose() { Mono resp = streamCall.onClose(); - Assert.assertNotNull(resp); + Assertions.assertNotNull(resp); } @Test @@ -108,7 +108,7 @@ public void testDispose() { @Test public void testIsDisposed() { - Assert.assertFalse(streamCall.isDisposed()); + Assertions.assertFalse(streamCall.isDisposed()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/telemetry/SpanContextTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/telemetry/SpanContextTest.java index 8b1aac6c0..3714c3c2d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/telemetry/SpanContextTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/telemetry/SpanContextTest.java @@ -11,10 +11,12 @@ package com.tencent.trpc.core.telemetry; -import junit.framework.TestCase; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -public class SpanContextTest extends TestCase { +import org.junit.jupiter.api.Test; + +public class SpanContextTest { @Test public void testInvalidContext() { @@ -22,4 +24,4 @@ public void testInvalidContext() { assertEquals(SpanContext.INVALID.getSpanId(), SpanContext.INVALID_SPAN_ID); assertFalse(SpanContext.INVALID.isSampled()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceClientFilterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceClientFilterTest.java index 958c0c643..f2fc63c0a 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceClientFilterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceClientFilterTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -42,8 +42,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.CompletableFuture; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class TraceClientFilterTest { @@ -165,8 +165,8 @@ public void testNormalSpan() { CompletableFuture future = new CompletableFuture(); Response rsp = new DefResponse(); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } @@ -187,8 +187,8 @@ public void testExceptionSpan() { Response rsp = new DefResponse(); rsp.setException(new IllegalArgumentException("")); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } @@ -209,8 +209,8 @@ public void testTRpcExceptionSpan() { Response rsp = new DefResponse(); rsp.setException(TRpcException.newBizException(10, "")); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceServerFilterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceServerFilterTest.java index 31c7000fb..9afff8692 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceServerFilterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/trace/TraceServerFilterTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -44,16 +44,14 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.CompletableFuture; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PowerMockIgnore({"javax.management.*"}) +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.Mockito; + +@ExtendWith(MockitoExtension.class) public class TraceServerFilterTest { private TracerServerFilter filter = new TracerServerFilter() { @@ -159,12 +157,12 @@ public Map inject(Tracer tracer, Span span) { } }; - @Before + @BeforeEach public void before() { TracerFactoryManager.getManager().registPlugin("mtest", TestTraceFactory.class); } - @After + @AfterEach public void after() { ExtensionLoader.destroyAllPlugin(); } @@ -186,8 +184,8 @@ public void testNormalSpan() { CompletableFuture future = new CompletableFuture(); Response rsp = new DefResponse(); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } @@ -208,8 +206,8 @@ public void testExceptionSpan() { Response rsp = new DefResponse(); rsp.setException(new IllegalArgumentException("")); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } @@ -230,8 +228,8 @@ public void testTRpcExceptionSpan() { Response rsp = new DefResponse(); rsp.setException(TRpcException.newBizException(10, "")); future.complete(rsp); - Invoker invoker = (Invoker) PowerMockito.mock(Invoker.class); - PowerMockito.when(invoker.invoke(request)).thenReturn(future); + Invoker invoker = (Invoker) Mockito.mock(Invoker.class); + Mockito.when(invoker.invoke(request)).thenReturn(future); filter.filter(invoker, request); } @@ -242,4 +240,4 @@ public Tracer getTracer(String serverName, Integer port) { return NoopTracerFactory.create(); } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractClientTransportTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractClientTransportTest.java index 3d644b8ed..9a3e920cf 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractClientTransportTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractClientTransportTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.transport; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.exception.TransportException; import com.tencent.trpc.core.transport.codec.ClientCodec; import java.util.Set; import java.util.concurrent.CompletableFuture; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AbstractClientTransportTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractServerTransportTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractServerTransportTest.java index ab351be93..1aefcbb2c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractServerTransportTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/AbstractServerTransportTest.java @@ -11,13 +11,13 @@ package com.tencent.trpc.core.transport; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.exception.TransportException; import com.tencent.trpc.core.transport.codec.ServerCodec; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AbstractServerTransportTest { @@ -81,4 +81,4 @@ protected void doClose() { } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/ClientTransportTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/ClientTransportTest.java index 0ed698dbf..7583b3784 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/ClientTransportTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/ClientTransportTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.transport; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.transport.common.TestClientCodec; @@ -23,8 +23,8 @@ import java.net.InetSocketAddress; import java.util.Set; import java.util.concurrent.CompletionStage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClientTransportTest { @@ -38,7 +38,7 @@ public class ClientTransportTest { private ClientTransport clientNotPool; - @Before + @BeforeEach public void before() throws Exception { clientTransport = newClientTransport(HOST, PORT, Boolean.TRUE); clientNotPool = newClientTransport(HOST, PORT, Boolean.FALSE); @@ -119,4 +119,4 @@ public void testClientTransportStop() { this.clientTransport.close(); assertTrue(clientTransport.isClosed()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/codec/AbstractCodecTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/codec/AbstractCodecTest.java index 55a8e74b4..70e30ba60 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/codec/AbstractCodecTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/codec/AbstractCodecTest.java @@ -18,15 +18,15 @@ import com.tencent.trpc.core.sign.SignSupport; import com.tencent.trpc.core.transport.Channel; -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; public class AbstractCodecTest { private AbstractCodec abstractCodec; - @Before + @BeforeEach public void setUp() { SerializationSupport.preLoadSerialization(); CompressorSupport.preLoadCompressors(); @@ -46,18 +46,18 @@ public Object decode(Channel channel, ChannelBuffer channelBuffer) { @Test public void testCheckAndGetSerialization() { - Assert.assertNotNull(abstractCodec.checkAndGetSerialization("json")); - Assert.assertNotNull(abstractCodec.checkAndGetSerialization(new JSONSerialization().type())); + Assertions.assertNotNull(abstractCodec.checkAndGetSerialization("json")); + Assertions.assertNotNull(abstractCodec.checkAndGetSerialization(new JSONSerialization().type())); } @Test public void testCheckAndGetCompressor() { - Assert.assertNotNull(abstractCodec.checkAndGetCompressor("gzip")); + Assertions.assertNotNull(abstractCodec.checkAndGetCompressor("gzip")); } @Test public void testGetEncodableValue() { - Assert.assertNotNull(abstractCodec.getEncodableValue(10, new JSONSerialization(), + Assertions.assertNotNull(abstractCodec.getEncodableValue(10, new JSONSerialization(), new SnappyCompressor(), false, null)); } @@ -66,4 +66,4 @@ public void testGetContentEncoding() { abstractCodec.getContentEncoding(abstractCodec.getEncodableValue(10, new JSONSerialization(), new SnappyCompressor(), false, null)); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AbstractClientChannelHandlerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AbstractClientChannelHandlerTest.java index 6e54c67e7..cf7f851cb 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AbstractClientChannelHandlerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AbstractClientChannelHandlerTest.java @@ -11,14 +11,14 @@ package com.tencent.trpc.core.transport.handler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AbstractClientChannelHandlerTest { @Test public void testCreate() { AbstractClientChannelHandler clientChannelHandler = new AbstractClientChannelHandler(null, null); - Assert.assertNotNull(clientChannelHandler); + Assertions.assertNotNull(clientChannelHandler); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AcceptLimitHandlerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AcceptLimitHandlerTest.java index f43f9f034..42b788c0d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AcceptLimitHandlerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/transport/handler/AcceptLimitHandlerTest.java @@ -18,8 +18,8 @@ import com.tencent.trpc.core.transport.impl.TestServerTransport; import java.net.InetSocketAddress; import java.util.concurrent.CompletionStage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AcceptLimitHandlerTest { @@ -30,7 +30,7 @@ public class AcceptLimitHandlerTest { /** * Init AcceptLimitHandler & channel */ - @Before + @BeforeEach public void setUp() { ProtocolConfig config = new ProtocolConfig(); config.setIp("localhost"); diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/BinderUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/BinderUtilsTest.java index b94ea2fd0..54da6dc8e 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/BinderUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/BinderUtilsTest.java @@ -19,9 +19,9 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -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; public class BinderUtilsTest { @@ -30,7 +30,7 @@ public class BinderUtilsTest { private Map valueMap; private BinderObj obj = new BinderObj(); - @Before + @BeforeEach public void setUp() { valueMap = new HashMap<>(); valueMap.put("firstName", "young"); @@ -40,18 +40,18 @@ public void setUp() { @Test public void testUnderscoresToUpperCase() { - Assert.assertEquals(BinderUtils.underscoresToUpperCase("a_bi_cd"), "aBiCd"); + Assertions.assertEquals(BinderUtils.underscoresToUpperCase("a_bi_cd"), "aBiCd"); } @Test public void testUpperCaseToUnderscores() { - Assert.assertEquals("a_bi_cd", BinderUtils.upperCaseToUnderscores("aBiCd")); + Assertions.assertEquals("a_bi_cd", BinderUtils.upperCaseToUnderscores("aBiCd")); } @Test public void testNewFunction() { - Assert.assertEquals(BinderUtils.newFunction("a").apply("b"), "a"); + Assertions.assertEquals(BinderUtils.newFunction("a").apply("b"), "a"); } @Test @@ -59,9 +59,9 @@ public void testBind() { BinderUtils.bind(Function.identity(), obj, valueMap, "firstName", Function.identity()); BinderUtils.bind(Function.identity(), obj, valueMap, "age", Function.identity()); BinderUtils.bind(Function.identity(), obj, valueMap, "money", Function.identity()); - Assert.assertEquals("young", obj.getFirstName()); - Assert.assertEquals(12, obj.getAge()); - Assert.assertEquals(15, obj.getMoney().intValue()); + Assertions.assertEquals("young", obj.getFirstName()); + Assertions.assertEquals(12, obj.getAge()); + Assertions.assertEquals(15, obj.getMoney().intValue()); } @Test @@ -69,8 +69,8 @@ public void testBind1() { valueMap.put("first_name", "hello"); BinderUtils.bind("age", obj, valueMap, "age", Function.identity()); BinderUtils.bind("firstName", obj, valueMap, "first_name", Function.identity()); - Assert.assertEquals("hello", obj.getFirstName()); - Assert.assertEquals(12, obj.getAge()); + Assertions.assertEquals("hello", obj.getFirstName()); + Assertions.assertEquals(12, obj.getAge()); } @@ -78,39 +78,39 @@ public void testBind1() { public void testTestBind3() { valueMap.put("age2", 14); BinderUtils.bind("age", obj, valueMap, "age2"); - Assert.assertEquals(14, obj.getAge()); + Assertions.assertEquals(14, obj.getAge()); } @Test public void testTestBind4() { valueMap.put("age", 16); BinderUtils.bind(obj, valueMap); - Assert.assertEquals(16, obj.getAge()); + Assertions.assertEquals(16, obj.getAge()); } @Test public void testTestBind6() { BinderUtils.bind(obj, "age", 20, Function.identity()); BinderUtils.bind(obj, "first_name", "hello1", BinderUtils.UNDERSCORES_TO_UPPERCASE); - Assert.assertEquals(20, obj.getAge()); - Assert.assertEquals("hello1", obj.getFirstName()); + Assertions.assertEquals(20, obj.getAge()); + Assertions.assertEquals("hello1", obj.getFirstName()); } @Test public void testBind7() { BinderUtils.bind(obj, "age", 20); BinderUtils.bind(obj, "first_name", "a"); - Assert.assertEquals(20, obj.getAge()); - Assert.assertEquals("a", obj.getFirstName()); + Assertions.assertEquals(20, obj.getAge()); + Assertions.assertEquals("a", obj.getFirstName()); } @Test public void testBind8() { BinderObj binderObj = new BinderObj(); BinderUtils.bind(binderObj); - Assert.assertEquals(20, binderObj.getAge()); - Assert.assertEquals(15, binderObj.getMoney().intValue()); - Assert.assertNull(binderObj.getFirstName()); + Assertions.assertEquals(20, binderObj.getAge()); + Assertions.assertEquals(15, binderObj.getMoney().intValue()); + Assertions.assertNull(binderObj.getFirstName()); } @Test @@ -118,31 +118,31 @@ public void testMergeList() { BinderObj targetObj = new BinderObj(); BinderObj sourceObj = new BinderObj(); BinderUtils.merge(targetObj, sourceObj); - Assert.assertNull(targetObj.getFriends()); - Assert.assertNull(sourceObj.getFriends()); + Assertions.assertNull(targetObj.getFriends()); + Assertions.assertNull(sourceObj.getFriends()); List targetFriends = Lists.newArrayList("obama"); List sourceFriends = Lists.newArrayList("harry"); - Assert.assertEquals(1, targetFriends.size()); - Assert.assertEquals(1, sourceFriends.size()); + Assertions.assertEquals(1, targetFriends.size()); + Assertions.assertEquals(1, sourceFriends.size()); targetObj.setFriends(targetFriends); sourceObj.setFriends(null); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getFriends().size(), 1); - Assert.assertNull(sourceObj.getFriends()); - Assert.assertEquals(targetObj.getFriends().get(0), "obama"); + Assertions.assertEquals(targetObj.getFriends().size(), 1); + Assertions.assertNull(sourceObj.getFriends()); + Assertions.assertEquals(targetObj.getFriends().get(0), "obama"); targetObj.setFriends(null); sourceObj.setFriends(sourceFriends); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getFriends().size(), 1); - Assert.assertEquals(sourceObj.getFriends().size(), 1); - Assert.assertEquals(targetObj.getFriends().get(0), "harry"); + Assertions.assertEquals(targetObj.getFriends().size(), 1); + Assertions.assertEquals(sourceObj.getFriends().size(), 1); + Assertions.assertEquals(targetObj.getFriends().get(0), "harry"); targetObj.setFriends(targetFriends); sourceObj.setFriends(sourceFriends); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getFriends().size(), 2); - Assert.assertEquals(sourceObj.getFriends().size(), 1); - Assert.assertEquals(targetObj.getFriends().get(0), "harry"); - Assert.assertEquals(targetObj.getFriends().get(1), "obama"); + Assertions.assertEquals(targetObj.getFriends().size(), 2); + Assertions.assertEquals(sourceObj.getFriends().size(), 1); + Assertions.assertEquals(targetObj.getFriends().get(0), "harry"); + Assertions.assertEquals(targetObj.getFriends().get(1), "obama"); } @Test @@ -150,8 +150,8 @@ public void testMergeMap() { BinderObj targetObj = new BinderObj(); BinderObj sourceObj = new BinderObj(); BinderUtils.merge(targetObj, sourceObj); - Assert.assertNull(targetObj.getHouses()); - Assert.assertNull(sourceObj.getHouses()); + Assertions.assertNull(targetObj.getHouses()); + Assertions.assertNull(sourceObj.getHouses()); String tgKey = "tg"; Object tgValue = new Object(); Map targetHouses = new HashMap<>(); @@ -163,42 +163,42 @@ public void testMergeMap() { targetObj.setHouses(targetHouses); sourceObj.setHouses(null); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getHouses().size(), 1); - Assert.assertNull(sourceObj.getHouses()); - Assert.assertTrue(targetObj.getHouses().containsKey(tgKey)); - Assert.assertEquals(targetObj.getHouses().get(tgKey), tgValue); + Assertions.assertEquals(targetObj.getHouses().size(), 1); + Assertions.assertNull(sourceObj.getHouses()); + Assertions.assertTrue(targetObj.getHouses().containsKey(tgKey)); + Assertions.assertEquals(targetObj.getHouses().get(tgKey), tgValue); targetObj.setHouses(null); sourceObj.setHouses(sourceHouses); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getHouses().size(), 1); - Assert.assertEquals(sourceObj.getHouses().size(), 1); - Assert.assertTrue(targetObj.getHouses().containsKey(srcKey)); - Assert.assertEquals(targetObj.getHouses().get(srcKey), srcValue); + Assertions.assertEquals(targetObj.getHouses().size(), 1); + Assertions.assertEquals(sourceObj.getHouses().size(), 1); + Assertions.assertTrue(targetObj.getHouses().containsKey(srcKey)); + Assertions.assertEquals(targetObj.getHouses().get(srcKey), srcValue); targetObj.setHouses(targetHouses); sourceObj.setHouses(sourceHouses); BinderUtils.merge(targetObj, sourceObj); - Assert.assertEquals(targetObj.getHouses().size(), 2); - Assert.assertEquals(sourceObj.getHouses().size(), 1); - Assert.assertTrue(targetObj.getHouses().containsKey(tgKey)); - Assert.assertEquals(targetObj.getHouses().get(tgKey), tgValue); - Assert.assertTrue(targetObj.getHouses().containsKey(srcKey)); - Assert.assertEquals(targetObj.getHouses().get(srcKey), srcValue); + Assertions.assertEquals(targetObj.getHouses().size(), 2); + Assertions.assertEquals(sourceObj.getHouses().size(), 1); + Assertions.assertTrue(targetObj.getHouses().containsKey(tgKey)); + Assertions.assertEquals(targetObj.getHouses().get(tgKey), tgValue); + Assertions.assertTrue(targetObj.getHouses().containsKey(srcKey)); + Assertions.assertEquals(targetObj.getHouses().get(srcKey), srcValue); } @Test public void testLazyBind() { BinderObj binderObj = new BinderObj(); BinderUtils.bind(binderObj); - Assert.assertEquals(20, binderObj.getAge()); - Assert.assertEquals(15, binderObj.getMoney().intValue()); - Assert.assertNull(binderObj.getFirstName()); + Assertions.assertEquals(20, binderObj.getAge()); + Assertions.assertEquals(15, binderObj.getMoney().intValue()); + Assertions.assertNull(binderObj.getFirstName()); BinderUtils.lazyBind(binderObj, "first_name", "harry", obj -> ((String) obj).toUpperCase()); - Assert.assertEquals("HARRY", binderObj.getFirstName()); + Assertions.assertEquals("HARRY", binderObj.getFirstName()); BinderObj binderObj2 = new BinderObj(); BinderUtils.bind(binderObj2); String nics = null; BinderUtils.lazyBind(binderObj2, "first_name", nics, obj -> NetUtils.resolveMultiNicAddr((String) obj)); - Assert.assertEquals(null, binderObj2.getFirstName()); + Assertions.assertEquals(null, binderObj2.getFirstName()); } @Test @@ -221,7 +221,7 @@ public void testLazyBindSpeed() { timerUtil.end(); final long lazyBindCost = timerUtil.getCost(); logger.debug("lazyBindCost: {}ms, bindCost: {}ms", lazyBindCost, bindCost); - Assert.assertTrue(lazyBindCost <= bindCost); + Assertions.assertTrue(lazyBindCost <= bindCost); } private static class BinderObj { @@ -284,4 +284,4 @@ public void setHouses(Map houses) { this.houses = houses; } } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/CharsetsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/CharsetsTest.java index c05b1dd82..41d18d585 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/CharsetsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/CharsetsTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.core.utils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CharsetsTest { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassLoaderUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassLoaderUtilsTest.java index fb22210d3..20cb561db 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassLoaderUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassLoaderUtilsTest.java @@ -12,8 +12,8 @@ package com.tencent.trpc.core.utils; import com.tencent.trpc.core.common.ConfigManager; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ClassLoaderUtilsTest { @@ -21,12 +21,12 @@ public class ClassLoaderUtilsTest { public void testGetClassLoader() throws ClassNotFoundException { String className = "com.tencent.trpc.core.utils.ClassLoaderUtilsTest"; Class clazz = ClassLoaderUtils.getClassLoader(this.getClass()).loadClass(className); - Assert.assertEquals(clazz.getName(), className); + Assertions.assertEquals(clazz.getName(), className); Thread.currentThread().setContextClassLoader(null); clazz = ClassLoaderUtils.getClassLoader(null).loadClass(className); - Assert.assertNotNull(clazz); + Assertions.assertNotNull(clazz); clazz = ClassLoaderUtils.getClassLoader(this.getClass()).loadClass(className); - Assert.assertEquals(clazz.getName(), className); + Assertions.assertEquals(clazz.getName(), className); ClassLoader pre = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(pre); } @@ -37,6 +37,6 @@ public void testGetCachedClassLoader() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ConfigManager.getInstance().start(); ClassLoader cachedClassLoader = ClassLoaderUtils.getClassLoader(null); - Assert.assertEquals(cachedClassLoader, classLoader); + Assertions.assertEquals(cachedClassLoader, classLoader); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassUtilsTest.java index 27f336d9e..852166884 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ClassUtilsTest.java @@ -18,8 +18,8 @@ import com.tencent.trpc.core.serialization.support.PBSerialization; import java.lang.reflect.Method; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ClassUtilsTest { @@ -34,14 +34,14 @@ public String getTestField() { @Test public void testIsByteArray() { byte[] data = new byte[]{1, 2}; - Assert.assertTrue(ClassUtils.isByteArray(data)); + Assertions.assertTrue(ClassUtils.isByteArray(data)); Byte[] dataB = new Byte[]{3, 4}; - Assert.assertTrue(ClassUtils.isByteArray(dataB)); - Assert.assertTrue(ClassUtils.isByteArray(byte[].class)); - Assert.assertTrue(ClassUtils.isByteArray(Byte[].class)); - Assert.assertEquals(1, ClassUtils.cast2ByteArray(new Byte[]{1})[0]); + Assertions.assertTrue(ClassUtils.isByteArray(dataB)); + Assertions.assertTrue(ClassUtils.isByteArray(byte[].class)); + Assertions.assertTrue(ClassUtils.isByteArray(Byte[].class)); + Assertions.assertEquals(1, ClassUtils.cast2ByteArray(new Byte[]{1})[0]); Object obj = ClassUtils.newInstance(Object.class); - Assert.assertNotNull(obj); + Assertions.assertNotNull(obj); try { ClassUtils.newInstance(LifecycleObj.class); } catch (RuntimeException e) { @@ -53,50 +53,50 @@ public void testIsByteArray() { public void testCast2ByteArray() { byte[] data = new byte[]{1, 2}; byte[] newData = ClassUtils.cast2ByteArray(data); - Assert.assertNotNull(newData); + Assertions.assertNotNull(newData); } @Test public void testGetAllInterfaces() { List classes = ClassUtils.getAllInterfaces(Object.class); - Assert.assertEquals(classes.size(), 0); + Assertions.assertEquals(classes.size(), 0); List pbInterfaces = ClassUtils.getAllInterfaces(PBSerialization.class); - Assert.assertEquals(pbInterfaces.size(), 1); - Assert.assertEquals(pbInterfaces.get(0), Serialization.class); + Assertions.assertEquals(pbInterfaces.size(), 1); + Assertions.assertEquals(pbInterfaces.get(0), Serialization.class); List classNull = ClassUtils.getAllInterfaces(null); - Assert.assertTrue(classNull.isEmpty()); + Assertions.assertTrue(classNull.isEmpty()); } @Test public void testGetDeclaredMethod() throws NoSuchMethodException { Method method = ClassUtils.getDeclaredMethod(ClassUtilsTest.class, "getTestField"); - Assert.assertEquals(method, ClassUtilsTest.class.getMethod("getTestField")); + Assertions.assertEquals(method, ClassUtilsTest.class.getMethod("getTestField")); Method methodNull = ClassUtils.getDeclaredMethod(null, "getTestField"); - Assert.assertNull(methodNull); + Assertions.assertNull(methodNull); methodNull = ClassUtils.getDeclaredMethod(ClassUtilsTest.class, "getTestField1"); - Assert.assertNull(methodNull); + Assertions.assertNull(methodNull); } @Test public void testGetValue() throws NoSuchFieldException { - Assert.assertEquals("common_string", + Assertions.assertEquals("common_string", ClassUtils.getValue(new TestInstance(), TestInstance.class.getDeclaredField("commonString")).get()); } @Test public void testGetStaticValue() throws NoSuchFieldException { - Assert.assertEquals("static_value", + Assertions.assertEquals("static_value", ClassUtils.getStaticValue(TestInstance.class.getDeclaredField("staticValue")).get()); } @Test public void testGetConstantValues() { - Assert.assertTrue(ClassUtils.getConstantValues(TestInstance.class).contains("public_constant")); - Assert.assertFalse(ClassUtils.getConstantValues(TestInstance.class).contains("private_constant")); - Assert.assertFalse(ClassUtils.getConstantValues(TestInstance.class).contains("final_value")); + Assertions.assertTrue(ClassUtils.getConstantValues(TestInstance.class).contains("public_constant")); + Assertions.assertFalse(ClassUtils.getConstantValues(TestInstance.class).contains("private_constant")); + Assertions.assertFalse(ClassUtils.getConstantValues(TestInstance.class).contains("final_value")); } private static class TestInstance { diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/CollectionUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/CollectionUtilsTest.java index 08f1d8de5..acfc593a1 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/CollectionUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/CollectionUtilsTest.java @@ -15,8 +15,8 @@ import com.google.common.collect.Sets; import java.util.List; import java.util.Set; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CollectionUtilsTest { @@ -27,10 +27,10 @@ public void testMergeList() { List l3 = Lists.newArrayList(6); List expected = Lists.newArrayList(1, 2, 3, 4, 5, 6); List merged = CollectionUtils.mergeList(l1, l2, l3); - Assert.assertEquals(expected, merged); + Assertions.assertEquals(expected, merged); List mergedLinkedList = CollectionUtils.mergeList(Lists::newLinkedList, l1, l2, l3); - Assert.assertEquals(Lists.newLinkedList(expected), mergedLinkedList); - Assert.assertEquals(0, CollectionUtils.mergeList(null).size()); + Assertions.assertEquals(Lists.newLinkedList(expected), mergedLinkedList); + Assertions.assertEquals(0, CollectionUtils.mergeList(null).size()); } @Test @@ -40,16 +40,16 @@ public void testMergeSet() { Set s3 = Sets.newHashSet(6); Set expected = Sets.newHashSet(1, 2, 3, 4, 5, 6); Set merged = CollectionUtils.mergeSet(s1, s2, s3); - Assert.assertEquals(expected.size(), merged.size()); + Assertions.assertEquals(expected.size(), merged.size()); merged.removeAll(expected); - Assert.assertTrue(merged.isEmpty()); + Assertions.assertTrue(merged.isEmpty()); Set mergedLinkedSet = CollectionUtils.mergeSet(Sets::newLinkedHashSet, s1, s2, s3); - Assert.assertEquals(Sets.newLinkedHashSet(Sets.newTreeSet(expected)), mergedLinkedSet); + Assertions.assertEquals(Sets.newLinkedHashSet(Sets.newTreeSet(expected)), mergedLinkedSet); } @Test public void testSize() { - Assert.assertEquals(0, CollectionUtils.size(null)); - Assert.assertEquals(1, CollectionUtils.size(Sets.newHashSet(1, 1, 1))); + Assertions.assertEquals(0, CollectionUtils.size(null)); + Assertions.assertEquals(1, CollectionUtils.size(Sets.newHashSet(1, 1, 1))); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ConcurrentHashSetTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ConcurrentHashSetTest.java index 299f1b238..77b82f744 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ConcurrentHashSetTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ConcurrentHashSetTest.java @@ -12,8 +12,8 @@ package com.tencent.trpc.core.utils; import java.util.Iterator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ConcurrentHashSetTest { @@ -21,17 +21,17 @@ public class ConcurrentHashSetTest { public void testUse() { ConcurrentHashSet concurrentHashSet = new ConcurrentHashSet(); ConcurrentHashSet concurrentHashSetMax = new ConcurrentHashSet(100); - Assert.assertTrue(concurrentHashSetMax.isEmpty()); + Assertions.assertTrue(concurrentHashSetMax.isEmpty()); concurrentHashSet.add(1); concurrentHashSet.add(2); - Assert.assertTrue(concurrentHashSet.size() == 2); - Assert.assertTrue(concurrentHashSet.contains(1)); + Assertions.assertTrue(concurrentHashSet.size() == 2); + Assertions.assertTrue(concurrentHashSet.contains(1)); concurrentHashSet.remove(1); - Assert.assertFalse(concurrentHashSet.contains(1)); + Assertions.assertFalse(concurrentHashSet.contains(1)); Iterator iterator = concurrentHashSet.iterator(); Number t2 = iterator.next(); - Assert.assertTrue(t2.intValue() == 2); + Assertions.assertTrue(t2.intValue() == 2); concurrentHashSet.clear(); - Assert.assertTrue(concurrentHashSet.isEmpty()); + Assertions.assertTrue(concurrentHashSet.isEmpty()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/FutureUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/FutureUtilsTest.java index 864e88c70..2bc703e69 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/FutureUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/FutureUtilsTest.java @@ -18,8 +18,8 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class FutureUtilsTest { @@ -27,7 +27,7 @@ public class FutureUtilsTest { public void test() { CompletionStage stage = FutureUtils.newFuture(); stage.toCompletableFuture().complete(1); - Assert.assertEquals(FutureUtils.adapt(stage).join().intValue(), 1); + Assertions.assertEquals(FutureUtils.adapt(stage).join().intValue(), 1); CompletionStage stage2 = FutureUtils.failed(new IllegalArgumentException()); Exception expectEx2 = null; try { @@ -35,7 +35,7 @@ public void test() { } catch (Exception ex) { expectEx2 = ex; } - Assert.assertTrue(expectEx2 != null && expectEx2.getCause() instanceof IllegalArgumentException); + Assertions.assertTrue(expectEx2 != null && expectEx2.getCause() instanceof IllegalArgumentException); CompletionStage stage3 = FutureUtils.newFuture(); FutureUtils.failed(stage3.toCompletableFuture(), new IllegalArgumentException()); Exception expectEx3 = null; @@ -44,7 +44,7 @@ public void test() { } catch (Exception ex) { expectEx3 = ex; } - Assert.assertTrue(expectEx3 != null && expectEx3 + Assertions.assertTrue(expectEx3 != null && expectEx3 .getCause() instanceof IllegalArgumentException); FutureUtils.allOf(Lists.newArrayList(stage3.toCompletableFuture())); CompletionStage timeoutStage = FutureUtils.withTimeout(FutureUtils.newFuture(), @@ -55,15 +55,15 @@ public void test() { } catch (Exception ex) { expectEx4 = ex; } - Assert.assertTrue(expectEx4 != null && expectEx4.getCause() instanceof TimeoutException); + Assertions.assertTrue(expectEx4 != null && expectEx4.getCause() instanceof TimeoutException); } @Test public void testNewSuccessFuture() throws ExecutionException, InterruptedException { CompletableFuture voidCompletableFuture = FutureUtils.newSuccessFuture(); - Assert.assertNotNull(voidCompletableFuture); + Assertions.assertNotNull(voidCompletableFuture); Object object = new Object(); CompletableFuture objectCompletableFuture = FutureUtils.newSuccessFuture(object); - Assert.assertSame(objectCompletableFuture.get().getClass(), Object.class); + Assertions.assertSame(objectCompletableFuture.get().getClass(), Object.class); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/IPUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/IPUtilsTest.java index b3b4a75f0..bb112b342 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/IPUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/IPUtilsTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IPUtilsTest { @@ -22,28 +22,28 @@ public void testTransfer() { int ipInt = IPUtils.ip2int(host); byte[] ipBytes = IPUtils.ip2bytes(host); String newIp = IPUtils.bytes2ip(ipBytes); - Assert.assertEquals(newIp, host); + Assertions.assertEquals(newIp, host); String newIp2 = IPUtils.int2ip(ipInt); - Assert.assertEquals(newIp2, host); + Assertions.assertEquals(newIp2, host); NetUtils.resolveNicAddr("eth1"); - Assert.assertEquals(0, IPUtils.ip2int(null)); + Assertions.assertEquals(0, IPUtils.ip2int(null)); } @Test public void testIsIPStrValid() { - Assert.assertFalse(IPUtils.isIPStrValid(null)); - Assert.assertFalse(IPUtils.isIPStrValid("")); - Assert.assertFalse(IPUtils.isIPStrValid("0.0.0.0")); - Assert.assertFalse(IPUtils.isIPStrValid("::")); - Assert.assertFalse(IPUtils.isIPStrValid("127.0.0.1")); - Assert.assertFalse(IPUtils.isIPStrValid("::1")); - Assert.assertFalse(IPUtils.isIPStrValid("169.254.1.1")); - Assert.assertFalse(IPUtils.isIPStrValid("fe80::42:c0ff:fea8:a02")); - Assert.assertFalse(IPUtils.isIPStrValid("172.16.0.1")); - Assert.assertFalse(IPUtils.isIPStrValid("192.168.10.6")); - Assert.assertFalse(IPUtils.isIPStrValid("FEC0::1:2:3:4")); - Assert.assertFalse(IPUtils.isIPStrValid("fd12:3456:789a:1::1")); - Assert.assertTrue(IPUtils.isIPStrValid("1.2.3.4")); - Assert.assertTrue(IPUtils.isIPStrValid("2402:4e00::")); + Assertions.assertFalse(IPUtils.isIPStrValid(null)); + Assertions.assertFalse(IPUtils.isIPStrValid("")); + Assertions.assertFalse(IPUtils.isIPStrValid("0.0.0.0")); + Assertions.assertFalse(IPUtils.isIPStrValid("::")); + Assertions.assertFalse(IPUtils.isIPStrValid("127.0.0.1")); + Assertions.assertFalse(IPUtils.isIPStrValid("::1")); + Assertions.assertFalse(IPUtils.isIPStrValid("169.254.1.1")); + Assertions.assertFalse(IPUtils.isIPStrValid("fe80::42:c0ff:fea8:a02")); + Assertions.assertFalse(IPUtils.isIPStrValid("172.16.0.1")); + Assertions.assertFalse(IPUtils.isIPStrValid("192.168.10.6")); + Assertions.assertFalse(IPUtils.isIPStrValid("FEC0::1:2:3:4")); + Assertions.assertFalse(IPUtils.isIPStrValid("fd12:3456:789a:1::1")); + Assertions.assertTrue(IPUtils.isIPStrValid("1.2.3.4")); + Assertions.assertTrue(IPUtils.isIPStrValid("2402:4e00::")); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/NetUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/NetUtilsTest.java index 3c3d5d05c..6343623dd 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/NetUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/NetUtilsTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -20,52 +20,53 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.util.Collections; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.MockedStatic; +import org.mockito.Mockito; -@RunWith(PowerMockRunner.class) -@PrepareForTest({NetUtils.class, InetAddress.class, NetworkInterface.class}) +@ExtendWith(MockitoExtension.class) public class NetUtilsTest { private static final Logger logger = LoggerFactory.getLogger(NetUtilsTest.class); @Test public void testNet() { - Assert.assertEquals(Constants.UNKNOWN, NetUtils.toIpPort(null)); + Assertions.assertEquals(Constants.UNKNOWN, NetUtils.toIpPort(null)); InetSocketAddress inetSocketAddress = new InetSocketAddress("9.9.8.12", 8080); String ipPort = NetUtils.toIpPort(inetSocketAddress); - Assert.assertEquals("9.9.8.12:8080", ipPort); + Assertions.assertEquals("9.9.8.12:8080", ipPort); int port1 = NetUtils.getAvailablePort(); int port2 = NetUtils.getAvailablePort("127.0.0.1", 8080); int port3 = NetUtils.getRandomPort(); - Assert.assertTrue(port1 < 65536); - Assert.assertTrue(port2 < 65536); - Assert.assertTrue(port3 < 65536); + Assertions.assertTrue(port1 < 65536); + Assertions.assertTrue(port2 < 65536); + Assertions.assertTrue(port3 < 65536); } @Test public void testGetHostIp() { - Assert.assertNotNull(NetUtils.getHostIp()); + Assertions.assertNotNull(NetUtils.getHostIp()); } @Test public void testGetHostIpNull() throws UnknownHostException { - PowerMockito.mockStatic(InetAddress.class); - PowerMockito.when(InetAddress.getLocalHost()).thenThrow(new IllegalStateException()); - Assert.assertNull(NetUtils.getHostIp()); + try (MockedStatic mockedStatic = Mockito.mockStatic(InetAddress.class)) { + mockedStatic.when(InetAddress::getLocalHost).thenThrow(new IllegalStateException()); + Assertions.assertNull(NetUtils.getHostIp()); + } } @Test public void testGetHostIpV4() throws UnknownHostException { - PowerMockito.mockStatic(InetAddress.class); - InetAddress inetAddress = PowerMockito.mock(InetAddress.class); - PowerMockito.when(inetAddress.isLoopbackAddress()).thenReturn(true); - PowerMockito.when(InetAddress.getLocalHost()).thenReturn(inetAddress); - Assert.assertNotNull(NetUtils.getHostIp()); + try (MockedStatic mockedStatic = Mockito.mockStatic(InetAddress.class)) { + InetAddress inetAddress = Mockito.mock(InetAddress.class); + Mockito.when(inetAddress.isLoopbackAddress()).thenReturn(true); + mockedStatic.when(InetAddress::getLocalHost).thenReturn(inetAddress); + Assertions.assertNotNull(NetUtils.getHostIp()); + } } @Test @@ -73,15 +74,16 @@ public void testGetInet4Address() { try { NetUtils.getInet4Address(); } catch (SocketException e) { - Assert.fail(); + Assertions.fail(); } } @Test public void testGetInet4AddressNull() throws SocketException { - PowerMockito.mockStatic(NetworkInterface.class); - PowerMockito.when(NetworkInterface.getNetworkInterfaces()).thenReturn(Collections.emptyEnumeration()); - Assert.assertNull(NetUtils.getInet4Address()); + try (MockedStatic mockedStatic = Mockito.mockStatic(NetworkInterface.class)) { + mockedStatic.when(NetworkInterface::getNetworkInterfaces).thenReturn(Collections.emptyEnumeration()); + Assertions.assertNull(NetUtils.getInet4Address()); + } } @Test @@ -89,8 +91,8 @@ public void testResolveMultiNicAddr() { String host = NetUtils.resolveMultiNicAddr("eth0, lo0, eth1"); logger.debug(host); NetUtils.resolveMultiNicAddr("lo0"); - Assert.assertNull(NetUtils.resolveMultiNicAddr("")); + Assertions.assertNull(NetUtils.resolveMultiNicAddr("")); String none = null; - Assert.assertNull(NetUtils.resolveMultiNicAddr(none)); + Assertions.assertNull(NetUtils.resolveMultiNicAddr(none)); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/PreconditionUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/PreconditionUtilsTest.java index b68f274d3..4757895eb 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/PreconditionUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/PreconditionUtilsTest.java @@ -13,20 +13,16 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PreconditionUtilsTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void testCheckArgument() { - expectedEx.expect(IllegalArgumentException.class); - List list = new ArrayList(); - PreconditionUtils - .checkArgument(list == null, "list is null %s", "list"); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + List list = new ArrayList(); + PreconditionUtils.checkArgument(list == null, "list is null %s", "list"); + }); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ProtoJsonConverterTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ProtoJsonConverterTest.java index bc6527db8..5fe19f07a 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/ProtoJsonConverterTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/ProtoJsonConverterTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.utils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.protobuf.ByteString; import com.tencent.trpc.core.utils.HelloRequestProtocol.HelloRequest; @@ -22,8 +22,8 @@ import java.util.Base64; 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; /** * pb to json test class @@ -50,7 +50,7 @@ public class ProtoJsonConverterTest { @Test public void testToString() { String toString = ProtoJsonConverter.toString(REQUEST); - Assert.assertEquals(toString, "{\n" + Assertions.assertEquals(toString, "{\n" + " \"intField\": 1,\n" + " \"stringField\": \"string$中文\",\n" + " \"booleanField\": true,\n" @@ -75,7 +75,7 @@ public void testToString() { + " \"weeks\": [0]\n" + "}"); String nullString = ProtoJsonConverter.toString(null); - Assert.assertNull(nullString); + Assertions.assertNull(nullString); } @Test @@ -215,7 +215,7 @@ public void testMessageToJson() { @Test public void testJsonToMessage() { String json = ProtoJsonConverter.messageToJson(REQUEST, false, false); - Assert.assertEquals("{\"intField\":1,\"stringField\":\"string$中文\",\"booleanField\":true," + Assertions.assertEquals("{\"intField\":1,\"stringField\":\"string$中文\",\"booleanField\":true," + "\"doubleField\":1.0,\"floatField\":2.0,\"longField\":\"100\",\"byteStringField\":\"YQ==\"," + "\"other\":{\"intField\":2},\"intFields\":[1],\"stringFields\":[\"string$\"]," + "\"booleanFields\":[true],\"doubleFields\":[1.0],\"floatFields\":[2.0]," diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcContextUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcContextUtilsTest.java index d3290e629..f8c0a806b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcContextUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcContextUtilsTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.utils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import com.tencent.trpc.core.rpc.RpcContext; import com.tencent.trpc.core.rpc.Request; @@ -26,8 +26,8 @@ import io.opentracing.SpanContext; import io.opentracing.tag.Tag; 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 RpcContextUtilsTest { @@ -106,7 +106,7 @@ public void finish(long l) { } }; RpcContextUtils.putValueMapValue(ctx, RpcContextValueKeys.CTX_TRACE_SPAN, span); - Assert.assertEquals(span, RpcContextUtils.getSpan(ctx)); + Assertions.assertEquals(span, RpcContextUtils.getSpan(ctx)); } @Test @@ -225,17 +225,17 @@ public void testSetExtensionDimension() { String extDimension = "test"; RpcContextUtils.setExtensionDimension(context, extDimension); String extDimensionFromContext = RpcContextUtils.getExtensionDimension(context); - Assert.assertEquals(extDimension, extDimensionFromContext); + Assertions.assertEquals(extDimension, extDimensionFromContext); } @Test public void testGetExtensionDimension() { RpcContext context = new RpcClientContext(); String extDimensionFromContext = RpcContextUtils.getExtensionDimension(context); - Assert.assertEquals("", extDimensionFromContext); + Assertions.assertEquals("", extDimensionFromContext); String extDimension = "test"; RpcContextUtils.putRequestAttachValue(context, RpcContextValueKeys.CTX_M007_EXT3, extDimension); extDimensionFromContext = RpcContextUtils.getExtensionDimension(context); - Assert.assertEquals(extDimension, extDimensionFromContext); + Assertions.assertEquals(extDimension, extDimensionFromContext); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcUtilsTest.java index 5af670a2d..7de13ad5b 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/RpcUtilsTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -35,8 +35,8 @@ import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RpcUtilsTest { @@ -71,50 +71,50 @@ public String genericMethod() { public void testIsReturnFutureType() throws Exception { boolean flag = InvokeMode.isAsync(RpcUtils.parseInvokeMode( RpcUtilsTest.class.getMethod("reMethod", String.class))); - Assert.assertFalse(flag); + Assertions.assertFalse(flag); boolean flagFuture = InvokeMode.isAsync(RpcUtils.parseInvokeMode(RpcUtilsTest.class.getMethod("futureMethod"))); - Assert.assertTrue(flagFuture); + Assertions.assertTrue(flagFuture); String methodName1 = RpcUtils.parseRpcMethodName(RpcUtilsTest.class.getMethod("method1", String.class), "100"); - Assert.assertEquals("9527", methodName1); + Assertions.assertEquals("9527", methodName1); String methodName2 = RpcUtils.parseRpcMethodName(RpcUtilsTest.class.getMethod("method2", String.class), "100"); - Assert.assertEquals("100", methodName2); + Assertions.assertEquals("100", methodName2); String serviceName = RpcUtils.parseRpcServiceName(RpcUtilsTest.class, "helloService"); - Assert.assertEquals("helloService", serviceName); + Assertions.assertEquals("helloService", serviceName); } @Test public void testIsGenericClient() { - Assert.assertFalse(RpcUtils.isGenericClient(Object.class)); - Assert.assertTrue(RpcUtils.isGenericClient(GenericClient.class)); - Assert.assertTrue(RpcUtils.isGenericClient(SimpleGenericClient.class)); + Assertions.assertFalse(RpcUtils.isGenericClient(Object.class)); + Assertions.assertTrue(RpcUtils.isGenericClient(GenericClient.class)); + Assertions.assertTrue(RpcUtils.isGenericClient(SimpleGenericClient.class)); } @Test public void testIsGenericMethod() throws NoSuchMethodException { Method method = RpcUtilsTest.class.getMethod("method1", String.class); - Assert.assertFalse(RpcUtils.isGenericMethod(method)); + Assertions.assertFalse(RpcUtils.isGenericMethod(method)); method = RpcUtilsTest.class.getMethod("genericMethod"); - Assert.assertTrue(RpcUtils.isGenericMethod(method)); + Assertions.assertTrue(RpcUtils.isGenericMethod(method)); } @Test public void testIsDefaultMethod() throws NoSuchMethodException { Method method = RpcUtilsTest.class.getMethod("method1", String.class); - Assert.assertFalse(RpcUtils.isDefaultRpcMethod(method)); + Assertions.assertFalse(RpcUtils.isDefaultRpcMethod(method)); method = RpcUtilsTest.class.getMethod("defaultMethod"); - Assert.assertTrue(RpcUtils.isDefaultRpcMethod(method)); + Assertions.assertTrue(RpcUtils.isDefaultRpcMethod(method)); } @Test public void testNewResponse() { Request request = new DefRequest(); - Assert.assertNotNull(RpcUtils.newResponse(request, new Object(), null)); + Assertions.assertNotNull(RpcUtils.newResponse(request, new Object(), null)); } @Test @@ -125,12 +125,12 @@ public void testParseAsyncInvokeResult() throws ExecutionException, InterruptedE CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); response.complete(new DefResponse()); CompletableFuture.allOf(future).join(); - Assert.assertNull(future.get()); + Assertions.assertNull(future.get()); future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); response.complete(null); CompletableFuture.allOf(future).join(); - Assert.assertNull(future.get()); + Assertions.assertNull(future.get()); } @Test @@ -145,53 +145,59 @@ public void testParseAsyncInvokeCommonResult() throws ExecutionException, Interr response.complete(new DefResponse()); CompletableFuture.allOf(future).join(); Object o = future.get(); - Assert.assertNotNull(o); - Assert.assertTrue(o instanceof RpcResult); + Assertions.assertNotNull(o); + Assertions.assertTrue(o instanceof RpcResult); response = FutureUtils.newFuture(); future = RpcUtils.parseAsyncInvokeResult(response, clientContext, methodInfo); response.complete(null); - Assert.assertNotNull(future.get()); - Assert.assertTrue(o instanceof RpcResult); + Assertions.assertNotNull(future.get()); + Assertions.assertTrue(o instanceof RpcResult); } - @Test(expected = CompletionException.class) + @Test public void testParseAsyncInvokeResult1() { - CompletableFuture response = FutureUtils.newFuture(); - RpcClientContext clientContext = new RpcClientContext(); - clientContext.setOneWay(Boolean.FALSE); - CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); - response.completeExceptionally(TRpcException.newBizException(1, "aaa")); - CompletableFuture.allOf(future).join(); + Assertions.assertThrows(CompletionException.class, () -> { + CompletableFuture response = FutureUtils.newFuture(); + RpcClientContext clientContext = new RpcClientContext(); + clientContext.setOneWay(Boolean.FALSE); + CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); + response.completeExceptionally(TRpcException.newBizException(1, "aaa")); + CompletableFuture.allOf(future).join(); + }); } - @Test(expected = CompletionException.class) + @Test public void testParseAsyncInvokeResult2() { - CompletableFuture response = FutureUtils.newFuture(); - RpcClientContext clientContext = new RpcClientContext(); - clientContext.setOneWay(Boolean.FALSE); - RpcContextUtils.putValueMapValue(clientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, - LinkInvokeTimeout.builder() - .serviceEnableLinkTimeout(true) - .build()); - CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); - response.completeExceptionally(TRpcException.newFrameException(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR, - "aaa")); - CompletableFuture.allOf(future).join(); + Assertions.assertThrows(CompletionException.class, () -> { + CompletableFuture response = FutureUtils.newFuture(); + RpcClientContext clientContext = new RpcClientContext(); + clientContext.setOneWay(Boolean.FALSE); + RpcContextUtils.putValueMapValue(clientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, + LinkInvokeTimeout.builder() + .serviceEnableLinkTimeout(true) + .build()); + CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); + response.completeExceptionally(TRpcException.newFrameException(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR, + "aaa")); + CompletableFuture.allOf(future).join(); + }); } - @Test(expected = CompletionException.class) + @Test public void testParseAsyncInvokeResult3() { - CompletableFuture response = FutureUtils.newFuture(); - RpcClientContext clientContext = new RpcClientContext(); - clientContext.setOneWay(Boolean.FALSE); - RpcContextUtils.putValueMapValue(clientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, - LinkInvokeTimeout.builder() - .serviceEnableLinkTimeout(true) - .build()); - CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); - response.completeExceptionally(TRpcException.newBizException(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR, - "aaa")); - CompletableFuture.allOf(future).join(); + Assertions.assertThrows(CompletionException.class, () -> { + CompletableFuture response = FutureUtils.newFuture(); + RpcClientContext clientContext = new RpcClientContext(); + clientContext.setOneWay(Boolean.FALSE); + RpcContextUtils.putValueMapValue(clientContext, RpcContextValueKeys.CTX_LINK_INVOKE_TIMEOUT, + LinkInvokeTimeout.builder() + .serviceEnableLinkTimeout(true) + .build()); + CompletableFuture future = RpcUtils.parseAsyncInvokeResult(response, clientContext, null); + response.completeExceptionally(TRpcException.newBizException(ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR, + "aaa")); + CompletableFuture.allOf(future).join(); + }); } @Test @@ -207,7 +213,7 @@ public void testParseAsyncInvoke4() throws NoSuchMethodException, ExecutionExcep response.completeExceptionally(TRpcException.newBizException(1, "aaa")); CompletableFuture.allOf(future).join(); Object result = future.get(); - Assert.assertTrue(result instanceof RpcResult); + Assertions.assertTrue(result instanceof RpcResult); } @Test @@ -226,7 +232,7 @@ public void testParseSyncInvokeResult() { }).start(); Object result = RpcUtils.parseSyncInvokeResult(future, new RpcClientContext(), 2000, 3000, null); - Assert.assertEquals(value, result); + Assertions.assertEquals(value, result); } @Test @@ -248,28 +254,32 @@ public void testParseSyncInvokeCommonResult() throws NoSuchMethodException { RpcMethodInfo methodInfo = new RpcMethodInfo(CommonResultClient.class, method); RpcResult result = (RpcResult) RpcUtils.parseSyncInvokeResult(future, new RpcClientContext(), 2000, 3000, methodInfo); - Assert.assertEquals(value, result.getData()); + Assertions.assertEquals(value, result.getData()); } - @Test(expected = TRpcException.class) + @Test public void testParseSyncInvoke1() { - RpcUtils.parseSyncInvokeResult(FutureUtils.newFuture(), new RpcClientContext(), - 1, 20, null); + Assertions.assertThrows(TRpcException.class, () -> { + RpcUtils.parseSyncInvokeResult(FutureUtils.newFuture(), new RpcClientContext(), + 1, 20, null); + }); } - @Test(expected = TRpcException.class) + @Test public void testParseSyncInvoke2() { - CompletableFuture future = FutureUtils.newFuture(); - new Thread(() -> { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - future.completeExceptionally(TRpcException.newBizException(1, "aaa")); - }).start(); + Assertions.assertThrows(TRpcException.class, () -> { + CompletableFuture future = FutureUtils.newFuture(); + new Thread(() -> { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + future.completeExceptionally(TRpcException.newBizException(1, "aaa")); + }).start(); - RpcUtils.parseSyncInvokeResult(future, new RpcClientContext(), 2000, 3000, null); + RpcUtils.parseSyncInvokeResult(future, new RpcClientContext(), 2000, 3000, null); + }); } @Test @@ -279,7 +289,7 @@ public void testParseSyncInvoke3() throws NoSuchMethodException { RpcMethodInfo methodInfo = new RpcMethodInfo(CommonResultClient.class, method); RpcResult result = (RpcResult) RpcUtils.parseSyncInvokeResult(FutureUtils.newFuture(), new RpcClientContext(), 1, 20, methodInfo); - Assert.assertEquals(result.getCode(), ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR); + Assertions.assertEquals(result.getCode(), ErrorCode.TRPC_CLIENT_INVOKE_TIMEOUT_ERR); } @Test @@ -312,7 +322,7 @@ public CompletionStage invoke(Request request) { CompletionStage response2 = invoker.invoke(new DefRequest()); String defResponse = (String) RpcUtils.parseSyncInvokeBackupResult(response2.toCompletableFuture(), 1, new LeftTimeout(3000, 2000), invoker, new DefRequest()); - Assert.assertEquals(value, defResponse); + Assertions.assertEquals(value, defResponse); } catch (Exception e) { e.printStackTrace(); } @@ -355,7 +365,7 @@ public CompletionStage invoke(Request request) { CompletionStage response2 = invoker.invoke(new DefRequest()); String defResponse = (String) RpcUtils.parseSyncInvokeBackupResult(response2.toCompletableFuture(), 1, new LeftTimeout(3000, 2000), invoker, new DefRequest()); - Assert.assertEquals(value, defResponse); + Assertions.assertEquals(value, defResponse); } catch (Exception e) { e.printStackTrace(); } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/SeqUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/SeqUtilsTest.java index 7169743da..4045a0aa3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/SeqUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/SeqUtilsTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SeqUtilsTest { @@ -20,6 +20,6 @@ public class SeqUtilsTest { public void testSeq() { int intSeq = SeqUtils.genIntegerSeq(); int intSeq1 = SeqUtils.genIntegerSeq(); - Assert.assertEquals(intSeq1, intSeq + 1); + Assertions.assertEquals(intSeq1, intSeq + 1); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/StringUtilsTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/StringUtilsTest.java index 0a5bfc267..4cf09f8af 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/StringUtilsTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/StringUtilsTest.java @@ -11,22 +11,22 @@ package com.tencent.trpc.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StringUtilsTest { @Test public void testSplitToWords() { - Assert.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords("a, b, c")); - Assert.assertArrayEquals(new String[]{"a. b. c"}, StringUtils.splitToWords("a. b. c")); - Assert.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords("a,b,c")); - Assert.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords(" a, b, c ")); - Assert.assertArrayEquals(new String[]{"hello"}, StringUtils.splitToWords("hello")); - Assert.assertArrayEquals(new String[]{"hello"}, StringUtils.splitToWords(" hello ")); - Assert.assertArrayEquals(new String[]{"hello world"}, StringUtils.splitToWords("hello world")); - Assert.assertArrayEquals(new String[]{"hello world"}, StringUtils.splitToWords(" hello world ")); - Assert.assertArrayEquals(new String[]{}, StringUtils.splitToWords(null)); - Assert.assertArrayEquals(new String[]{}, StringUtils.splitToWords("")); + Assertions.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords("a, b, c")); + Assertions.assertArrayEquals(new String[]{"a. b. c"}, StringUtils.splitToWords("a. b. c")); + Assertions.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords("a,b,c")); + Assertions.assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.splitToWords(" a, b, c ")); + Assertions.assertArrayEquals(new String[]{"hello"}, StringUtils.splitToWords("hello")); + Assertions.assertArrayEquals(new String[]{"hello"}, StringUtils.splitToWords(" hello ")); + Assertions.assertArrayEquals(new String[]{"hello world"}, StringUtils.splitToWords("hello world")); + Assertions.assertArrayEquals(new String[]{"hello world"}, StringUtils.splitToWords(" hello world ")); + Assertions.assertArrayEquals(new String[]{}, StringUtils.splitToWords(null)); + Assertions.assertArrayEquals(new String[]{}, StringUtils.splitToWords("")); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimeUtilTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimeUtilTest.java index 24113ac11..0870c0f79 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimeUtilTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimeUtilTest.java @@ -11,24 +11,24 @@ package com.tencent.trpc.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TimeUtilTest { @Test public void testConvertTimeUnitStringToMills() { int day = TimeUtil.convertTimeUnitStringToMills("5d"); - Assert.assertEquals(day, 5 * 24 * 60 * 60 * 1000); + Assertions.assertEquals(day, 5 * 24 * 60 * 60 * 1000); int hour = TimeUtil.convertTimeUnitStringToMills("54h"); - Assert.assertEquals(hour, 54 * 60 * 60 * 1000); + Assertions.assertEquals(hour, 54 * 60 * 60 * 1000); int second = TimeUtil.convertTimeUnitStringToMills("345m"); - Assert.assertEquals(second, 345 * 60 * 1000); + Assertions.assertEquals(second, 345 * 60 * 1000); int ms = TimeUtil.convertTimeUnitStringToMills("345343ms"); - Assert.assertEquals(345343, ms); + Assertions.assertEquals(345343, ms); int s = TimeUtil.convertTimeUnitStringToMills("34443s"); - Assert.assertEquals(s, 34443 * 1000); + Assertions.assertEquals(s, 34443 * 1000); int seconds = TimeUtil.convertTimeUnitStringToSeconds("3442s"); - Assert.assertEquals(seconds, 3442); + Assertions.assertEquals(seconds, 3442); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimerUtilTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimerUtilTest.java index 0e539d46b..69b3b1e9c 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimerUtilTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/TimerUtilTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TimerUtilTest { @@ -23,16 +23,16 @@ public void testTimer() throws InterruptedException { Thread.sleep(50); timerUtil.end(); long cost = timerUtil.getCost(); - Assert.assertTrue(cost >= 25); + Assertions.assertTrue(cost >= 25); timerUtil.reset(); - Assert.assertTrue(timerUtil.getCost() == 0); + Assertions.assertTrue(timerUtil.getCost() == 0); timerUtil.nstart(); Thread.sleep(10); timerUtil.nend(); - Assert.assertTrue(timerUtil.ngetCost() > 1); + Assertions.assertTrue(timerUtil.ngetCost() > 1); timerUtil.getMinCost(); timerUtil.getTotalCost(); - Assert.assertTrue(timerUtil.getMaxCost() > 1); - Assert.assertTrue(timerUtil.getTotalCost() > 1); + Assertions.assertTrue(timerUtil.getMaxCost() > 1); + Assertions.assertTrue(timerUtil.getTotalCost() > 1); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/utils/YamlParserTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/utils/YamlParserTest.java index 341d8a728..f9c556b31 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/utils/YamlParserTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/utils/YamlParserTest.java @@ -13,8 +13,8 @@ import java.io.InputStream; 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 YamlParserTest { @@ -25,19 +25,19 @@ public void testParseAsInputStream() { InputStream resourceAsStream = ClassLoaderUtils. getClassLoader(YamlParser.class).getResourceAsStream(defaultFileName); Map map = YamlParser.parseAs(resourceAsStream, Map.class); - Assert.assertNotNull(map); + Assertions.assertNotNull(map); } @Test public void testParseAs() { String path = YamlParser.class.getClassLoader().getResource(defaultFileName).getPath(); Object map = YamlParser.parseAs(path, Object.class); - Assert.assertNotNull(map); + Assertions.assertNotNull(map); } @Test public void testParseAsFromClassPath() { Map map = YamlParser.parseAsFromClassPath(defaultFileName, Map.class); - Assert.assertNotNull(map); + Assertions.assertNotNull(map); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/AbstractWorkerPoolTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/AbstractWorkerPoolTest.java index 8cfa281f2..152d6cef4 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/AbstractWorkerPoolTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/AbstractWorkerPoolTest.java @@ -14,49 +14,44 @@ import com.tencent.trpc.core.management.ForkJoinPoolMXBeanImpl; import java.lang.Thread.UncaughtExceptionHandler; import java.util.concurrent.RejectedExecutionException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AbstractWorkerPoolTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void testToExecutor() { - expectedEx.expect(UnsupportedOperationException.class); - expectedEx.expectMessage("not support toThreadPoolExecutor"); - - AbstractWorkerPool pool = new AbstractWorkerPool() { - - @Override - public UncaughtExceptionHandler getUncaughtExceptionHandler() { - return null; - } + UnsupportedOperationException exception = Assertions.assertThrows(UnsupportedOperationException.class, () -> { + AbstractWorkerPool pool = new AbstractWorkerPool() { - @Override - public String getName() { - return null; - } + @Override + public UncaughtExceptionHandler getUncaughtExceptionHandler() { + return null; + } - @Override - public void execute(Task task) throws RejectedExecutionException { + @Override + public String getName() { + return null; + } - } + @Override + public void execute(Task task) throws RejectedExecutionException { - @Override - public ForkJoinPoolMXBeanImpl report() { - return null; - } + } - @Override - public void close(long timeoutMills) { + @Override + public ForkJoinPoolMXBeanImpl report() { + return null; + } - } - }; + @Override + public void close(long timeoutMills) { - pool.toExecutor(); + } + }; + pool.toExecutor(); + }); + Assertions.assertTrue(exception.getMessage().contains("not support toThreadPoolExecutor")); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java index 7661eea99..4bec25e47 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java @@ -18,8 +18,8 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class WorkerPoolManagerTest { @@ -29,7 +29,7 @@ public class WorkerPoolManagerTest { @Test public void testGetShareScheduler() { ScheduledExecutorService shareScheduler = WorkerPoolManager.getShareScheduler(); - Assert.assertNotNull(shareScheduler); + Assertions.assertNotNull(shareScheduler); } /** @@ -38,7 +38,7 @@ public void testGetShareScheduler() { @Test public void testGetShutdownExecutor() { Executor shutdownExecutor = WorkerPoolManager.getShutdownExecutor(); - Assert.assertNotNull(shutdownExecutor); + Assertions.assertNotNull(shutdownExecutor); } /** @@ -48,11 +48,11 @@ public void testGetShutdownExecutor() { public void testRegistDefaultPluginConfig() { WorkerPoolManager.registDefaultPluginConfig(); WorkerPool consumer = WorkerPoolManager.get(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME); - Assert.assertNotNull(consumer); + Assertions.assertNotNull(consumer); WorkerPool provider = WorkerPoolManager.get(WorkerPoolManager.DEF_PROVIDER_WORKER_POOL_NAME); - Assert.assertNotNull(provider); + Assertions.assertNotNull(provider); WorkerPool naming = WorkerPoolManager.get(WorkerPoolManager.DEF_NAMING_WORKER_POOL_NAME); - Assert.assertNotNull(naming); + Assertions.assertNotNull(naming); } /** @@ -81,11 +81,11 @@ public void testGet() { public void testGetAllInitializedExtension() { this.testRegistDefaultPluginConfig(); List allInitializedExtension = WorkerPoolManager.getAllInitializedExtension(); - Assert.assertTrue(allInitializedExtension.contains( + Assertions.assertTrue(allInitializedExtension.contains( WorkerPoolManager.get(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME))); - Assert.assertTrue(allInitializedExtension.contains( + Assertions.assertTrue(allInitializedExtension.contains( WorkerPoolManager.get(WorkerPoolManager.DEF_PROVIDER_WORKER_POOL_NAME))); - Assert.assertTrue(allInitializedExtension.contains( + Assertions.assertTrue(allInitializedExtension.contains( WorkerPoolManager.get(WorkerPoolManager.DEF_NAMING_WORKER_POOL_NAME))); } @@ -99,7 +99,7 @@ public void testRefresh() { .newThreadWorkerPoolConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, 20, Boolean.FALSE); WorkerPoolManager.refresh(WorkerPoolManager.DEF_NAMING_WORKER_POOL_NAME, pluginConfig); WorkerPool workerPool = WorkerPoolManager.get(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME); - Assert.assertNotNull(workerPool); + Assertions.assertNotNull(workerPool); } @Test @@ -110,7 +110,7 @@ public void testWorkPool() { 20,20, Boolean.FALSE); WorkerPoolManager.refresh(WorkerPoolManager.DEF_NAMING_WORKER_POOL_NAME, pluginConfig); WorkerPool workerPool = WorkerPoolManager.get(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME); - Assert.assertNotNull(workerPool); + Assertions.assertNotNull(workerPool); } /** @@ -120,22 +120,22 @@ public void testWorkPool() { public void testNewThreadWorkerPoolConfig() { PluginConfig pluginConfig = WorkerPoolManager .newThreadWorkerPoolConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, 20, Boolean.FALSE); - Assert.assertNotNull(pluginConfig); - Assert.assertEquals(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, pluginConfig.getName()); - Assert.assertEquals(WorkerPool.class, pluginConfig.getPluginInterface()); - Assert.assertEquals(20, pluginConfig.getProperties().get("core_pool_size")); - Assert.assertFalse((Boolean) pluginConfig.getProperties().get("use_fiber")); - Assert.assertTrue((Boolean) pluginConfig.getProperties().get("share_schedule")); + Assertions.assertNotNull(pluginConfig); + Assertions.assertEquals(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, pluginConfig.getName()); + Assertions.assertEquals(WorkerPool.class, pluginConfig.getPluginInterface()); + Assertions.assertEquals(20, pluginConfig.getProperties().get("core_pool_size")); + Assertions.assertFalse((Boolean) pluginConfig.getProperties().get("use_fiber")); + Assertions.assertTrue((Boolean) pluginConfig.getProperties().get("share_schedule")); pluginConfig = WorkerPoolManager.newThreadWorkerPoolConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, 2000, Boolean.TRUE); - Assert.assertNotNull(pluginConfig); + Assertions.assertNotNull(pluginConfig); ThreadPoolConfig.validate(pluginConfig); - Assert.assertEquals(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, pluginConfig.getName()); - Assert.assertEquals(WorkerPool.class, pluginConfig.getPluginInterface()); - Assert.assertEquals(2000, pluginConfig.getProperties().get("core_pool_size")); - Assert.assertTrue((Boolean) pluginConfig.getProperties().get("use_fiber")); - Assert.assertTrue((Boolean) pluginConfig.getProperties().get("share_schedule")); + Assertions.assertEquals(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, pluginConfig.getName()); + Assertions.assertEquals(WorkerPool.class, pluginConfig.getPluginInterface()); + Assertions.assertEquals(2000, pluginConfig.getProperties().get("core_pool_size")); + Assertions.assertTrue((Boolean) pluginConfig.getProperties().get("use_fiber")); + Assertions.assertTrue((Boolean) pluginConfig.getProperties().get("share_schedule")); } /** @@ -152,7 +152,7 @@ public void testShutdown() { @Test public void testReset() { WorkerPoolManager.reset(); - Assert.assertNotNull(WorkerPoolManager.getShareScheduler()); + Assertions.assertNotNull(WorkerPoolManager.getShareScheduler()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/handler/TrpcThreadExceptionHandlerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/handler/TrpcThreadExceptionHandlerTest.java index 54d171dcc..4c515a6f3 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/handler/TrpcThreadExceptionHandlerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/handler/TrpcThreadExceptionHandlerTest.java @@ -16,19 +16,19 @@ import com.tencent.trpc.core.exception.TRpcException; import java.sql.SQLException; import java.util.concurrent.atomic.AtomicLong; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TrpcThreadExceptionHandlerTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); ConfigManager.startTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinPoolConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinPoolConfigTest.java index 6d7ce7575..076efd8c8 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinPoolConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinPoolConfigTest.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; public class ForkJoinPoolConfigTest { @@ -31,13 +31,13 @@ public class ForkJoinPoolConfigTest { @Test public void testParse() { ForkJoinPoolConfig forkJoinPoolConfig = ForkJoinPoolConfig.parse(FORK_JOIN_POOL_PLUGIN_NAME, PLUGIN_CONFIG); - Assert.assertNotNull(forkJoinPoolConfig); - Assert.assertEquals(2, forkJoinPoolConfig.getParallelism()); - Assert.assertEquals(10000, forkJoinPoolConfig.getTimeoutMills()); + Assertions.assertNotNull(forkJoinPoolConfig); + Assertions.assertEquals(2, forkJoinPoolConfig.getParallelism()); + Assertions.assertEquals(10000, forkJoinPoolConfig.getTimeoutMills()); PLUGIN_CONFIG.put(ForkJoinPoolConfig.TIMEOUT_MS, 20); forkJoinPoolConfig = ForkJoinPoolConfig.parse(FORK_JOIN_POOL_PLUGIN_NAME, PLUGIN_CONFIG); - Assert.assertEquals(2, forkJoinPoolConfig.getParallelism()); - Assert.assertEquals(20, forkJoinPoolConfig.getTimeoutMills()); + Assertions.assertEquals(2, forkJoinPoolConfig.getParallelism()); + Assertions.assertEquals(20, forkJoinPoolConfig.getTimeoutMills()); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinWorkerPoolTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinWorkerPoolTest.java index fadffa40f..8c33326ba 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinWorkerPoolTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ForkJoinWorkerPoolTest.java @@ -19,8 +19,8 @@ import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ForkJoinPool; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ForkJoinWorkerPoolTest { @@ -45,32 +45,32 @@ public void testForkJoinWorkerPool() { properties); ForkJoinWorkerPool forkJoinWorkerPool = new ForkJoinWorkerPool(); forkJoinWorkerPool.setPluginConfig(poolPluginConfig); - Assert.assertEquals(ForkJoinWorkerPool.NAME, forkJoinWorkerPool.getName()); + Assertions.assertEquals(ForkJoinWorkerPool.NAME, forkJoinWorkerPool.getName()); forkJoinWorkerPool.init(); try { forkJoinWorkerPool.refresh(poolPluginConfig); } catch (Exception e) { - Assert.assertTrue(e instanceof UnsupportedOperationException); + Assertions.assertTrue(e instanceof UnsupportedOperationException); } PoolMXBean report = forkJoinWorkerPool.report(); ForkJoinPoolMXBean forkJoinPoolMXBean = (ForkJoinPoolMXBean) report; - Assert.assertEquals(0, forkJoinPoolMXBean.getPoolSize()); - Assert.assertEquals(0, forkJoinPoolMXBean.getQueuedTaskCount()); - Assert.assertEquals(0, forkJoinPoolMXBean.getQueuedSubmissionCount()); - Assert.assertTrue(forkJoinPoolMXBean.getCommonPoolParallelism() >= 0); - Assert.assertTrue(forkJoinPoolMXBean.getParallelism() >= 0); - Assert.assertEquals(WorkerPoolType.FORK_JOIN.getName(), forkJoinPoolMXBean.getType()); - Assert.assertNotNull(forkJoinPoolMXBean.getObjectName()); - Assert.assertEquals(0, forkJoinPoolMXBean.getRunningThreadCount()); - Assert.assertEquals(0, forkJoinPoolMXBean.getActiveThreadCount()); - Assert.assertEquals(0, forkJoinPoolMXBean.getStealCount()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getPoolSize()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getQueuedTaskCount()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getQueuedSubmissionCount()); + Assertions.assertTrue(forkJoinPoolMXBean.getCommonPoolParallelism() >= 0); + Assertions.assertTrue(forkJoinPoolMXBean.getParallelism() >= 0); + Assertions.assertEquals(WorkerPoolType.FORK_JOIN.getName(), forkJoinPoolMXBean.getType()); + Assertions.assertNotNull(forkJoinPoolMXBean.getObjectName()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getRunningThreadCount()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getActiveThreadCount()); + Assertions.assertEquals(0, forkJoinPoolMXBean.getStealCount()); forkJoinWorkerPool.execute(() -> System.out.println("hello")); Executor executor = forkJoinWorkerPool.toExecutor(); - Assert.assertTrue(executor instanceof ForkJoinPool); + Assertions.assertTrue(executor instanceof ForkJoinPool); forkJoinWorkerPool.destroy(); executor = forkJoinWorkerPool.toExecutor(); ForkJoinPool forkJoinPool = (ForkJoinPool) executor; - Assert.assertTrue(forkJoinPool.isShutdown()); + Assertions.assertTrue(forkJoinPool.isShutdown()); forkJoinWorkerPool.close(0); } } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadPoolConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadPoolConfigTest.java index d08b39fed..cf2230c4d 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadPoolConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadPoolConfigTest.java @@ -11,16 +11,16 @@ package com.tencent.trpc.core.worker.support.thread; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.worker.WorkerPoolManager; 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; public class ThreadPoolConfigTest { @@ -89,13 +89,13 @@ public void testParse() { public void testValidate() { ThreadPoolConfig config = new ThreadPoolConfig(); config.setCorePoolSize(-1); - Assert.assertThrows(IllegalArgumentException.class, config::validate); + Assertions.assertThrows(IllegalArgumentException.class, config::validate); config.setCorePoolSize(0); config.setQueueSize(-1); - Assert.assertThrows(IllegalArgumentException.class, config::validate); + Assertions.assertThrows(IllegalArgumentException.class, config::validate); config.setQueueSize(0); config.setCloseTimeout(-1); - Assert.assertThrows(IllegalArgumentException.class, config::validate); + Assertions.assertThrows(IllegalArgumentException.class, config::validate); config.setCloseTimeout(0); config.validate(); } diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadWorkerPoolTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadWorkerPoolTest.java index 3a4311a62..4b45848e7 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadWorkerPoolTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/support/thread/ThreadWorkerPoolTest.java @@ -20,8 +20,8 @@ import com.tencent.trpc.core.management.ThreadPoolMXBean; 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; public class ThreadWorkerPoolTest { @@ -35,7 +35,7 @@ public void testInit() { ThreadWorkerPool threadWorkerPool = new ThreadWorkerPool(); threadWorkerPool.setPluginConfig(poolPluginConfig); threadWorkerPool.init(); - Assert.assertEquals("work_pool", threadWorkerPool.getName()); + Assertions.assertEquals("work_pool", threadWorkerPool.getName()); threadWorkerPool.execute(() -> { throw new TRpcException(); }); @@ -46,14 +46,14 @@ public void testInit() { threadWorkerPool.init(); PoolMXBean report = threadWorkerPool.report(); ThreadPoolMXBean threadPoolMXBean = (ThreadPoolMXBean) report; - Assert.assertEquals(0, threadPoolMXBean.getPoolSize()); - Assert.assertEquals(0, threadPoolMXBean.getTaskCount()); - Assert.assertEquals(0, threadPoolMXBean.getCompletedTaskCount()); - Assert.assertEquals(0, threadPoolMXBean.getActiveThreadCount()); - Assert.assertEquals(WorkerPoolType.THREAD.getName(), threadPoolMXBean.getType()); - Assert.assertEquals(2, threadPoolMXBean.getCorePoolSize()); - Assert.assertEquals(2, threadPoolMXBean.getMaximumPoolSize()); - Assert.assertNotNull(report.toString()); + Assertions.assertEquals(0, threadPoolMXBean.getPoolSize()); + Assertions.assertEquals(0, threadPoolMXBean.getTaskCount()); + Assertions.assertEquals(0, threadPoolMXBean.getCompletedTaskCount()); + Assertions.assertEquals(0, threadPoolMXBean.getActiveThreadCount()); + Assertions.assertEquals(WorkerPoolType.THREAD.getName(), threadPoolMXBean.getType()); + Assertions.assertEquals(2, threadPoolMXBean.getCorePoolSize()); + Assertions.assertEquals(2, threadPoolMXBean.getMaximumPoolSize()); + Assertions.assertNotNull(report.toString()); } private Map getProperties() { @@ -98,19 +98,19 @@ public void testVirtualThreads() { } PoolMXBean report = threadWorkerPool.report(); ThreadPoolMXBean threadPoolMXBean = (ThreadPoolMXBean) report; - Assert.assertEquals(0, threadPoolMXBean.getPoolSize()); - Assert.assertEquals(0, threadPoolMXBean.getTaskCount()); - Assert.assertEquals(0, threadPoolMXBean.getCompletedTaskCount()); - Assert.assertEquals(0, threadPoolMXBean.getActiveThreadCount()); - Assert.assertEquals(WorkerPoolType.THREAD.getName(), threadPoolMXBean.getType()); + Assertions.assertEquals(0, threadPoolMXBean.getPoolSize()); + Assertions.assertEquals(0, threadPoolMXBean.getTaskCount()); + Assertions.assertEquals(0, threadPoolMXBean.getCompletedTaskCount()); + Assertions.assertEquals(0, threadPoolMXBean.getActiveThreadCount()); + Assertions.assertEquals(WorkerPoolType.THREAD.getName(), threadPoolMXBean.getType()); if (threadPoolMXBean instanceof ThreadPerTaskExecutorMXBeanImpl) { - Assert.assertEquals(0, threadPoolMXBean.getCorePoolSize()); - Assert.assertEquals(Integer.MAX_VALUE, threadPoolMXBean.getMaximumPoolSize()); + Assertions.assertEquals(0, threadPoolMXBean.getCorePoolSize()); + Assertions.assertEquals(Integer.MAX_VALUE, threadPoolMXBean.getMaximumPoolSize()); } else { - Assert.assertEquals(DEFALUT_POOL_SIZE, threadPoolMXBean.getCorePoolSize()); - Assert.assertEquals(DEFALUT_POOL_SIZE, threadPoolMXBean.getMaximumPoolSize()); + Assertions.assertEquals(DEFALUT_POOL_SIZE, threadPoolMXBean.getCorePoolSize()); + Assertions.assertEquals(DEFALUT_POOL_SIZE, threadPoolMXBean.getMaximumPoolSize()); } - Assert.assertNotNull(report.toString()); + Assertions.assertNotNull(report.toString()); } -} \ No newline at end of file +} diff --git a/trpc-core/src/test/java/org/slf4j/TrpcMDCAdapterTest.java b/trpc-core/src/test/java/org/slf4j/TrpcMDCAdapterTest.java index e5d2e1f23..1665379f5 100644 --- a/trpc-core/src/test/java/org/slf4j/TrpcMDCAdapterTest.java +++ b/trpc-core/src/test/java/org/slf4j/TrpcMDCAdapterTest.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; import org.slf4j.spi.MDCAdapter; public class TrpcMDCAdapterTest { @@ -30,6 +30,6 @@ public void testTrpcMDCAdapter() { Map contextMap = new HashMap<>(); adapter.setContextMap(contextMap); adapter.getCopyOfContextMap(); - Assert.assertNotNull(adapter); + Assertions.assertNotNull(adapter); } } From cb67b58bdba120338443d790169e24a76bb90123 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Tue, 20 Jan 2026 11:14:21 +0800 Subject: [PATCH 7/8] feat: optimize trpc-core test --- .../cluster/def/DefClusterInvokerTest.java | 3 + .../common/config/ProviderConfigTest.java | 105 ++++++++++-------- .../trpc/core/rpc/RpcServerMapTest.java | 2 +- .../core/worker/WorkerPoolManagerTest.java | 4 +- 4 files changed, 66 insertions(+), 48 deletions(-) diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java index ac2362fa1..21c798d52 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/def/DefClusterInvokerTest.java @@ -46,8 +46,11 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; @ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class DefClusterInvokerTest { private DefClusterInvoker defClusterInvoker; diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java index 70a374598..809a348ab 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/common/config/ProviderConfigTest.java @@ -21,7 +21,6 @@ import com.google.common.collect.Lists; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.extension.ExtensionLoader; -import com.tencent.trpc.core.filter.FilterManager; import com.tencent.trpc.core.filter.spi.Filter; import com.tencent.trpc.core.registry.MockRegistry; import com.tencent.trpc.core.registry.spi.Registry; @@ -38,11 +37,15 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; @ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class ProviderConfigTest { @BeforeEach @@ -77,50 +80,62 @@ public void testInitServiceInterfaceConfig() { @Test public void testInit() { - Mockito.mockStatic(ExtensionLoader.class); - Mockito.mockStatic(RpcServerManager.class); - ExtensionLoader mock = Mockito.mock(ExtensionLoader.class); - Mockito.when(ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock); - Mockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true); - Mockito.when(ExtensionLoader.getPluginConfigMap()).then(v -> v.callRealMethod()); - ThreadWorkerPool threadWorkerPool = new ThreadWorkerPool(); - threadWorkerPool.setPluginConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_CONFIG); - threadWorkerPool.init(); - Mockito.when(ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock); - Mockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool); - Filter mockFilter = Mockito.mock(Filter.class); - Mockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter); - ExtensionLoader.getExtensionLoader(Filter.class); - ServiceConfig serviceConfig = new ServiceConfig(); - serviceConfig.setName("protoid"); - serviceConfig.setIp("127.0.0.1"); - serviceConfig.setFilters(Lists.newArrayList("filterId")); - ProviderConfig config = ProviderConfig.newInstance(); - serviceConfig.addProviderConfig(config); - config.setServiceInterface(Object.class); - config.setServiceConfig(serviceConfig); - config.setRef(new Object()); - Map configMap = new HashMap<>(); - Map extMap = new HashMap<>(); - extMap.put("address_list", "10.0.0.1"); - configMap.put("registyId", new PluginConfig("registyId", MockRegistry.class, extMap)); - ConfigManager.getInstance().getPluginConfigMap().put(Registry.class, configMap); - config.init(); - RpcServer rpcServerMock = Mockito.mock(RpcServer.class); - Mockito.when(RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid()))) - .thenReturn(rpcServerMock); - Mockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig()); - serviceConfig.export(); - Mockito.verify(rpcServerMock, Mockito.times(1)).export(Mockito.any(ProviderInvoker.class)); - Mockito.verify(rpcServerMock, Mockito.times(1)).open(); - assertTrue(serviceConfig.isExported()); - serviceConfig.unExport(); - assertFalse(serviceConfig.isExported()); - ExtensionLoader mockRegistryLoader = Mockito.mock(ExtensionLoader.class); - Mockito.when(ExtensionLoader.getExtensionLoader(Registry.class)) - .thenReturn(mockRegistryLoader); - Registry registry = Mockito.mock(Registry.class); - Mockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry); + try (MockedStatic loaderMockedStatic = Mockito.mockStatic(ExtensionLoader.class); + MockedStatic managerMockedStatic = Mockito.mockStatic(RpcServerManager.class)) { + + ExtensionLoader mock = Mockito.mock(ExtensionLoader.class); + loaderMockedStatic.when(() -> ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock); + Mockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true); + loaderMockedStatic.when(ExtensionLoader::getPluginConfigMap).thenCallRealMethod(); + + ThreadWorkerPool threadWorkerPool = new ThreadWorkerPool(); + threadWorkerPool.setPluginConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_CONFIG); + threadWorkerPool.init(); + loaderMockedStatic.when(() -> ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock); + Mockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool); + + Filter mockFilter = Mockito.mock(Filter.class); + Mockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter); + + ServiceConfig serviceConfig = new ServiceConfig(); + serviceConfig.setName("protoid"); + serviceConfig.setIp("127.0.0.1"); + serviceConfig.setFilters(Lists.newArrayList("filterId")); + + ProviderConfig config = ProviderConfig.newInstance(); + serviceConfig.addProviderConfig(config); + config.setServiceInterface(Object.class); + config.setServiceConfig(serviceConfig); + config.setRef(new Object()); + + Map configMap = new HashMap<>(); + Map extMap = new HashMap<>(); + extMap.put("address_list", "10.0.0.1"); + configMap.put("registyId", new PluginConfig("registyId", MockRegistry.class, extMap)); + ConfigManager.getInstance().getPluginConfigMap().put(Registry.class, configMap); + config.init(); + + RpcServer rpcServerMock = Mockito.mock(RpcServer.class); + managerMockedStatic.when(() -> RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid()))) + .thenReturn(rpcServerMock); + Mockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig()); + Mockito.doNothing().when(rpcServerMock).export(Mockito.any(ProviderInvoker.class)); + Mockito.doNothing().when(rpcServerMock).open(); + + serviceConfig.export(); + Mockito.verify(rpcServerMock, Mockito.times(1)).export(Mockito.any(ProviderInvoker.class)); + Mockito.verify(rpcServerMock, Mockito.times(1)).open(); + assertTrue(serviceConfig.isExported()); + + serviceConfig.unExport(); + assertFalse(serviceConfig.isExported()); + + ExtensionLoader mockRegistryLoader = Mockito.mock(ExtensionLoader.class); + loaderMockedStatic.when(() -> ExtensionLoader.getExtensionLoader(Registry.class)) + .thenReturn(mockRegistryLoader); + Registry registry = Mockito.mock(Registry.class); + Mockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry); + } } @Test diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java index 70a68dbac..2540925c6 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/rpc/RpcServerMapTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java index 4bec25e47..d69c03a01 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/worker/WorkerPoolManagerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -107,7 +107,7 @@ public void testWorkPool() { this.testRegistDefaultPluginConfig(); PluginConfig pluginConfig = WorkerPoolManager .newThreadWorkerPoolConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME, - 20,20, Boolean.FALSE); + 20, 20, Boolean.FALSE); WorkerPoolManager.refresh(WorkerPoolManager.DEF_NAMING_WORKER_POOL_NAME, pluginConfig); WorkerPool workerPool = WorkerPoolManager.get(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_NAME); Assertions.assertNotNull(workerPool); From 0025a5b9110cafc18ce2eba06750914fdb0356f6 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Tue, 20 Jan 2026 11:21:38 +0800 Subject: [PATCH 8/8] feat: optimize ci and codecov --- .github/codecov.yml | 19 +++++++++----- .github/workflows/ci.yml | 40 +++--------------------------- .github/workflows/merge.yml | 6 ++--- .github/workflows/pull_request.yml | 4 +-- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index e47606237..3a20ca07f 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -5,13 +5,20 @@ comment: coverage: # https://docs.codecov.com/docs/codecovyml-reference#coverage precision: 5 - range: - - 70.0 - - 75.0 + range: "80...100" status: project: default: branches: - - ^master$ - target: 70.0 # the minimum coverage ratio that the commit must meet to be considered a success. - threshold: 1% # allow the coverage to drop by X%, and posting a success status. \ No newline at end of file + - ^JDK17/Springboot3$ + target: 80.0 + threshold: 1% + ignore: + - "**/test/**" + - "**/*Test.java" + - "**/*AuthCenter.java" + - "**/*QappPackage.java" + - "**/*TRPCProtocol.java" +parsers: + jacoco: + partials_as_hits: true \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d2383aa2..82be6786b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,28 +10,12 @@ name: Maven Install Test on: push: - branches: [ "master" ] + branches: [ "JDK17/Springboot3" ] pull_request: - branches: [ "master" ] + branches: [ "JDK17/Springboot3" ] schedule: - cron: '0 9 * * *' jobs: - JDK8: - runs-on: ubuntu-latest - steps: - - name: Checkout codes - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - - name: Test with Maven - run: mvn clean install -Dmaven.test.skip=true -B -U --file pom.xml JDK17: runs-on: ubuntu-latest steps: @@ -64,29 +48,13 @@ jobs: cache: maven - name: Test with Maven run: mvn clean install -Dmaven.test.skip=true -B -U --file pom.xml - JDK8-master: - runs-on: ubuntu-latest - steps: - - name: Checkout codes - uses: actions/checkout@v3 - with: - ref: "master" - repository: trpc-group/trpc-java - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - - name: Test with Maven - run: mvn clean install -Dmaven.test.skip=true -B -U --file pom.xml JDK17-master: runs-on: ubuntu-latest steps: - name: Checkout codes uses: actions/checkout@v3 with: - ref: "master" + ref: "JDK17/Springboot3" repository: trpc-group/trpc-java - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -102,7 +70,7 @@ jobs: - name: Checkout codes uses: actions/checkout@v3 with: - ref: "master" + ref: "JDK17/Springboot3" repository: trpc-group/trpc-java - name: Set up JDK 21 uses: actions/setup-java@v3 diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 0d4453983..24fb05543 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -10,7 +10,7 @@ name: Java CI with Maven on: push: - branches: [ "master" ] + branches: [ "JDK17/Springboot3" ] schedule: - cron: '0 9 * * *' jobs: @@ -19,10 +19,10 @@ jobs: steps: - name: Checkout codes uses: actions/checkout@v3 - - name: Set up JDK 8 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '17' distribution: 'temurin' cache: maven - name: Test with Maven diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8acdf7a14..1bfdd3d47 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,10 +20,10 @@ jobs: with: ref: ${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Set up JDK 8 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '17' distribution: 'temurin' cache: maven - name: Test with Maven