(), group);
- Assert.fail();
+ fail();
} catch (NacosException e) {
- Assert.assertEquals("dataIds invalid", e.getMessage());
+ assertEquals("dataIds invalid", e.getMessage());
}
try {
@@ -164,9 +166,9 @@ public void testCheckKeyParam3() throws NacosException {
group = "c";
ParamUtils.checkKeyParam(Arrays.asList(dataId), group);
- Assert.fail();
+ fail();
} catch (NacosException e) {
- Assert.assertEquals("dataId invalid", e.getMessage());
+ assertEquals("dataId invalid", e.getMessage());
}
try {
@@ -174,33 +176,34 @@ public void testCheckKeyParam3() throws NacosException {
group = "";
ParamUtils.checkKeyParam(Arrays.asList(dataId), group);
- Assert.fail();
+ fail();
} catch (NacosException e) {
- Assert.assertEquals("group invalid", e.getMessage());
+ assertEquals("group invalid", e.getMessage());
}
}
@Test
- public void testCheckParam() throws NacosException {
+ void testCheckParam() throws NacosException {
String dataId = "b";
String group = "c";
String content = "a";
ParamUtils.checkParam(dataId, group, content);
}
-
+
@Test
- public void testCheckParamFail() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("content invalid");
-
- String dataId = "b";
- String group = "c";
- String content = "";
- ParamUtils.checkParam(dataId, group, content);
+ void testCheckParamFail() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+
+ String dataId = "b";
+ String group = "c";
+ String content = "";
+ ParamUtils.checkParam(dataId, group, content);
+ });
+ assertTrue(exception.getMessage().contains("content invalid"));
}
@Test
- public void testCheckParam2() throws NacosException {
+ void testCheckParam2() throws NacosException {
String dataId = "b";
String group = "c";
String datumId = "d";
@@ -209,60 +212,65 @@ public void testCheckParam2() throws NacosException {
}
@Test
- public void testCheckParam2Fail() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("content invalid");
-
- String dataId = "b";
- String group = "c";
- String datumId = "d";
- String content = "";
- ParamUtils.checkParam(dataId, group, datumId, content);
+ void testCheckParam2Fail() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+
+ String dataId = "b";
+ String group = "c";
+ String datumId = "d";
+ String content = "";
+ ParamUtils.checkParam(dataId, group, datumId, content);
+ });
+ assertTrue(exception.getMessage().contains("content invalid"));
}
@Test
- public void testCheckTenant() throws NacosException {
+ void testCheckTenant() throws NacosException {
String tenant = "a";
ParamUtils.checkTenant(tenant);
}
@Test
- public void testCheckTenantFail() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("tenant invalid");
- String tenant = "";
- ParamUtils.checkTenant(tenant);
+ void testCheckTenantFail() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+ String tenant = "";
+ ParamUtils.checkTenant(tenant);
+ });
+ assertTrue(exception.getMessage().contains("tenant invalid"));
}
@Test
- public void testCheckBetaIps() throws NacosException {
+ void testCheckBetaIps() throws NacosException {
ParamUtils.checkBetaIps("127.0.0.1");
}
@Test
- public void testCheckBetaIpsFail1() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("betaIps invalid");
-
- ParamUtils.checkBetaIps("");
+ void testCheckBetaIpsFail1() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+
+ ParamUtils.checkBetaIps("");
+ });
+ assertTrue(exception.getMessage().contains("betaIps invalid"));
}
@Test
- public void testCheckBetaIpsFail2() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("betaIps invalid");
- ParamUtils.checkBetaIps("aaa");
+ void testCheckBetaIpsFail2() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+ ParamUtils.checkBetaIps("aaa");
+ });
+ assertTrue(exception.getMessage().contains("betaIps invalid"));
}
@Test
- public void testCheckContent() throws NacosException {
+ void testCheckContent() throws NacosException {
ParamUtils.checkContent("aaa");
}
@Test
- public void testCheckContentFail() throws NacosException {
- exceptionRule.expect(NacosException.class);
- exceptionRule.expectMessage("content invalid");
- ParamUtils.checkContent("");
+ void testCheckContentFail() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+ ParamUtils.checkContent("");
+ });
+ assertTrue(exception.getMessage().contains("content invalid"));
}
}
\ No newline at end of file
diff --git a/client/src/test/java/com/alibaba/nacos/client/config/utils/SnapShotSwitchTest.java b/client/src/test/java/com/alibaba/nacos/client/config/utils/SnapShotSwitchTest.java
index 13ad8f4364e..2e0990db99f 100644
--- a/client/src/test/java/com/alibaba/nacos/client/config/utils/SnapShotSwitchTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/config/utils/SnapShotSwitchTest.java
@@ -18,21 +18,23 @@
package com.alibaba.nacos.client.config.utils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class SnapShotSwitchTest {
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SnapShotSwitchTest {
@Test
- public void testGetIsSnapShot() {
+ void testGetIsSnapShot() {
Boolean isSnapShot = SnapShotSwitch.getIsSnapShot();
- Assert.assertTrue(isSnapShot);
+ assertTrue(isSnapShot);
SnapShotSwitch.setIsSnapShot(false);
- Assert.assertFalse(SnapShotSwitch.getIsSnapShot());
+ assertFalse(SnapShotSwitch.getIsSnapShot());
SnapShotSwitch.setIsSnapShot(true);
- Assert.assertTrue(SnapShotSwitch.getIsSnapShot());
+ assertTrue(SnapShotSwitch.getIsSnapShot());
}
}
\ No newline at end of file
diff --git a/client/src/test/java/com/alibaba/nacos/client/env/NacosClientPropertiesTest.java b/client/src/test/java/com/alibaba/nacos/client/env/NacosClientPropertiesTest.java
index ce696d99b3c..ce047577211 100644
--- a/client/src/test/java/com/alibaba/nacos/client/env/NacosClientPropertiesTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/env/NacosClientPropertiesTest.java
@@ -16,34 +16,39 @@
package com.alibaba.nacos.client.env;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.util.Properties;
-public class NacosClientPropertiesTest {
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class NacosClientPropertiesTest {
- @BeforeClass
- public static void init() {
+ @BeforeAll
+ static void init() {
System.setProperty("nacos.env.first", "jvm");
}
- @AfterClass
- public static void teardown() {
+ @AfterAll
+ static void teardown() {
System.clearProperty("nacos.env.first");
}
@Test
- public void testGetProperty() {
+ void testGetProperty() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.home", "/home/nacos");
final String value = NacosClientProperties.PROTOTYPE.getProperty("nacos.home");
- Assert.assertEquals("/home/nacos", value);
+ assertEquals("/home/nacos", value);
}
@Test
- public void testGetPropertyMultiLayer() {
+ void testGetPropertyMultiLayer() {
NacosClientProperties.PROTOTYPE.setProperty("top.layer", "top");
@@ -57,85 +62,85 @@ public void testGetPropertyMultiLayer() {
layerCEnv.setProperty("c.layer", "c");
String value = layerCEnv.getProperty("c.layer");
- Assert.assertEquals("c", value);
+ assertEquals("c", value);
value = layerCEnv.getProperty("b.layer");
- Assert.assertEquals("b", value);
+ assertEquals("b", value);
value = layerCEnv.getProperty("a.layer");
- Assert.assertEquals("a", value);
+ assertEquals("a", value);
value = layerCEnv.getProperty("top.layer");
- Assert.assertEquals("top", value);
+ assertEquals("top", value);
}
@Test
- public void testGetPropertyDefaultValue() {
+ void testGetPropertyDefaultValue() {
final String value = NacosClientProperties.PROTOTYPE.getProperty("nacos.home.default", "/home/default_value");
- Assert.assertEquals("/home/default_value", value);
+ assertEquals("/home/default_value", value);
}
@Test
- public void testGetBoolean() {
+ void testGetBoolean() {
NacosClientProperties.PROTOTYPE.setProperty("use.cluster", "true");
final Boolean value = NacosClientProperties.PROTOTYPE.getBoolean("use.cluster");
- Assert.assertTrue(value);
+ assertTrue(value);
}
@Test
- public void testGetBooleanDefaultValue() {
+ void testGetBooleanDefaultValue() {
final Boolean value = NacosClientProperties.PROTOTYPE.getBoolean("use.cluster.default", false);
- Assert.assertFalse(value);
+ assertFalse(value);
}
@Test
- public void testGetInteger() {
+ void testGetInteger() {
NacosClientProperties.PROTOTYPE.setProperty("max.timeout", "200");
final Integer value = NacosClientProperties.PROTOTYPE.getInteger("max.timeout");
- Assert.assertEquals(200, value.intValue());
+ assertEquals(200, value.intValue());
}
@Test
- public void testGetIntegerDefaultValue() {
+ void testGetIntegerDefaultValue() {
final Integer value = NacosClientProperties.PROTOTYPE.getInteger("max.timeout.default", 400);
- Assert.assertEquals(400, value.intValue());
+ assertEquals(400, value.intValue());
}
@Test
- public void testGetLong() {
+ void testGetLong() {
NacosClientProperties.PROTOTYPE.setProperty("connection.timeout", "200");
final Long value = NacosClientProperties.PROTOTYPE.getLong("connection.timeout");
- Assert.assertEquals(200L, value.longValue());
+ assertEquals(200L, value.longValue());
}
@Test
- public void testGetLongDefault() {
+ void testGetLongDefault() {
final Long value = NacosClientProperties.PROTOTYPE.getLong("connection.timeout.default", 400L);
- Assert.assertEquals(400L, value.longValue());
+ assertEquals(400L, value.longValue());
}
@Test
- public void setProperty() {
+ void setProperty() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.set.property", "true");
final String ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.set.property");
- Assert.assertEquals("true", ret);
+ assertEquals("true", ret);
}
@Test
- public void setPropertyWithScope() {
+ void setPropertyWithScope() {
final NacosClientProperties properties = NacosClientProperties.PROTOTYPE.derive();
properties.setProperty("nacos.set.property.scope", "config");
String ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.set.property.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
ret = properties.getProperty("nacos.set.property.scope");
- Assert.assertEquals("config", ret);
+ assertEquals("config", ret);
}
@Test
- public void testAddProperties() {
+ void testAddProperties() {
Properties properties = new Properties();
properties.setProperty("nacos.add.properties", "true");
@@ -143,11 +148,11 @@ public void testAddProperties() {
final String ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.add.properties");
- Assert.assertEquals("true", ret);
+ assertEquals("true", ret);
}
@Test
- public void testAddPropertiesWithScope() {
+ void testAddPropertiesWithScope() {
Properties properties = new Properties();
properties.setProperty("nacos.add.properties.scope", "config");
@@ -156,15 +161,15 @@ public void testAddPropertiesWithScope() {
nacosClientProperties.addProperties(properties);
String ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.add.properties.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
ret = nacosClientProperties.getProperty("nacos.add.properties.scope");
- Assert.assertEquals("config", ret);
+ assertEquals("config", ret);
}
@Test
- public void testTestDerive() {
+ void testTestDerive() {
Properties properties = new Properties();
properties.setProperty("nacos.derive.properties.scope", "derive");
@@ -172,23 +177,23 @@ public void testTestDerive() {
final String value = nacosClientProperties.getProperty("nacos.derive.properties.scope");
- Assert.assertEquals("derive", value);
+ assertEquals("derive", value);
}
@Test
- public void testContainsKey() {
+ void testContainsKey() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.contains.key", "true");
boolean ret = NacosClientProperties.PROTOTYPE.containsKey("nacos.contains.key");
- Assert.assertTrue(ret);
+ assertTrue(ret);
ret = NacosClientProperties.PROTOTYPE.containsKey("nacos.contains.key.in.sys");
- Assert.assertFalse(ret);
+ assertFalse(ret);
}
@Test
- public void testContainsKeyMultiLayers() {
+ void testContainsKeyMultiLayers() {
NacosClientProperties.PROTOTYPE.setProperty("top.layer", "top");
@@ -202,49 +207,49 @@ public void testContainsKeyMultiLayers() {
layerCEnv.setProperty("c.layer", "c");
boolean exist = layerCEnv.containsKey("c.layer");
- Assert.assertTrue(exist);
+ assertTrue(exist);
exist = layerCEnv.containsKey("b.layer");
- Assert.assertTrue(exist);
+ assertTrue(exist);
exist = layerCEnv.containsKey("a.layer");
- Assert.assertTrue(exist);
+ assertTrue(exist);
exist = layerCEnv.containsKey("top.layer");
- Assert.assertTrue(exist);
+ assertTrue(exist);
}
@Test
- public void testContainsKeyWithScope() {
+ void testContainsKeyWithScope() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.contains.global.scope", "global");
final NacosClientProperties namingProperties = NacosClientProperties.PROTOTYPE.derive();
namingProperties.setProperty("nacos.contains.naming.scope", "naming");
boolean ret = NacosClientProperties.PROTOTYPE.containsKey("nacos.contains.global.scope");
- Assert.assertTrue(ret);
+ assertTrue(ret);
ret = NacosClientProperties.PROTOTYPE.containsKey("nacos.contains.naming.scope");
- Assert.assertFalse(ret);
+ assertFalse(ret);
ret = namingProperties.containsKey("nacos.contains.naming.scope");
- Assert.assertTrue(ret);
+ assertTrue(ret);
ret = namingProperties.containsKey("nacos.contains.global.scope");
- Assert.assertTrue(ret);
+ assertTrue(ret);
}
@Test
- public void testAsProperties() {
+ void testAsProperties() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.as.properties", "true");
final Properties properties = NacosClientProperties.PROTOTYPE.asProperties();
- Assert.assertNotNull(properties);
- Assert.assertEquals("true", properties.getProperty("nacos.as.properties"));
+ assertNotNull(properties);
+ assertEquals("true", properties.getProperty("nacos.as.properties"));
}
@Test
- public void testAsPropertiesWithScope() {
+ void testAsPropertiesWithScope() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.as.properties.global.scope", "global");
NacosClientProperties.PROTOTYPE.setProperty("nacos.server.addr.scope", "global");
@@ -253,17 +258,17 @@ public void testAsPropertiesWithScope() {
configProperties.setProperty("nacos.server.addr.scope", "config");
final Properties properties = configProperties.asProperties();
- Assert.assertNotNull(properties);
+ assertNotNull(properties);
String ret = properties.getProperty("nacos.as.properties.global.scope");
- Assert.assertEquals("global", ret);
+ assertEquals("global", ret);
ret = properties.getProperty("nacos.server.addr.scope");
- Assert.assertEquals("config", ret);
+ assertEquals("config", ret);
}
@Test
- public void testGetPropertyWithScope() {
+ void testGetPropertyWithScope() {
NacosClientProperties.PROTOTYPE.setProperty("nacos.global.scope", "global");
@@ -274,41 +279,40 @@ public void testGetPropertyWithScope() {
namingProperties.setProperty("nacos.naming.scope", "naming");
String ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.global.scope");
- Assert.assertEquals("global", ret);
+ assertEquals("global", ret);
ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.config.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
ret = NacosClientProperties.PROTOTYPE.getProperty("nacos.naming.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
ret = configProperties.getProperty("nacos.config.scope");
- Assert.assertEquals("config", ret);
+ assertEquals("config", ret);
ret = configProperties.getProperty("nacos.global.scope");
- Assert.assertEquals("global", ret);
+ assertEquals("global", ret);
ret = configProperties.getProperty("nacos.naming.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
ret = namingProperties.getProperty("nacos.naming.scope");
- Assert.assertEquals("naming", ret);
+ assertEquals("naming", ret);
ret = namingProperties.getProperty("nacos.global.scope");
- Assert.assertEquals("global", ret);
+ assertEquals("global", ret);
ret = namingProperties.getProperty("nacos.config.scope");
- Assert.assertNull(ret);
+ assertNull(ret);
}
@Test
- public void testGetPropertyFrom() {
+ void testGetPropertyFrom() {
System.setProperty("nacos.home.default.test", "/home/jvm_args");
NacosClientProperties.PROTOTYPE.setProperty("nacos.home.default.test", "/home/properties_args");
- Assert.assertEquals(NacosClientProperties.PROTOTYPE.getPropertyFrom(SourceType.JVM, "nacos.home.default.test"),
- "/home/jvm_args");
- Assert.assertEquals(
- NacosClientProperties.PROTOTYPE.getPropertyFrom(SourceType.PROPERTIES, "nacos.home.default.test"),
- "/home/properties_args");
- Assert.assertEquals(NacosClientProperties.PROTOTYPE.getPropertyFrom(null, "nacos.home.default.test"),
+ assertEquals("/home/jvm_args",
+ NacosClientProperties.PROTOTYPE.getPropertyFrom(SourceType.JVM, "nacos.home.default.test"));
+ assertEquals("/home/properties_args",
+ NacosClientProperties.PROTOTYPE.getPropertyFrom(SourceType.PROPERTIES, "nacos.home.default.test"));
+ assertEquals(NacosClientProperties.PROTOTYPE.getPropertyFrom(null, "nacos.home.default.test"),
NacosClientProperties.PROTOTYPE.getProperty("nacos.home.default.test"));
}
diff --git a/client/src/test/java/com/alibaba/nacos/client/env/SearchablePropertiesTest.java b/client/src/test/java/com/alibaba/nacos/client/env/SearchablePropertiesTest.java
index 5518884b21a..d4f52428fbb 100644
--- a/client/src/test/java/com/alibaba/nacos/client/env/SearchablePropertiesTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/env/SearchablePropertiesTest.java
@@ -17,59 +17,59 @@
package com.alibaba.nacos.client.env;
import com.alibaba.nacos.client.constant.Constants;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
-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;
/**
* Additional test cases for SearchableProperties.
*
* Common cases see {@link NacosClientPropertiesTest}.
*/
-public class SearchablePropertiesTest {
+class SearchablePropertiesTest {
Method initMethod;
- @BeforeClass
- public static void init() {
+ @BeforeAll
+ static void init() {
System.setProperty(Constants.SysEnv.NACOS_ENV_FIRST, "jvm");
}
- @Before
- public void setUp() throws Exception {
+ @AfterAll
+ static void teardown() {
+ System.clearProperty(Constants.SysEnv.NACOS_ENV_FIRST);
+ }
+
+ @BeforeEach
+ void setUp() throws Exception {
initMethod = SearchableProperties.class.getDeclaredMethod("init");
initMethod.setAccessible(true);
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
init();
initMethod.invoke(null);
}
- @AfterClass
- public static void teardown() {
- System.clearProperty(Constants.SysEnv.NACOS_ENV_FIRST);
- }
-
@Test
- public void testInitWithInvalidOrder() throws IllegalAccessException, InvocationTargetException {
+ void testInitWithInvalidOrder() throws IllegalAccessException, InvocationTargetException {
System.setProperty(Constants.SysEnv.NACOS_ENV_FIRST, "invalid");
List order = (List) initMethod.invoke(null);
assertOrder(order, SourceType.PROPERTIES, SourceType.JVM, SourceType.ENV);
}
@Test
- public void testInitWithoutSpecifiedOrder() throws IllegalAccessException, InvocationTargetException {
+ void testInitWithoutSpecifiedOrder() throws IllegalAccessException, InvocationTargetException {
System.clearProperty(Constants.SysEnv.NACOS_ENV_FIRST);
List order = (List) initMethod.invoke(null);
assertOrder(order, SourceType.PROPERTIES, SourceType.JVM, SourceType.ENV);
@@ -83,7 +83,7 @@ private void assertOrder(List order, SourceType... sourceTypes) {
}
@Test
- public void testGetPropertyFromEnv() {
+ void testGetPropertyFromEnv() {
System.setProperty("testFromSource", "jvm");
NacosClientProperties properties = SearchableProperties.INSTANCE.derive();
properties.setProperty("testFromSource", "properties");
@@ -91,7 +91,7 @@ public void testGetPropertyFromEnv() {
}
@Test
- public void testGetPropertyFromUnknown() {
+ void testGetPropertyFromUnknown() {
System.setProperty("testFromSource", "jvm");
NacosClientProperties properties = SearchableProperties.INSTANCE.derive();
properties.setProperty("testFromSource", "properties");
diff --git a/client/src/test/java/com/alibaba/nacos/client/env/SystemEnvPropertySourceTest.java b/client/src/test/java/com/alibaba/nacos/client/env/SystemEnvPropertySourceTest.java
index 89361fc68a2..89d1ad6604b 100644
--- a/client/src/test/java/com/alibaba/nacos/client/env/SystemEnvPropertySourceTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/env/SystemEnvPropertySourceTest.java
@@ -16,28 +16,28 @@
package com.alibaba.nacos.client.env;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Additional test cases for SystemEnvPropertySource.
*
* Common cases see {@link NacosClientPropertiesTest}.
*/
-public class SystemEnvPropertySourceTest {
+class SystemEnvPropertySourceTest {
SystemEnvPropertySource systemEnvPropertySource;
private Map mockEnvMap;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
systemEnvPropertySource = new SystemEnvPropertySource();
mockEnvMap = new HashMap<>();
Field envField = SystemEnvPropertySource.class.getDeclaredField("env");
@@ -50,42 +50,42 @@ public void setUp() throws Exception {
}
@Test
- public void testGetEnvForLowerCaseKey() {
+ void testGetEnvForLowerCaseKey() {
assertEquals("value1", systemEnvPropertySource.getProperty("testcase1"));
}
@Test
- public void testGetEnvForLowerCaseKeyWithDot() {
+ void testGetEnvForLowerCaseKeyWithDot() {
assertEquals("value2", systemEnvPropertySource.getProperty("test.case.2"));
}
@Test
- public void testGetEnvForLowerCaseKeyWithHyphen() {
+ void testGetEnvForLowerCaseKeyWithHyphen() {
assertEquals("value2", systemEnvPropertySource.getProperty("test-case-2"));
}
@Test
- public void testGetEnvForLowerCaseKeyWithHyphenAndDot() {
+ void testGetEnvForLowerCaseKeyWithHyphenAndDot() {
assertEquals("value2", systemEnvPropertySource.getProperty("test.case-2"));
}
@Test
- public void testGetEnvForUpperCaseKey() {
+ void testGetEnvForUpperCaseKey() {
assertEquals("value3", systemEnvPropertySource.getProperty("TESTCASE3"));
}
@Test
- public void testGetEnvForUpperCaseKeyWithDot() {
+ void testGetEnvForUpperCaseKeyWithDot() {
assertEquals("value4", systemEnvPropertySource.getProperty("TEST.CASE.4"));
}
@Test
- public void testGetEnvForUpperCaseKeyWithHyphen() {
+ void testGetEnvForUpperCaseKeyWithHyphen() {
assertEquals("value4", systemEnvPropertySource.getProperty("TEST-CASE-4"));
}
@Test
- public void testGetEnvForUpperCaseKeyWithHyphenAndDot() {
+ void testGetEnvForUpperCaseKeyWithHyphenAndDot() {
assertEquals("value4", systemEnvPropertySource.getProperty("TEST_CASE.4"));
}
}
\ No newline at end of file
diff --git a/client/src/test/java/com/alibaba/nacos/client/env/convert/CompositeConverterTest.java b/client/src/test/java/com/alibaba/nacos/client/env/convert/CompositeConverterTest.java
index a248a42eed6..8d200e29a29 100644
--- a/client/src/test/java/com/alibaba/nacos/client/env/convert/CompositeConverterTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/env/convert/CompositeConverterTest.java
@@ -16,42 +16,45 @@
package com.alibaba.nacos.client.env.convert;
-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;
import java.util.MissingFormatArgumentException;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class CompositeConverterTest {
+class CompositeConverterTest {
CompositeConverter compositeConverter;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
compositeConverter = new CompositeConverter();
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
}
- @Test(expected = MissingFormatArgumentException.class)
- public void testConvertNotSupportType() {
- compositeConverter.convert("test", CompositeConverter.class);
+ @Test
+ void testConvertNotSupportType() {
+ assertThrows(MissingFormatArgumentException.class, () -> {
+ compositeConverter.convert("test", CompositeConverter.class);
+ });
}
@Test
- public void testConvertBooleanForEmptyProperty() {
+ void testConvertBooleanForEmptyProperty() {
assertNull(compositeConverter.convert(null, Boolean.class));
}
@Test
- public void testConvertBooleanTrue() {
+ void testConvertBooleanTrue() {
assertTrue(compositeConverter.convert("true", Boolean.class));
assertTrue(compositeConverter.convert("on", Boolean.class));
assertTrue(compositeConverter.convert("yes", Boolean.class));
@@ -59,49 +62,57 @@ public void testConvertBooleanTrue() {
}
@Test
- public void testConvertBooleanFalse() {
+ void testConvertBooleanFalse() {
assertFalse(compositeConverter.convert("false", Boolean.class));
assertFalse(compositeConverter.convert("off", Boolean.class));
assertFalse(compositeConverter.convert("no", Boolean.class));
assertFalse(compositeConverter.convert("0", Boolean.class));
}
- @Test(expected = IllegalArgumentException.class)
- public void testConvertBooleanIllegal() {
- compositeConverter.convert("aaa", Boolean.class);
+ @Test
+ void testConvertBooleanIllegal() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ compositeConverter.convert("aaa", Boolean.class);
+ });
}
@Test
- public void testConvertIntegerForEmptyProperty() {
+ void testConvertIntegerForEmptyProperty() {
assertNull(compositeConverter.convert(null, Integer.class));
}
@Test
- public void testConvertInteger() {
+ void testConvertInteger() {
assertEquals(100, (int) compositeConverter.convert("100", Integer.class));
- assertEquals(Integer.MAX_VALUE, (int) compositeConverter.convert(String.valueOf(Integer.MAX_VALUE), Integer.class));
- assertEquals(Integer.MIN_VALUE, (int) compositeConverter.convert(String.valueOf(Integer.MIN_VALUE), Integer.class));
+ assertEquals(Integer.MAX_VALUE,
+ (int) compositeConverter.convert(String.valueOf(Integer.MAX_VALUE), Integer.class));
+ assertEquals(Integer.MIN_VALUE,
+ (int) compositeConverter.convert(String.valueOf(Integer.MIN_VALUE), Integer.class));
}
- @Test(expected = IllegalArgumentException.class)
- public void testConvertIntegerIllegal() {
- compositeConverter.convert("aaa", Integer.class);
+ @Test
+ void testConvertIntegerIllegal() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ compositeConverter.convert("aaa", Integer.class);
+ });
}
@Test
- public void testConvertLongForEmptyProperty() {
+ void testConvertLongForEmptyProperty() {
assertNull(compositeConverter.convert(null, Long.class));
}
@Test
- public void testConvertLong() {
+ void testConvertLong() {
assertEquals(100L, (long) compositeConverter.convert("100", Long.class));
assertEquals(Long.MAX_VALUE, (long) compositeConverter.convert(String.valueOf(Long.MAX_VALUE), Long.class));
assertEquals(Long.MIN_VALUE, (long) compositeConverter.convert(String.valueOf(Long.MIN_VALUE), Long.class));
}
- @Test(expected = IllegalArgumentException.class)
- public void testConvertLongIllegal() {
- compositeConverter.convert("aaa", Long.class);
+ @Test
+ void testConvertLongIllegal() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ compositeConverter.convert("aaa", Long.class);
+ });
}
}
\ No newline at end of file
diff --git a/client/src/test/java/com/alibaba/nacos/client/logging/NacosLoggingTest.java b/client/src/test/java/com/alibaba/nacos/client/logging/NacosLoggingTest.java
index b2d94d42404..bdd3f4d9701 100644
--- a/client/src/test/java/com/alibaba/nacos/client/logging/NacosLoggingTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/logging/NacosLoggingTest.java
@@ -20,21 +20,21 @@
import com.alibaba.nacos.common.logging.NacosLoggingAdapter;
import com.alibaba.nacos.common.logging.NacosLoggingProperties;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+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.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Field;
import java.util.Properties;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.doThrow;
-@RunWith(MockitoJUnitRunner.class)
-public class NacosLoggingTest {
+@ExtendWith(MockitoExtension.class)
+class NacosLoggingTest {
@Mock
NacosLoggingAdapter loggingAdapter;
@@ -43,8 +43,8 @@ public class NacosLoggingTest {
NacosLogging instance;
- @Before
- public void setUp() throws NoSuchFieldException, IllegalAccessException {
+ @BeforeEach
+ void setUp() throws NoSuchFieldException, IllegalAccessException {
loggingProperties = new NacosLoggingProperties("", new Properties());
instance = NacosLogging.getInstance();
Field loggingPropertiesField = NacosLogging.class.getDeclaredField("loggingProperties");
@@ -53,13 +53,13 @@ public void setUp() throws NoSuchFieldException, IllegalAccessException {
}
@Test
- public void testGetInstance() {
+ void testGetInstance() {
NacosLogging instance = NacosLogging.getInstance();
- Assert.assertNotNull(instance);
+ assertNotNull(instance);
}
@Test
- public void testLoadConfiguration() throws NoSuchFieldException, IllegalAccessException {
+ void testLoadConfiguration() throws NoSuchFieldException, IllegalAccessException {
instance = NacosLogging.getInstance();
Field nacosLogging = NacosLogging.class.getDeclaredField("loggingAdapter");
nacosLogging.setAccessible(true);
@@ -69,7 +69,7 @@ public void testLoadConfiguration() throws NoSuchFieldException, IllegalAccessEx
}
@Test
- public void testLoadConfigurationWithException() throws NoSuchFieldException, IllegalAccessException {
+ void testLoadConfigurationWithException() throws NoSuchFieldException, IllegalAccessException {
instance = NacosLogging.getInstance();
Field nacosLoggingField = NacosLogging.class.getDeclaredField("loggingAdapter");
nacosLoggingField.setAccessible(true);
diff --git a/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java
index e5a84b6e022..50580d0e526 100644
--- a/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java
@@ -29,10 +29,9 @@
import com.alibaba.nacos.client.naming.core.ServerListManager;
import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy;
import com.alibaba.nacos.client.security.SecurityProxy;
-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.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;
import java.lang.reflect.Field;
@@ -41,12 +40,13 @@
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-public class NacosNamingMaintainServiceTest {
+class NacosNamingMaintainServiceTest {
private NacosNamingMaintainService nacosNamingMaintainService;
@@ -58,18 +58,18 @@ public class NacosNamingMaintainServiceTest {
private ScheduledExecutorService executorService;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Properties prop = new Properties();
prop.setProperty(PropertyKeyConst.NAMESPACE, "public");
prop.setProperty("serverAddr", "localhost");
-
+
nacosNamingMaintainService = new NacosNamingMaintainService(prop);
serverProxy = mock(NamingHttpClientProxy.class);
serverListManager = mock(ServerListManager.class);
securityProxy = mock(SecurityProxy.class);
executorService = mock(ScheduledExecutorService.class);
-
+
Field serverProxyField = NacosNamingMaintainService.class.getDeclaredField("serverProxy");
serverProxyField.setAccessible(true);
serverProxyField.set(nacosNamingMaintainService, serverProxy);
@@ -84,18 +84,18 @@ public void setUp() throws Exception {
executorServiceField.set(nacosNamingMaintainService, executorService);
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
}
@Test
- public void testConstructor() throws NacosException {
+ void testConstructor() throws NacosException {
NacosNamingMaintainService client = new NacosNamingMaintainService("localhost");
- Assert.assertNotNull(client);
+ assertNotNull(client);
}
@Test
- public void testUpdateInstance1() throws NacosException {
+ void testUpdateInstance1() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -107,7 +107,7 @@ public void testUpdateInstance1() throws NacosException {
}
@Test
- public void testUpdateInstance2() throws NacosException {
+ void testUpdateInstance2() throws NacosException {
//given
String serviceName = "service1";
Instance instance = new Instance();
@@ -118,7 +118,7 @@ public void testUpdateInstance2() throws NacosException {
}
@Test
- public void testQueryService1() throws NacosException {
+ void testQueryService1() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -129,7 +129,7 @@ public void testQueryService1() throws NacosException {
}
@Test
- public void testQueryService2() throws NacosException {
+ void testQueryService2() throws NacosException {
//given
String serviceName = "service1";
Instance instance = new Instance();
@@ -140,7 +140,7 @@ public void testQueryService2() throws NacosException {
}
@Test
- public void testCreateService1() throws NacosException {
+ void testCreateService1() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -157,7 +157,7 @@ public boolean matches(Service service) {
}
@Test
- public void testCreateService2() throws NacosException {
+ void testCreateService2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -175,7 +175,7 @@ public boolean matches(Service service) {
}
@Test
- public void testCreateService3() throws NacosException {
+ void testCreateService3() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -194,7 +194,7 @@ public boolean matches(Service service) {
}
@Test
- public void testCreateService5() throws NacosException {
+ void testCreateService5() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -214,7 +214,7 @@ public boolean matches(Service service) {
}
@Test
- public void testCreateService4() throws NacosException {
+ void testCreateService4() throws NacosException {
//given
Service service = new Service();
AbstractSelector selector = new NoneSelector();
@@ -225,7 +225,7 @@ public void testCreateService4() throws NacosException {
}
@Test
- public void testDeleteService1() throws NacosException {
+ void testDeleteService1() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -235,7 +235,7 @@ public void testDeleteService1() throws NacosException {
}
@Test
- public void testDeleteService2() throws NacosException {
+ void testDeleteService2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -246,7 +246,7 @@ public void testDeleteService2() throws NacosException {
}
@Test
- public void testUpdateService1() throws NacosException {
+ void testUpdateService1() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -265,7 +265,7 @@ public boolean matches(Service service) {
}
@Test
- public void testUpdateService2() throws NacosException {
+ void testUpdateService2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "groupName";
@@ -287,7 +287,7 @@ public boolean matches(Service service) {
}
@Test
- public void testUpdateService3() throws NacosException {
+ void testUpdateService3() throws NacosException {
//given
Service service = new Service();
AbstractSelector selector = new NoneSelector();
@@ -298,7 +298,7 @@ public void testUpdateService3() throws NacosException {
}
@Test
- public void testShutDown() throws NacosException {
+ void testShutDown() throws NacosException {
//when
nacosNamingMaintainService.shutDown();
//then
diff --git a/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingServiceTest.java b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingServiceTest.java
index 8a6e5a95e32..7b1b0275bf0 100644
--- a/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingServiceTest.java
+++ b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingServiceTest.java
@@ -30,17 +30,16 @@
import com.alibaba.nacos.client.naming.event.InstancesChangeNotifier;
import com.alibaba.nacos.client.naming.remote.NamingClientProxy;
import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy;
+import com.alibaba.nacos.client.naming.selector.NamingSelectorFactory;
+import com.alibaba.nacos.client.naming.selector.NamingSelectorWrapper;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -49,7 +48,11 @@
import java.util.List;
import java.util.Properties;
-import static org.junit.Assert.assertEquals;
+import static com.alibaba.nacos.client.naming.selector.NamingSelectorFactory.getUniqueClusterString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
@@ -60,11 +63,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class NacosNamingServiceTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+@ExtendWith(MockitoExtension.class)
+class NacosNamingServiceTest {
@Mock
private NamingClientProxy proxy;
@@ -77,8 +77,8 @@ public class NacosNamingServiceTest {
private NacosNamingService client;
- @Before
- public void before() throws NoSuchFieldException, NacosException, IllegalAccessException {
+ @BeforeEach
+ void before() throws NoSuchFieldException, NacosException, IllegalAccessException {
Properties prop = new Properties();
prop.setProperty("serverAddr", "localhost");
prop.put(PropertyKeyConst.NAMESPACE, "test");
@@ -86,8 +86,8 @@ public void before() throws NoSuchFieldException, NacosException, IllegalAccessE
injectMocks(client);
}
- @After
- public void tearDown() throws NacosException {
+ @AfterEach
+ void tearDown() throws NacosException {
client.shutDown();
}
@@ -118,7 +118,7 @@ private void injectMocks(NacosNamingService client) throws NoSuchFieldException,
}
@Test
- public void testRegisterInstance1() throws NacosException {
+ void testRegisterInstance1() throws NacosException {
//given
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -133,7 +133,7 @@ public void testRegisterInstance1() throws NacosException {
}
@Test
- public void testBatchRegisterInstance() throws NacosException {
+ void testBatchRegisterInstance() throws NacosException {
Instance instance = new Instance();
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -152,7 +152,7 @@ public void testBatchRegisterInstance() throws NacosException {
}
@Test
- public void testBatchRegisterInstanceWithGroupNamePrefix() throws NacosException {
+ void testBatchRegisterInstanceWithGroupNamePrefix() throws NacosException {
Instance instance = new Instance();
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -171,7 +171,7 @@ public void testBatchRegisterInstanceWithGroupNamePrefix() throws NacosException
}
@Test
- public void testBatchRegisterInstanceWithWrongGroupNamePrefix() throws NacosException {
+ void testBatchRegisterInstanceWithWrongGroupNamePrefix() throws NacosException {
Instance instance = new Instance();
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -186,13 +186,13 @@ public void testBatchRegisterInstanceWithWrongGroupNamePrefix() throws NacosExce
try {
client.batchRegisterInstance(serviceName, Constants.DEFAULT_GROUP, instanceList);
} catch (Exception e) {
- Assert.assertTrue(e instanceof NacosException);
- Assert.assertTrue(e.getMessage().contains("wrong group name prefix of instance service name"));
+ assertTrue(e instanceof NacosException);
+ assertTrue(e.getMessage().contains("wrong group name prefix of instance service name"));
}
}
@Test
- public void testBatchDeRegisterInstance() throws NacosException {
+ void testBatchDeRegisterInstance() throws NacosException {
Instance instance = new Instance();
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -207,13 +207,13 @@ public void testBatchDeRegisterInstance() throws NacosException {
try {
client.batchDeregisterInstance(serviceName, Constants.DEFAULT_GROUP, instanceList);
} catch (Exception e) {
- Assert.assertTrue(e instanceof NacosException);
- Assert.assertTrue(e.getMessage().contains("not found"));
+ assertTrue(e instanceof NacosException);
+ assertTrue(e.getMessage().contains("not found"));
}
}
@Test
- public void testRegisterInstance2() throws NacosException {
+ void testRegisterInstance2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -229,7 +229,7 @@ public void testRegisterInstance2() throws NacosException {
}
@Test
- public void testRegisterInstance3() throws NacosException {
+ void testRegisterInstance3() throws NacosException {
//given
String serviceName = "service1";
String clusterName = "cluster1";
@@ -245,7 +245,7 @@ public void testRegisterInstance3() throws NacosException {
}
@Test
- public void testRegisterInstance4() throws NacosException {
+ void testRegisterInstance4() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -262,7 +262,7 @@ public void testRegisterInstance4() throws NacosException {
}
@Test
- public void testRegisterInstance5() throws NacosException {
+ void testRegisterInstance5() throws NacosException {
//given
String serviceName = "service1";
Instance instance = new Instance();
@@ -273,7 +273,7 @@ public void testRegisterInstance5() throws NacosException {
}
@Test
- public void testRegisterInstance6() throws NacosException {
+ void testRegisterInstance6() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -285,22 +285,23 @@ public void testRegisterInstance6() throws NacosException {
}
@Test
- public void testRegisterInstance7() throws NacosException {
- expectedException.expect(NacosException.class);
- expectedException.expectMessage(
- "Instance 'clusterName' should be characters with only 0-9a-zA-Z-. (current: cluster1,cluster2)");
-
- //given
- String serviceName = "service1";
- String groupName = "group1";
- Instance instance = new Instance();
- instance.setClusterName("cluster1,cluster2");
- //when
- client.registerInstance(serviceName, groupName, instance);
+ void testRegisterInstance7() throws NacosException {
+ Throwable exception = assertThrows(NacosException.class, () -> {
+
+ //given
+ String serviceName = "service1";
+ String groupName = "group1";
+ Instance instance = new Instance();
+ instance.setClusterName("cluster1,cluster2");
+ //when
+ client.registerInstance(serviceName, groupName, instance);
+ });
+ assertTrue(exception.getMessage().contains(
+ "Instance 'clusterName' should be characters with only 0-9a-zA-Z-. (current: cluster1,cluster2)"));
}
@Test
- public void testDeregisterInstance1() throws NacosException {
+ void testDeregisterInstance1() throws NacosException {
//given
String serviceName = "service1";
String ip = "1.1.1.1";
@@ -315,7 +316,7 @@ public void testDeregisterInstance1() throws NacosException {
}
@Test
- public void testDeregisterInstance2() throws NacosException {
+ void testDeregisterInstance2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -331,7 +332,7 @@ public void testDeregisterInstance2() throws NacosException {
}
@Test
- public void testDeregisterInstance3() throws NacosException {
+ void testDeregisterInstance3() throws NacosException {
//given
String serviceName = "service1";
String clusterName = "cluster1";
@@ -347,7 +348,7 @@ public void testDeregisterInstance3() throws NacosException {
}
@Test
- public void testDeregisterInstance4() throws NacosException {
+ void testDeregisterInstance4() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -364,7 +365,7 @@ public void testDeregisterInstance4() throws NacosException {
}
@Test
- public void testDeregisterInstance5() throws NacosException {
+ void testDeregisterInstance5() throws NacosException {
//given
String serviceName = "service1";
Instance instance = new Instance();
@@ -375,7 +376,7 @@ public void testDeregisterInstance5() throws NacosException {
}
@Test
- public void testDeregisterInstance6() throws NacosException {
+ void testDeregisterInstance6() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -387,7 +388,7 @@ public void testDeregisterInstance6() throws NacosException {
}
@Test
- public void testGetAllInstances1() throws NacosException {
+ void testGetAllInstances1() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -397,7 +398,7 @@ public void testGetAllInstances1() throws NacosException {
}
@Test
- public void testGetAllInstances2() throws NacosException {
+ void testGetAllInstances2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -408,7 +409,7 @@ public void testGetAllInstances2() throws NacosException {
}
@Test
- public void testGetAllInstances3() throws NacosException {
+ void testGetAllInstances3() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -418,7 +419,7 @@ public void testGetAllInstances3() throws NacosException {
}
@Test
- public void testGetAllInstances4() throws NacosException {
+ void testGetAllInstances4() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -430,7 +431,7 @@ public void testGetAllInstances4() throws NacosException {
}
@Test
- public void testGetAllInstances5() throws NacosException {
+ void testGetAllInstances5() throws NacosException {
//given
String serviceName = "service1";
List clusterList = Arrays.asList("cluster1", "cluster2");
@@ -441,7 +442,7 @@ public void testGetAllInstances5() throws NacosException {
}
@Test
- public void testGetAllInstances6() throws NacosException {
+ void testGetAllInstances6() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -454,19 +455,19 @@ public void testGetAllInstances6() throws NacosException {
}
@Test
- public void testGetAllInstances7() throws NacosException {
+ void testGetAllInstances7() throws NacosException {
//given
String serviceName = "service1";
List clusterList = Arrays.asList("cluster1", "cluster2");
//when
client.getAllInstances(serviceName, clusterList, false);
//then
- verify(proxy, times(1))
- .queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "cluster1,cluster2", false);
+ verify(proxy, times(1)).queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "cluster1,cluster2",
+ false);
}
@Test
- public void testGetAllInstances8() throws NacosException {
+ void testGetAllInstances8() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -478,7 +479,7 @@ public void testGetAllInstances8() throws NacosException {
}
@Test
- public void testGetAllInstanceFromFailover() throws NacosException {
+ void testGetAllInstanceFromFailover() throws NacosException {
when(serviceInfoHolder.isFailoverSwitch()).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo("group1@@service1");
serviceInfo.setHosts(Collections.singletonList(new Instance()));
@@ -490,7 +491,7 @@ public void testGetAllInstanceFromFailover() throws NacosException {
}
@Test
- public void testGetAllInstanceFromFailoverEmpty() throws NacosException {
+ void testGetAllInstanceFromFailoverEmpty() throws NacosException {
when(serviceInfoHolder.isFailoverSwitch()).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo("group1@@service1");
when(serviceInfoHolder.getFailoverServiceInfo(anyString(), anyString(), anyString())).thenReturn(serviceInfo);
@@ -500,7 +501,7 @@ public void testGetAllInstanceFromFailoverEmpty() throws NacosException {
}
@Test
- public void testSelectInstances1() throws NacosException {
+ void testSelectInstances1() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -510,7 +511,7 @@ public void testSelectInstances1() throws NacosException {
}
@Test
- public void testSelectInstances2() throws NacosException {
+ void testSelectInstances2() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -521,7 +522,7 @@ public void testSelectInstances2() throws NacosException {
}
@Test
- public void testSelectInstances3() throws NacosException {
+ void testSelectInstances3() throws NacosException {
//given
String serviceName = "service1";
//when
@@ -531,7 +532,7 @@ public void testSelectInstances3() throws NacosException {
}
@Test
- public void testSelectInstances4() throws NacosException {
+ void testSelectInstances4() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -543,7 +544,7 @@ public void testSelectInstances4() throws NacosException {
}
@Test
- public void testSelectInstances5() throws NacosException {
+ void testSelectInstances5() throws NacosException {
//given
String serviceName = "service1";
List clusterList = Arrays.asList("cluster1", "cluster2");
@@ -554,7 +555,7 @@ public void testSelectInstances5() throws NacosException {
}
@Test
- public void testSelectInstances6() throws NacosException {
+ void testSelectInstances6() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -567,19 +568,19 @@ public void testSelectInstances6() throws NacosException {
}
@Test
- public void testSelectInstances7() throws NacosException {
+ void testSelectInstances7() throws NacosException {
//given
String serviceName = "service1";
List clusterList = Arrays.asList("cluster1", "cluster2");
//when
client.selectInstances(serviceName, clusterList, true, false);
//then
- verify(proxy, times(1))
- .queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "cluster1,cluster2", false);
+ verify(proxy, times(1)).queryInstancesOfService(serviceName, Constants.DEFAULT_GROUP, "cluster1,cluster2",
+ false);
}
@Test
- public void testSelectInstances8() throws NacosException {
+ void testSelectInstances8() throws NacosException {
//given
String serviceName = "service1";
String groupName = "group1";
@@ -591,7 +592,7 @@ public void testSelectInstances8() throws NacosException {
}
@Test
- public void testSelectInstancesWithHealthyFlag() throws NacosException {
+ void testSelectInstancesWithHealthyFlag() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setHealthy(true);
@@ -623,11 +624,11 @@ public void testSelectInstancesWithHealthyFlag() throws NacosException {
List instances = client.selectInstances(serviceName, groupName, clusterList, true, false);
//then
assertEquals(1, instances.size());
- Assert.assertSame(healthyInstance, instances.get(0));
+ assertSame(healthyInstance, instances.get(0));
}
@Test
- public void testSelectOneHealthyInstance1() throws NacosException {
+ void testSelectOneHealthyInstance1() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -646,7 +647,7 @@ public void testSelectOneHealthyInstance1() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance2() throws NacosException {
+ void testSelectOneHealthyInstance2() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -666,7 +667,7 @@ public void testSelectOneHealthyInstance2() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance3() throws NacosException {
+ void testSelectOneHealthyInstance3() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -675,8 +676,8 @@ public void testSelectOneHealthyInstance3() throws NacosException {
hosts.add(healthyInstance);
ServiceInfo infoWithHealthyInstance = new ServiceInfo();
infoWithHealthyInstance.setHosts(hosts);
- when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean()))
- .thenReturn(infoWithHealthyInstance);
+ when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(
+ infoWithHealthyInstance);
String serviceName = "service1";
//when
@@ -686,7 +687,7 @@ public void testSelectOneHealthyInstance3() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance4() throws NacosException {
+ void testSelectOneHealthyInstance4() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -695,8 +696,8 @@ public void testSelectOneHealthyInstance4() throws NacosException {
hosts.add(healthyInstance);
ServiceInfo infoWithHealthyInstance = new ServiceInfo();
infoWithHealthyInstance.setHosts(hosts);
- when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean()))
- .thenReturn(infoWithHealthyInstance);
+ when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(
+ infoWithHealthyInstance);
String serviceName = "service1";
String groupName = "group1";
@@ -708,7 +709,7 @@ public void testSelectOneHealthyInstance4() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance5() throws NacosException {
+ void testSelectOneHealthyInstance5() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -728,7 +729,7 @@ public void testSelectOneHealthyInstance5() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance6() throws NacosException {
+ void testSelectOneHealthyInstance6() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -750,7 +751,7 @@ public void testSelectOneHealthyInstance6() throws NacosException {
}
@Test
- public void testSelectOneHealthyInstance7() throws NacosException {
+ void testSelectOneHealthyInstance7() throws NacosException {
//given
Instance healthyInstance = new Instance();
healthyInstance.setIp("1.1.1.1");
@@ -759,20 +760,20 @@ public void testSelectOneHealthyInstance7() throws NacosException {
hosts.add(healthyInstance);
ServiceInfo infoWithHealthyInstance = new ServiceInfo();
infoWithHealthyInstance.setHosts(hosts);
- when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean()))
- .thenReturn(infoWithHealthyInstance);
+ when(proxy.queryInstancesOfService(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(
+ infoWithHealthyInstance);
String serviceName = "service1";
List