diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/ClientAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/ClientAbilitiesTest.java index 7510c1e82..b15c83dcd 100644 --- a/api/src/test/java/com/alibaba/nacos/api/ability/ClientAbilitiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/ability/ClientAbilitiesTest.java @@ -20,25 +20,25 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ClientAbilitiesTest { +class ClientAbilitiesTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ClientAbilities abilities = new ClientAbilities(); String json = mapper.writeValueAsString(abilities); assertTrue(json.contains("\"remoteAbility\":{")); @@ -47,7 +47,7 @@ public class ClientAbilitiesTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false}," + "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false," + "\"supportRemoteMetric\":false}}"; diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/ServerAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/ServerAbilitiesTest.java index 69ba2aca8..1b9785cfe 100644 --- a/api/src/test/java/com/alibaba/nacos/api/ability/ServerAbilitiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/ability/ServerAbilitiesTest.java @@ -20,35 +20,35 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ServerAbilitiesTest { +class ServerAbilitiesTest { private static ObjectMapper mapper; private ServerAbilities serverAbilities; - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { serverAbilities = new ServerAbilities(); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { serverAbilities = new ServerAbilities(); String json = mapper.writeValueAsString(serverAbilities); assertTrue(json.contains("\"remoteAbility\":{")); @@ -57,7 +57,7 @@ public class ServerAbilitiesTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false}," + "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false," + "\"supportRemoteMetric\":false}}"; @@ -68,10 +68,10 @@ public class ServerAbilitiesTest { } @Test - public void testEqualsAndHashCode() { + void testEqualsAndHashCode() { assertEquals(serverAbilities, serverAbilities); assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode()); - assertNotEquals(serverAbilities, null); + assertNotEquals(null, serverAbilities); assertNotEquals(serverAbilities, new ClientAbilities()); ServerAbilities test = new ServerAbilities(); assertEquals(serverAbilities, test); diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java index b6ec8a54e..e7db88cc8 100644 --- a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java @@ -16,14 +16,14 @@ package com.alibaba.nacos.api.ability.register.impl; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ClusterClientAbilitiesTest { +class ClusterClientAbilitiesTest { @Test - public void testGetStaticAbilities() { + void testGetStaticAbilities() { // TODO add the cluster client abilities. assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java index ea9cabd46..36a6db496 100644 --- a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java @@ -16,14 +16,14 @@ package com.alibaba.nacos.api.ability.register.impl; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class SdkClientAbilitiesTest { +class SdkClientAbilitiesTest { @Test - public void testGetStaticAbilities() { + void testGetStaticAbilities() { // TODO add the sdk client abilities. assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java index 2058a3531..79ba5f6e4 100644 --- a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java @@ -17,20 +17,20 @@ package com.alibaba.nacos.api.ability.register.impl; import com.alibaba.nacos.api.ability.constant.AbilityKey; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ServerAbilitiesTest { +class ServerAbilitiesTest { @Test - public void testGetStaticAbilities() { + void testGetStaticAbilities() { assertFalse(ServerAbilities.getStaticAbilities().isEmpty()); } - + @Test - public void testSupportPersistentInstanceByGrpcAbilities() { + void testSupportPersistentInstanceByGrpcAbilities() { assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC)); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/annotation/NacosPropertiesTest.java b/api/src/test/java/com/alibaba/nacos/api/annotation/NacosPropertiesTest.java index c0ff4ccee..1e3885d04 100644 --- a/api/src/test/java/com/alibaba/nacos/api/annotation/NacosPropertiesTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/annotation/NacosPropertiesTest.java @@ -16,8 +16,7 @@ package com.alibaba.nacos.api.annotation; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.env.MockEnvironment; import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER; @@ -28,23 +27,24 @@ import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOL import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER; import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER; import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class NacosPropertiesTest { +class NacosPropertiesTest { @Test - public void testPlaceholders() { - Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER); - Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER); - Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER); - Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER); - Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER); - Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER); - Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER); - Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER); + void testPlaceholders() { + assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER); + assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER); + assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER); + assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER); + assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER); + assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER); + assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER); + assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER); } @Test - public void testResolvePlaceholders() { + void testResolvePlaceholders() { testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value"); testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", ""); @@ -75,11 +75,11 @@ public class NacosPropertiesTest { MockEnvironment environment = new MockEnvironment(); environment.setProperty(propertyName, propertyValue); String resolvedValue = environment.resolvePlaceholders(placeholder); - Assert.assertEquals(expectValue, resolvedValue); + assertEquals(expectValue, resolvedValue); } @Test - public void testSort() { + void testSort() { } } diff --git a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityEventTest.java b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityEventTest.java index cab555aed..c2e6bd071 100644 --- a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityEventTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityEventTest.java @@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class EntityEventTest { +class EntityEventTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { EntityEvent entity = new EntityEvent(); entity.setEntityName("test-entity"); entity.setEntityType("CMDB"); @@ -50,7 +50,7 @@ public class EntityEventTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}"; EntityEvent entity = mapper.readValue(json, EntityEvent.class); assertEquals("test-entity", entity.getEntityName()); diff --git a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityTest.java b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityTest.java index 79f05b39a..5530921e2 100644 --- a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/EntityTest.java @@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class EntityTest { +class EntityTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { Entity entity = new Entity(); entity.setName("test-entity"); entity.setType(PreservedEntityTypes.ip.name()); @@ -51,7 +51,7 @@ public class EntityTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}"; Entity entity = mapper.readValue(json, Entity.class); assertEquals("test-entity", entity.getName()); diff --git a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/LabelTest.java b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/LabelTest.java index 4a0023a00..519e54013 100644 --- a/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/LabelTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/LabelTest.java @@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class LabelTest { +class LabelTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { Label label = new Label(); label.setName("test-label"); label.setDescription("CMDB description"); @@ -52,7 +52,7 @@ public class LabelTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}"; Label label = mapper.readValue(json, Label.class); assertEquals("test-label", label.getName()); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeEventTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeEventTest.java index 3120941f2..c7adfac3a 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeEventTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeEventTest.java @@ -16,18 +16,18 @@ package com.alibaba.nacos.api.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -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; -public class ConfigChangeEventTest { +class ConfigChangeEventTest { @Test - public void testConstructor() { + void testConstructor() { Map mockData = new HashMap<>(); mockData.put("test", new ConfigChangeItem("testKey", null, "testValue")); ConfigChangeEvent event = new ConfigChangeEvent(mockData); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeItemTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeItemTest.java index cbd28b297..6f0ee8621 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeItemTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ConfigChangeItemTest.java @@ -16,15 +16,15 @@ package com.alibaba.nacos.api.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class ConfigChangeItemTest { +class ConfigChangeItemTest { @Test - public void testSetNewValue() { + void testSetNewValue() { ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue"); item.setType(PropertyChangeType.ADDED); assertEquals("testKey", item.getKey()); @@ -46,7 +46,7 @@ public class ConfigChangeItemTest { } @Test - public void testToString() { + void testToString() { ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue"); item.setType(PropertyChangeType.ADDED); assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}", diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ConfigTypeTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ConfigTypeTest.java index ca8160f22..003c21af4 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ConfigTypeTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ConfigTypeTest.java @@ -16,16 +16,16 @@ package com.alibaba.nacos.api.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class ConfigTypeTest { +class ConfigTypeTest { @Test - public void isValidType() { + void isValidType() { assertTrue(ConfigType.isValidType("xml")); assertTrue(ConfigType.isValidType("properties")); assertTrue(ConfigType.isValidType("json")); @@ -38,7 +38,7 @@ public class ConfigTypeTest { } @Test - public void testGetDefaultType() { + void testGetDefaultType() { assertEquals("text", ConfigType.getDefaultType().getType()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ability/ClientRemoteAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ability/ClientRemoteAbilityTest.java index eb9ab8140..2246fa519 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ability/ClientRemoteAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ability/ClientRemoteAbilityTest.java @@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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; -public class ClientRemoteAbilityTest { +class ClientRemoteAbilityTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ClientRemoteAbility abilities = new ClientRemoteAbility(); String json = mapper.writeValueAsString(abilities); assertEquals("{\"supportRemoteConnection\":false}", json); } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"supportRemoteConnection\":true}"; ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class); assertTrue(abilities.isSupportRemoteConnection()); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerConfigAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerConfigAbilityTest.java index d93e594a2..f20f91a74 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerConfigAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerConfigAbilityTest.java @@ -16,21 +16,20 @@ package com.alibaba.nacos.api.config.ability; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class ServerConfigAbilityTest { +class ServerConfigAbilityTest { @Test - public void testEquals() { + void testEquals() { ServerConfigAbility ability = new ServerConfigAbility(); ability.setSupportRemoteMetrics(true); assertEquals(ability, ability); - assertFalse(ability.equals(null)); - assertFalse(ability.equals(new ClientConfigAbility())); + assertNotEquals(null, ability); + assertNotEquals(ability, new ClientConfigAbility()); ServerConfigAbility newOne = new ServerConfigAbility(); assertNotEquals(ability, newOne); newOne.setSupportRemoteMetrics(true); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerRemoteAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerRemoteAbilityTest.java index b25af0f68..173f82136 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerRemoteAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/ability/ServerRemoteAbilityTest.java @@ -23,35 +23,35 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ServerRemoteAbilityTest { +class ServerRemoteAbilityTest { private static ObjectMapper mapper; private ServerRemoteAbility serverAbilities; - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { serverAbilities = new ServerRemoteAbility(); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { serverAbilities = new ServerRemoteAbility(); String json = mapper.writeValueAsString(serverAbilities); assertTrue(json.contains("\"supportRemoteConnection\":false")); @@ -59,7 +59,7 @@ public class ServerRemoteAbilityTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}"; ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class); assertTrue(abilities.isSupportRemoteConnection()); @@ -67,10 +67,10 @@ public class ServerRemoteAbilityTest { } @Test - public void testEqualsAndHashCode() { + void testEqualsAndHashCode() { assertEquals(serverAbilities, serverAbilities); assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode()); - assertNotEquals(serverAbilities, null); + assertNotEquals(null, serverAbilities); assertNotEquals(serverAbilities, new ClientAbilities()); ServerRemoteAbility test = new ServerRemoteAbility(); assertEquals(serverAbilities, test); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractListenerTest.java b/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractListenerTest.java index cf3148840..c9eadd19a 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractListenerTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractListenerTest.java @@ -16,14 +16,14 @@ package com.alibaba.nacos.api.config.listener; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; -public class AbstractListenerTest { +class AbstractListenerTest { @Test - public void testGetExecutor() { + void testGetExecutor() { // Default listener executor is null. assertNull(new AbstractListener() { @Override diff --git a/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractSharedListenerTest.java b/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractSharedListenerTest.java index 8a1fa8d42..e61ea4e55 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractSharedListenerTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/listener/AbstractSharedListenerTest.java @@ -16,28 +16,28 @@ package com.alibaba.nacos.api.config.listener; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -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; -public class AbstractSharedListenerTest { +class AbstractSharedListenerTest { private static final String CONFIG_CONTENT = "test"; private static Map receivedMap; - @Before - public void setUp() { + @BeforeEach + void setUp() { receivedMap = new HashMap<>(); } @Test - public void testFillContext() { + void testFillContext() { assertEquals(0, receivedMap.size()); MockShardListener listener = new MockShardListener(); listener.receiveConfigInfo(CONFIG_CONTENT); @@ -52,7 +52,7 @@ public class AbstractSharedListenerTest { } @Test - public void getExecutor() { + void getExecutor() { // Default listener executor is null. assertNull(new MockShardListener().getExecutor()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/BasedConfigRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/BasedConfigRequestTest.java index 8e4cecea7..b50a92093 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/BasedConfigRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/BasedConfigRequestTest.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import java.util.HashMap; import java.util.Map; @@ -30,8 +30,6 @@ import java.util.UUID; public abstract class BasedConfigRequestTest { - protected static ObjectMapper mapper; - protected static final String DATA_ID = "test_data"; protected static final String GROUP = "group"; @@ -52,11 +50,13 @@ public abstract class BasedConfigRequestTest { protected static final String CONTENT = "content"; + protected static ObjectMapper mapper; + static { HEADERS.put(HEADER_KEY, HEADER_VALUE); } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ClientConfigMetricRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ClientConfigMetricRequestTest.java index 38cf4c63b..4b19652f7 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ClientConfigMetricRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ClientConfigMetricRequestTest.java @@ -18,18 +18,17 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Objects; import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.CACHE_DATA; import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ClientConfigMetricRequestTest extends BasedConfigRequestTest { +class ClientConfigMetricRequestTest extends BasedConfigRequestTest { @Override @Test @@ -57,35 +56,36 @@ public class ClientConfigMetricRequestTest extends BasedConfigRequestTest { + "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\"," + "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}"; ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class); - assertEquals(actual.getMetricsKeys().size(), 2); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE); + assertEquals(2, actual.getMetricsKeys().size()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY)); } @Test - public void testMetricsKeysEquals() { + void testMetricsKeysEquals() { String dataKey = String.join("+", KEY); ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey); assertEquals(key, key); - assertFalse(key.equals(null)); - assertFalse(key.equals(new ClientConfigMetricRequest())); - ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey - .build(SNAPSHOT_DATA, dataKey); + assertNotEquals(null, key); + assertNotEquals(key, new ClientConfigMetricRequest()); + ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA, + dataKey); assertNotEquals(key, newOne); newOne.setType(CACHE_DATA); assertEquals(key, newOne); } @Test - public void testMetricsHashCode() { + void testMetricsHashCode() { String dataKey = String.join("+", KEY); ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey); assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode()); } @Test - public void testMetricsToString() { - ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY)); + void testMetricsToString() { + ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, + String.join("+", KEY)); assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString()); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigBatchListenRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigBatchListenRequestTest.java index 9c85186d6..b40823515 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigBatchListenRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigBatchListenRequestTest.java @@ -18,12 +18,12 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class ConfigBatchListenRequestTest extends BasedConfigRequestTest { +class ConfigBatchListenRequestTest extends BasedConfigRequestTest { @Override @Test @@ -47,14 +47,14 @@ public class ConfigBatchListenRequestTest extends BasedConfigRequestTest { + "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\"," + "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}"; ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class); - assertEquals(actual.isListen(), true); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE); - assertEquals(actual.getConfigListenContexts().size(), 1); + assertEquals(true, actual.isListen()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY)); + assertEquals(1, actual.getConfigListenContexts().size()); } @Test - public void testConfigListenContextToString() { + void testConfigListenContextToString() { ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest(); configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5); assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}", diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeNotifyRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeNotifyRequestTest.java index 2f64d3a83..370d885ea 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeNotifyRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeNotifyRequestTest.java @@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest { +class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest { ConfigChangeNotifyRequest configChangeNotifyRequest; String requestId; - @Before - public void before() { + @BeforeEach + void before() { configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT); configChangeNotifyRequest.putAllHeader(HEADERS); requestId = injectRequestUuId(configChangeNotifyRequest); @@ -54,10 +54,10 @@ public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest { String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":" + "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}"; ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class); - assertEquals(actual.getDataId(), DATA_ID); - assertEquals(actual.getGroup(), GROUP); - assertEquals(actual.getTenant(), TENANT); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE); + assertEquals(DATA_ID, actual.getDataId()); + assertEquals(GROUP, actual.getGroup()); + assertEquals(TENANT, actual.getTenant()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY)); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigPublishRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigPublishRequestTest.java index 41e253b60..7dc214b7b 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigPublishRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigPublishRequestTest.java @@ -18,24 +18,24 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigPublishRequestTest extends BasedConfigRequestTest { - - ConfigPublishRequest configPublishRequest; +class ConfigPublishRequestTest extends BasedConfigRequestTest { private static final String TAG_PARAM = "tag"; private static final String APP_NAME_PARAM = "appName"; + ConfigPublishRequest configPublishRequest; + String requestId; - @Before - public void before() { + @BeforeEach + void before() { configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT); configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM); configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM); @@ -64,13 +64,13 @@ public class ConfigPublishRequestTest extends BasedConfigRequestTest { + "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\"," + "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}"; ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class); - assertEquals(actual.getDataId(), DATA_ID); - assertEquals(actual.getGroup(), GROUP); - assertEquals(actual.getTenant(), TENANT); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getContent(), CONTENT); - assertEquals(actual.getCasMd5(), MD5); - assertEquals(actual.getAdditionParam(TAG_PARAM), TAG_PARAM); - assertEquals(actual.getAdditionParam(APP_NAME_PARAM), APP_NAME_PARAM); + assertEquals(DATA_ID, actual.getDataId()); + assertEquals(GROUP, actual.getGroup()); + assertEquals(TENANT, actual.getTenant()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(CONTENT, actual.getContent()); + assertEquals(MD5, actual.getCasMd5()); + assertEquals(TAG_PARAM, actual.getAdditionParam(TAG_PARAM)); + assertEquals(APP_NAME_PARAM, actual.getAdditionParam(APP_NAME_PARAM)); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigQueryRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigQueryRequestTest.java index c8350f119..9fde8a18f 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigQueryRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigQueryRequestTest.java @@ -18,16 +18,16 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -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; -public class ConfigQueryRequestTest extends BasedConfigRequestTest { +class ConfigQueryRequestTest extends BasedConfigRequestTest { ConfigQueryRequest configQueryRequest; @@ -35,8 +35,8 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest { String requestId; - @Before - public void before() { + @BeforeEach + void before() { headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString()); configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT); configQueryRequest.putAllHeader(headers); @@ -45,7 +45,7 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest { } @Test - public void testIsNotify() { + void testIsNotify() { assertTrue(configQueryRequest.isNotify()); } @@ -67,10 +67,10 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest { String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\"," + "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}"; ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class); - assertEquals(actual.getDataId(), DATA_ID); - assertEquals(actual.getGroup(), GROUP); - assertEquals(actual.getTenant(), TENANT); - assertEquals(actual.getTag(), TAG); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); + assertEquals(DATA_ID, actual.getDataId()); + assertEquals(GROUP, actual.getGroup()); + assertEquals(TENANT, actual.getTenant()); + assertEquals(TAG, actual.getTag()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigRemoveRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigRemoveRequestTest.java index e5c97ad9f..054c5e538 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigRemoveRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/ConfigRemoveRequestTest.java @@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigRemoveRequestTest extends BasedConfigRequestTest { +class ConfigRemoveRequestTest extends BasedConfigRequestTest { ConfigRemoveRequest configRemoveRequest; String requestId; - @Before - public void before() { + @BeforeEach + void before() { configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG); requestId = injectRequestUuId(configRemoveRequest); @@ -56,10 +56,10 @@ public class ConfigRemoveRequestTest extends BasedConfigRequestTest { String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\"" + ",\"tag\":\"tag\",\"module\":\"config\"}"; ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class); - assertEquals(actual.getDataId(), DATA_ID); - assertEquals(actual.getGroup(), GROUP); - assertEquals(actual.getTenant(), TENANT); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getTag(), TAG); + assertEquals(DATA_ID, actual.getDataId()); + assertEquals(GROUP, actual.getGroup()); + assertEquals(TENANT, actual.getTenant()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(TAG, actual.getTag()); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java index 6145eec4a..d1055c18c 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java @@ -19,20 +19,20 @@ package com.alibaba.nacos.api.config.remote.request.cluster; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest { +class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest { ConfigChangeClusterSyncRequest configChangeClusterSyncRequest; String requestId; - @Before - public void before() { + @BeforeEach + void before() { configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest(); configChangeClusterSyncRequest.setDataId(DATA_ID); configChangeClusterSyncRequest.setGroup(GROUP); @@ -64,15 +64,16 @@ public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest { @Override @Test public void testDeserialize() throws JsonProcessingException { - String json = "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\"," - + "\"group\":\"group\",\"tenant\":\"test_tenant\"," - + "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}"; + String json = + "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\"," + + "\"group\":\"group\",\"tenant\":\"test_tenant\"," + + "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}"; ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class); - assertEquals(actual.getDataId(), DATA_ID); - assertEquals(actual.getGroup(), GROUP); - assertEquals(actual.getTenant(), TENANT); - assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE); - assertEquals(actual.getLastModified(), 0L); + assertEquals(DATA_ID, actual.getDataId()); + assertEquals(GROUP, actual.getGroup()); + assertEquals(TENANT, actual.getTenant()); + assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule()); + assertEquals(0L, actual.getLastModified()); assertTrue(actual.isBeta()); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ClientConfigMetricResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ClientConfigMetricResponseTest.java index 66de71c43..18b86c08a 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ClientConfigMetricResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ClientConfigMetricResponseTest.java @@ -18,14 +18,14 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -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; public class ClientConfigMetricResponseTest extends BasedConfigResponseTest { @@ -33,8 +33,8 @@ public class ClientConfigMetricResponseTest extends BasedConfigResponseTest { Map metric = new HashMap<>(16); - @Before - public void before() { + @BeforeEach + void before() { metric.put("m1", "v1"); clientConfigMetricResponse = new ClientConfigMetricResponse(); clientConfigMetricResponse.setMetrics(metric); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeBatchListenResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeBatchListenResponseTest.java index 54e068eae..de56fb710 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeBatchListenResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeBatchListenResponseTest.java @@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest { +class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest { ConfigChangeBatchListenResponse configChangeBatchListenResponse; - @Before - public void before() { + @BeforeEach + void before() { configChangeBatchListenResponse = new ConfigChangeBatchListenResponse(); requestId = injectResponseUuId(configChangeBatchListenResponse); configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT); @@ -50,8 +50,8 @@ public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest @Override @Test public void testSerializeFailResponse() throws JsonProcessingException { - ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse - .buildFailResponse("Fail"); + ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse.buildFailResponse( + "Fail"); String json = mapper.writeValueAsString(configChangeBatchListenResponse); assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode())); assertTrue(json.contains("\"errorCode\":0")); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponseTest.java index 77c673539..8c84f2b0d 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponseTest.java @@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest { ConfigChangeNotifyResponse configChangeNotifyResponse; - @Before - public void before() { + @BeforeEach + void before() { configChangeNotifyResponse = new ConfigChangeNotifyResponse(); requestId = injectResponseUuId(configChangeNotifyResponse); } @@ -41,7 +41,7 @@ public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest { assertTrue(json.contains("\"requestId\":\"" + requestId)); assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode())); assertTrue(json.contains("\"errorCode\":0")); - + } @Override diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigPublishResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigPublishResponseTest.java index 551db99c8..4aa69a6d8 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigPublishResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigPublishResponseTest.java @@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ConfigPublishResponseTest extends BasedConfigResponseTest { +class ConfigPublishResponseTest extends BasedConfigResponseTest { ConfigPublishResponse configPublishResponse; - @Before - public void before() { + @BeforeEach + void before() { configPublishResponse = ConfigPublishResponse.buildSuccessResponse(); requestId = injectResponseUuId(configPublishResponse); } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponseTest.java index dae2c1528..e0574dc15 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponseTest.java @@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ConfigQueryResponseTest extends BasedConfigResponseTest { +class ConfigQueryResponseTest extends BasedConfigResponseTest { ConfigQueryResponse configQueryResponse; - @Before - public void before() { + @BeforeEach + void before() { configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success"); configQueryResponse.setContentType("text"); configQueryResponse.setEncryptedDataKey("encryptedKey"); diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponseTest.java index 68c4f42d4..6b735f412 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponseTest.java @@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ConfigRemoveResponseTest extends BasedConfigResponseTest { +class ConfigRemoveResponseTest extends BasedConfigResponseTest { ConfigRemoveResponse configRemoveResponse; - @Before - public void before() { + @BeforeEach + void before() { configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse(); requestId = injectResponseUuId(configRemoveResponse); } diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/cluster/ConfigChangeClusterSyncResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/cluster/ConfigChangeClusterSyncResponseTest.java index 949f40468..b75054f41 100644 --- a/api/src/test/java/com/alibaba/nacos/api/config/remote/response/cluster/ConfigChangeClusterSyncResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/response/cluster/ConfigChangeClusterSyncResponseTest.java @@ -19,17 +19,17 @@ package com.alibaba.nacos.api.config.remote.response.cluster; import com.alibaba.nacos.api.config.remote.response.BasedConfigResponseTest; import com.alibaba.nacos.api.remote.response.ResponseCode; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest { ConfigChangeClusterSyncResponse configChangeClusterSyncResponse; - @Before - public void before() { + @BeforeEach + void before() { configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse(); requestId = injectResponseUuId(configChangeClusterSyncResponse); } diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/NacosExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/NacosExceptionTest.java index d70c7b4f3..7d43cf5ee 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/NacosExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/NacosExceptionTest.java @@ -17,14 +17,14 @@ package com.alibaba.nacos.api.exception; import com.alibaba.nacos.api.common.Constants; -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 NacosExceptionTest { +class NacosExceptionTest { @Test - public void testEmptyConstructor() { + void testEmptyConstructor() { NacosException exception = new NacosException(); assertEquals(0, exception.getErrCode()); assertEquals(Constants.NULL, exception.getErrMsg()); @@ -35,7 +35,7 @@ public class NacosExceptionTest { } @Test - public void testConstructorWithErrMsg() { + void testConstructorWithErrMsg() { NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test"); assertEquals(NacosException.SERVER_ERROR, exception.getErrCode()); assertEquals("test", exception.getErrMsg()); @@ -43,7 +43,7 @@ public class NacosExceptionTest { } @Test - public void testConstructorWithCause() { + void testConstructorWithCause() { NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test")); assertEquals(NacosException.SERVER_ERROR, exception.getErrCode()); assertEquals("cause test", exception.getErrMsg()); @@ -51,7 +51,7 @@ public class NacosExceptionTest { } @Test - public void testConstructorWithMultiCauses() { + void testConstructorWithMultiCauses() { NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test", new RuntimeException("multi"))); assertEquals(NacosException.SERVER_ERROR, exception.getErrCode()); @@ -60,7 +60,7 @@ public class NacosExceptionTest { } @Test - public void testConstructorWithFull() { + void testConstructorWithFull() { NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test", new RuntimeException("cause test")); assertEquals(NacosException.SERVER_ERROR, exception.getErrCode()); diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/api/NacosApiExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/api/NacosApiExceptionTest.java index 36e3920fe..9be5d98e6 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/api/NacosApiExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/api/NacosApiExceptionTest.java @@ -18,14 +18,14 @@ package com.alibaba.nacos.api.exception.api; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.model.v2.ErrorCode; -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 NacosApiExceptionTest { +class NacosApiExceptionTest { @Test - public void testEmptyConstructor() { + void testEmptyConstructor() { NacosApiException exception = new NacosApiException(); assertEquals(0, exception.getErrCode()); assertEquals(0, exception.getDetailErrCode()); @@ -34,7 +34,7 @@ public class NacosApiExceptionTest { } @Test - public void testConstructorWithoutCause() { + void testConstructorWithoutCause() { NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test"); assertEquals(500, exception.getErrCode()); assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode()); @@ -43,7 +43,7 @@ public class NacosApiExceptionTest { } @Test - public void testConstructorWithCause() { + void testConstructorWithCause() { NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, new RuntimeException("cause test"), "test"); assertEquals(500, exception.getErrCode()); diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosDeserializationExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosDeserializationExceptionTest.java index 612ba9d7c..e4922acb5 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosDeserializationExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosDeserializationExceptionTest.java @@ -18,17 +18,17 @@ package com.alibaba.nacos.api.exception.runtime; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.databind.type.SimpleType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Type; -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; -public class NacosDeserializationExceptionTest { +class NacosDeserializationExceptionTest { @Test - public void testEmptyConstructor() { + void testEmptyConstructor() { NacosDeserializationException exception = new NacosDeserializationException(); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); assertNull(exception.getMessage()); @@ -36,7 +36,7 @@ public class NacosDeserializationExceptionTest { } @Test - public void testConstructorWithTargetClass() { + void testConstructorWithTargetClass() { NacosDeserializationException exception = new NacosDeserializationException( NacosDeserializationExceptionTest.class); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); @@ -46,7 +46,7 @@ public class NacosDeserializationExceptionTest { } @Test - public void testConstructorWithTargetType() { + void testConstructorWithTargetType() { Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class); NacosDeserializationException exception = new NacosDeserializationException(type); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); @@ -57,7 +57,7 @@ public class NacosDeserializationExceptionTest { } @Test - public void testConstructorWithCause() { + void testConstructorWithCause() { NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test")); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage()); @@ -65,7 +65,7 @@ public class NacosDeserializationExceptionTest { } @Test - public void testConstructorWithTargetClassAndCause() { + void testConstructorWithTargetClassAndCause() { NacosDeserializationException exception = new NacosDeserializationException( NacosDeserializationExceptionTest.class, new RuntimeException("test")); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); @@ -75,7 +75,7 @@ public class NacosDeserializationExceptionTest { } @Test - public void testConstructorWithTargetTypeAndCause() { + void testConstructorWithTargetTypeAndCause() { Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class); NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test")); assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode()); diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosLoadExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosLoadExceptionTest.java index 3311852e9..3be1a4964 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosLoadExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosLoadExceptionTest.java @@ -16,15 +16,15 @@ package com.alibaba.nacos.api.exception.runtime; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class NacosLoadExceptionTest { +class NacosLoadExceptionTest { @Test - public void testConstructor() { + void testConstructor() { NacosLoadException exception = new NacosLoadException("test"); assertEquals("test", exception.getMessage()); assertNull(exception.getCause()); diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosRuntimeExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosRuntimeExceptionTest.java index 5ea20081a..8e5348113 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosRuntimeExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosRuntimeExceptionTest.java @@ -17,16 +17,16 @@ package com.alibaba.nacos.api.exception.runtime; import com.alibaba.nacos.api.exception.NacosException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class NacosRuntimeExceptionTest { +class NacosRuntimeExceptionTest { @Test - public void testConstructorWithErrorCode() { + void testConstructorWithErrorCode() { NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM); assertEquals(NacosException.INVALID_PARAM, exception.getErrCode()); assertNull(exception.getMessage()); @@ -34,7 +34,7 @@ public class NacosRuntimeExceptionTest { } @Test - public void testConstructorWithErrorCodeAndMsg() { + void testConstructorWithErrorCodeAndMsg() { NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test"); assertEquals(NacosException.INVALID_PARAM, exception.getErrCode()); assertEquals("errCode: 400, errMsg: test ", exception.getMessage()); @@ -42,7 +42,7 @@ public class NacosRuntimeExceptionTest { } @Test - public void testConstructorWithErrorCodeAndCause() { + void testConstructorWithErrorCodeAndCause() { NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, new RuntimeException("test")); assertEquals(NacosException.INVALID_PARAM, exception.getErrCode()); @@ -51,9 +51,9 @@ public class NacosRuntimeExceptionTest { } @Test - public void testConstructorWithFull() { - NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, - "test", new RuntimeException("cause test")); + void testConstructorWithFull() { + NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test", + new RuntimeException("cause test")); assertEquals(NacosException.INVALID_PARAM, exception.getErrCode()); assertEquals("errCode: 400, errMsg: test ", exception.getMessage()); assertTrue(exception.getCause() instanceof RuntimeException); diff --git a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosSerializationExceptionTest.java b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosSerializationExceptionTest.java index da4b0e679..fd7b2850a 100644 --- a/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosSerializationExceptionTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/exception/runtime/NacosSerializationExceptionTest.java @@ -17,15 +17,15 @@ package com.alibaba.nacos.api.exception.runtime; import com.alibaba.nacos.api.common.Constants; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class NacosSerializationExceptionTest { +class NacosSerializationExceptionTest { @Test - public void testEmptyConstructor() { + void testEmptyConstructor() { NacosSerializationException exception = new NacosSerializationException(); assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode()); assertNull(exception.getMessage()); @@ -33,7 +33,7 @@ public class NacosSerializationExceptionTest { } @Test - public void testConstructorWithSerializedClass() { + void testConstructorWithSerializedClass() { NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class); assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode()); assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ", @@ -42,7 +42,7 @@ public class NacosSerializationExceptionTest { } @Test - public void testConstructorWithCause() { + void testConstructorWithCause() { NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test")); assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode()); assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage()); @@ -50,7 +50,7 @@ public class NacosSerializationExceptionTest { } @Test - public void testConstructorWithSerializedClassAndCause() { + void testConstructorWithSerializedClassAndCause() { NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class, new RuntimeException("test")); assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode()); diff --git a/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java index 3c6188113..737c7a451 100644 --- a/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java @@ -16,16 +16,17 @@ package com.alibaba.nacos.api.model.v2; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ErrorCodeTest { +class ErrorCodeTest { + @Test - public void testCodeNotSame() { + void testCodeNotSame() { Class errorCodeClass = ErrorCode.class; ErrorCode[] errorCodes = errorCodeClass.getEnumConstants(); diff --git a/api/src/test/java/com/alibaba/nacos/api/model/v2/ResultTest.java b/api/src/test/java/com/alibaba/nacos/api/model/v2/ResultTest.java index a67203eb1..18444cdf0 100644 --- a/api/src/test/java/com/alibaba/nacos/api/model/v2/ResultTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/model/v2/ResultTest.java @@ -16,15 +16,15 @@ package com.alibaba.nacos.api.model.v2; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class ResultTest { +class ResultTest { @Test - public void testSuccessEmptyResult() { + void testSuccessEmptyResult() { Result result = Result.success(); assertNull(result.getData()); assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode()); @@ -32,7 +32,7 @@ public class ResultTest { } @Test - public void testSuccessWithData() { + void testSuccessWithData() { Result result = Result.success("test"); assertEquals("test", result.getData()); assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode()); @@ -40,7 +40,7 @@ public class ResultTest { } @Test - public void testFailureMessageResult() { + void testFailureMessageResult() { Result result = Result.failure("test"); assertNull(result.getData()); assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode()); @@ -48,7 +48,7 @@ public class ResultTest { } @Test - public void testFailureWithoutData() { + void testFailureWithoutData() { Result result = Result.failure(ErrorCode.DATA_ACCESS_ERROR); assertNull(result.getData()); assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode()); @@ -56,7 +56,7 @@ public class ResultTest { } @Test - public void testFailureWithData() { + void testFailureWithData() { Result result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error"); assertEquals("error", result.getData()); assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode()); @@ -64,7 +64,7 @@ public class ResultTest { } @Test - public void testToString() { + void testToString() { Result result = Result.success("test"); assertEquals("Result{errorCode=0, message='success', data=test}", result.toString()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/ability/ClientNamingAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/ability/ClientNamingAbilityTest.java index 4dd6dd79c..1a3b971aa 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/ability/ClientNamingAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/ability/ClientNamingAbilityTest.java @@ -16,15 +16,15 @@ package com.alibaba.nacos.api.naming.ability; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ClientNamingAbilityTest { +class ClientNamingAbilityTest { @Test - public void testGetAndSet() { + void testGetAndSet() { ClientNamingAbility ability = new ClientNamingAbility(); assertFalse(ability.isSupportDeltaPush()); assertFalse(ability.isSupportRemoteMetric()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/ability/ServerNamingAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/ability/ServerNamingAbilityTest.java index 978b41f99..4221972e3 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/ability/ServerNamingAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/ability/ServerNamingAbilityTest.java @@ -20,34 +20,33 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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; -public class ServerNamingAbilityTest { +class ServerNamingAbilityTest { private static ObjectMapper jacksonMapper; - @BeforeClass - public static void setUpClass() throws Exception { + @BeforeAll + static void setUpClass() throws Exception { jacksonMapper = new ObjectMapper(); jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException { + void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException { String nonExistItemJson = "{\"exampleAbility\":false}"; ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class); assertFalse(actual.isSupportJraft()); } @Test - public void testEquals() throws JsonProcessingException { + void testEquals() throws JsonProcessingException { ServerNamingAbility expected = new ServerNamingAbility(); expected.setSupportJraft(true); String serializeJson = jacksonMapper.writeValueAsString(expected); @@ -60,19 +59,19 @@ public class ServerNamingAbilityTest { } @Test - public void testEqualsForOneObject() { + void testEqualsForOneObject() { ServerNamingAbility ability = new ServerNamingAbility(); - assertTrue(ability.equals(ability)); + assertEquals(ability, ability); } @Test - public void testEqualsForOtherAbility() { + void testEqualsForOtherAbility() { ServerNamingAbility ability = new ServerNamingAbility(); - assertFalse(ability.equals(new ClientNamingAbility())); + assertNotEquals(ability, new ClientNamingAbility()); } @Test - public void testHashCode() throws JsonProcessingException { + void testHashCode() throws JsonProcessingException { ServerNamingAbility expected = new ServerNamingAbility(); expected.setSupportJraft(true); String serializeJson = jacksonMapper.writeValueAsString(expected); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/listener/NamingEventTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/listener/NamingEventTest.java index c2a6076ff..e918533e5 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/listener/NamingEventTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/listener/NamingEventTest.java @@ -16,26 +16,26 @@ package com.alibaba.nacos.api.naming.listener; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class NamingEventTest { +class NamingEventTest { private MockNamingEventListener eventListener; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { eventListener = new MockNamingEventListener(); } @Test - public void testNamingEventWithSimpleConstructor() { + void testNamingEventWithSimpleConstructor() { NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST); assertEquals("serviceName", event.getServiceName()); assertNull(event.getGroupName()); @@ -49,7 +49,7 @@ public class NamingEventTest { } @Test - public void testNamingEventWithFullConstructor() { + void testNamingEventWithFullConstructor() { NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST); assertEquals("serviceName", event.getServiceName()); assertEquals("group", event.getGroupName()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ClusterTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ClusterTest.java index 6cc8a204e..69910bd28 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ClusterTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ClusterTest.java @@ -22,29 +22,29 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class ClusterTest { +class ClusterTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSetAndGet() { + void testSetAndGet() { Cluster actual = new Cluster(); assertNull(actual.getName()); assertNull(actual.getServiceName()); @@ -72,7 +72,7 @@ public class ClusterTest { } @Test - public void testJsonSerialize() throws JsonProcessingException { + void testJsonSerialize() throws JsonProcessingException { Cluster actual = new Cluster("cluster"); actual.setServiceName("group@@service"); actual.setHealthChecker(new Http()); @@ -91,7 +91,7 @@ public class ClusterTest { } @Test - public void testJsonDeserialize() throws JsonProcessingException { + void testJsonDeserialize() throws JsonProcessingException { String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\"," + "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200}," + "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}"; diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/InstanceTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/InstanceTest.java index 441db3687..07726d078 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/InstanceTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/InstanceTest.java @@ -22,30 +22,31 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class InstanceTest { +class InstanceTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSetAndGet() { + void testSetAndGet() { Instance instance = new Instance(); assertNull(instance.getInstanceId()); assertNull(instance.getIp()); @@ -62,7 +63,7 @@ public class InstanceTest { } @Test - public void testJsonSerialize() throws JsonProcessingException { + void testJsonSerialize() throws JsonProcessingException { Instance instance = new Instance(); setInstance(instance); String actual = mapper.writeValueAsString(instance); @@ -82,7 +83,7 @@ public class InstanceTest { } @Test - public void testJsonDeserialize() throws JsonProcessingException { + void testJsonDeserialize() throws JsonProcessingException { String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false," + "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\"," + "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000," @@ -92,21 +93,21 @@ public class InstanceTest { } @Test - public void testCheckClusterNameFormat() { + void testCheckClusterNameFormat() { Instance instance = new Instance(); instance.setClusterName("demo"); assertEquals("demo", instance.getClusterName()); } @Test - public void testToInetAddr() { + void testToInetAddr() { Instance instance = new Instance(); setInstance(instance); assertEquals("1.1.1.1:1000", instance.toInetAddr()); } @Test - public void testContainsMetadata() { + void testContainsMetadata() { Instance instance = new Instance(); assertFalse(instance.containsMetadata("a")); instance.setMetadata(null); @@ -116,7 +117,7 @@ public class InstanceTest { } @Test - public void testGetInstanceIdGenerator() { + void testGetInstanceIdGenerator() { Instance instance = new Instance(); assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator()); instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test"); @@ -124,19 +125,19 @@ public class InstanceTest { } @Test - public void testEquals() { + void testEquals() { Instance actual = new Instance(); setInstance(actual); actual.setMetadata(new HashMap<>()); actual.addMetadata("a", "b"); - assertFalse(actual.equals(new Object())); + assertNotEquals(actual, new Object()); Instance expected = new Instance(); setInstance(expected); expected.setMetadata(new HashMap<>()); expected.addMetadata("a", "b"); - assertTrue(actual.equals(expected)); + assertEquals(actual, expected); expected.addMetadata("a", "c"); - assertFalse(actual.equals(expected)); + assertNotEquals(actual, expected); } private void setInstance(Instance instance) { diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ListViewTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ListViewTest.java index 562bb71cd..a4a6b574f 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ListViewTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ListViewTest.java @@ -16,19 +16,19 @@ package com.alibaba.nacos.api.naming.pojo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.LinkedList; 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; -public class ListViewTest { +class ListViewTest { @Test - public void testToString() { + void testToString() { List data = new LinkedList<>(); data.add("1"); data.add("2"); @@ -41,7 +41,7 @@ public class ListViewTest { } @Test - public void testSetAndGet() { + void testSetAndGet() { ListView listView = new ListView<>(); assertEquals(0, listView.getCount()); assertNull(listView.getData()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceInfoTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceInfoTest.java index 271431800..4ff58f938 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceInfoTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceInfoTest.java @@ -20,8 +20,8 @@ import com.alibaba.nacos.api.utils.StringUtils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -30,25 +30,26 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ServiceInfoTest { +class ServiceInfoTest { private ObjectMapper mapper; private ServiceInfo serviceInfo; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); serviceInfo = new ServiceInfo("G@@testName", "testClusters"); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { String actual = mapper.writeValueAsString(serviceInfo); assertTrue(actual.contains("\"name\":\"G@@testName\"")); assertTrue(actual.contains("\"clusters\":\"testClusters\"")); @@ -64,7 +65,7 @@ public class ServiceInfoTest { } @Test - public void testDeserialize() throws IOException { + void testDeserialize() throws IOException { String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[]," + "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}"; ServiceInfo actual = mapper.readValue(example, ServiceInfo.class); @@ -82,14 +83,14 @@ public class ServiceInfoTest { } @Test - public void testGetKey() { + void testGetKey() { String key = serviceInfo.getKey(); assertEquals("G@@testName@@testClusters", key); assertEquals("G@@testName@@testClusters", serviceInfo.toString()); } @Test - public void testGetKeyEncode() { + void testGetKeyEncode() { String key = serviceInfo.getKeyEncoded(); String encodeName = null; try { @@ -101,7 +102,7 @@ public class ServiceInfoTest { } @Test - public void testServiceInfoConstructor() { + void testServiceInfoConstructor() { String key1 = "group@@name"; String key2 = "group@@name@@c2"; ServiceInfo s1 = new ServiceInfo(key1); @@ -110,32 +111,34 @@ public class ServiceInfoTest { assertEquals(key2, s2.getKey()); } - @Test(expected = IllegalArgumentException.class) - public void testServiceInfoConstructorWithError() { - String key1 = "name"; - ServiceInfo s1 = new ServiceInfo(key1); + @Test + void testServiceInfoConstructorWithError() { + assertThrows(IllegalArgumentException.class, () -> { + String key1 = "name"; + ServiceInfo s1 = new ServiceInfo(key1); + }); } @Test - public void testValidateForAllIps() { + void testValidateForAllIps() { serviceInfo.setAllIPs(true); assertTrue(serviceInfo.validate()); } @Test - public void testValidateForNullHosts() { + void testValidateForNullHosts() { serviceInfo.setHosts(null); assertFalse(serviceInfo.validate()); } @Test - public void testValidateForEmptyHosts() { + void testValidateForEmptyHosts() { serviceInfo.setHosts(Collections.EMPTY_LIST); assertFalse(serviceInfo.validate()); } @Test - public void testValidateForUnhealthyHosts() { + void testValidateForUnhealthyHosts() { Instance instance = new Instance(); instance.setHealthy(false); serviceInfo.addHost(instance); @@ -143,7 +146,7 @@ public class ServiceInfoTest { } @Test - public void testValidateForBothUnhealthyAndHealthyHosts() { + void testValidateForBothUnhealthyAndHealthyHosts() { List instanceList = new LinkedList<>(); Instance instance = new Instance(); instanceList.add(instance); @@ -155,7 +158,7 @@ public class ServiceInfoTest { } @Test - public void testFromKey() { + void testFromKey() { String key1 = "group@@name"; String key2 = "group@@name@@c2"; ServiceInfo s1 = ServiceInfo.fromKey(key1); @@ -165,7 +168,7 @@ public class ServiceInfoTest { } @Test - public void testSetAndGet() throws JsonProcessingException { + void testSetAndGet() throws JsonProcessingException { serviceInfo.setReachProtectionThreshold(true); serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo)); ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceTest.java index 518b57ea0..d13eea441 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/ServiceTest.java @@ -16,19 +16,19 @@ package com.alibaba.nacos.api.naming.pojo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; -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; -public class ServiceTest { +class ServiceTest { @Test - public void testSetAndGet() { + void testSetAndGet() { Service service = new Service(); assertNull(service.getName()); assertNull(service.getAppName()); @@ -51,12 +51,13 @@ public class ServiceTest { } @Test - public void testToString() { + void testToString() { Service service = new Service("service"); service.setGroupName("group"); service.setAppName("app"); service.setProtectThreshold(1.0f); service.setMetadata(Collections.singletonMap("a", "b")); - assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", service.toString()); + assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", + service.toString()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/builder/InstanceBuilderTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/builder/InstanceBuilderTest.java index c53985927..574db46c3 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/builder/InstanceBuilderTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/builder/InstanceBuilderTest.java @@ -17,18 +17,18 @@ package com.alibaba.nacos.api.naming.pojo.builder; import com.alibaba.nacos.api.naming.pojo.Instance; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class InstanceBuilderTest { +class InstanceBuilderTest { private static final String SERVICE_NAME = "testService"; @@ -53,7 +53,7 @@ public class InstanceBuilderTest { private static final String META_VALUE = "value"; @Test - public void testBuildFullInstance() { + void testBuildFullInstance() { InstanceBuilder builder = InstanceBuilder.newBuilder(); Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID) .setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED) @@ -72,7 +72,7 @@ public class InstanceBuilderTest { } @Test - public void testBuildInstanceWithoutNewMetadata() { + void testBuildInstanceWithoutNewMetadata() { InstanceBuilder builder = InstanceBuilder.newBuilder(); Map metadata = new HashMap<>(); metadata.put("test", "test"); @@ -90,7 +90,7 @@ public class InstanceBuilderTest { } @Test - public void testBuildEmptyInstance() { + void testBuildEmptyInstance() { InstanceBuilder builder = InstanceBuilder.newBuilder(); Instance actual = builder.build(); assertNull(actual.getServiceName()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/AbstractHealthCheckerTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/AbstractHealthCheckerTest.java index 1ba45355f..22f9cd4cf 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/AbstractHealthCheckerTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/AbstractHealthCheckerTest.java @@ -20,26 +20,26 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.NamedType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; -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; -public class AbstractHealthCheckerTest { +class AbstractHealthCheckerTest { private final ObjectMapper objectMapper = new ObjectMapper(); - @Before - public void setUp() { + @BeforeEach + void setUp() { objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE)); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { TestChecker testChecker = new TestChecker(); testChecker.setTestValue(""); String actual = objectMapper.writeValueAsString(testChecker); @@ -48,7 +48,7 @@ public class AbstractHealthCheckerTest { } @Test - public void testDeserialize() throws IOException { + void testDeserialize() throws IOException { String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}"; TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class); assertEquals("", actual.getTestValue()); @@ -56,7 +56,7 @@ public class AbstractHealthCheckerTest { } @Test - public void testClone() throws CloneNotSupportedException { + void testClone() throws CloneNotSupportedException { AbstractHealthChecker none = new AbstractHealthChecker.None().clone(); assertEquals(AbstractHealthChecker.None.class, none.getClass()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckTypeTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckTypeTest.java index b5e8e5237..cd75c7edd 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckTypeTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckTypeTest.java @@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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; -public class HealthCheckTypeTest { +class HealthCheckTypeTest { @Test - public void testOfHealthCheckerClassForBuildInType() { + void testOfHealthCheckerClassForBuildInType() { assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP")); assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP")); assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL")); @@ -37,18 +37,18 @@ public class HealthCheckTypeTest { } @Test - public void testOfHealthCheckerClassForExtendType() { + void testOfHealthCheckerClassForExtendType() { HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class); assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE)); } @Test - public void testOfHealthCheckerClassForNonExistType() { + void testOfHealthCheckerClassForNonExistType() { assertNull(HealthCheckType.ofHealthCheckerClass("non-exist")); } @Test - public void testGetLoadedHealthCheckerClasses() { + void testGetLoadedHealthCheckerClasses() { HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class); List> actual = HealthCheckType.getLoadedHealthCheckerClasses(); assertEquals(5, actual.size()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckerFactoryTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckerFactoryTest.java index 9e60f4842..340b16f72 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckerFactoryTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/HealthCheckerFactoryTest.java @@ -19,75 +19,80 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck; import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException; import com.alibaba.nacos.api.exception.runtime.NacosSerializationException; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class HealthCheckerFactoryTest { +class HealthCheckerFactoryTest { - @BeforeClass - public static void beforeClass() { + @BeforeAll + static void beforeClass() { HealthCheckerFactory.registerSubType(new TestChecker()); } @Test - public void testSerialize() { + void testSerialize() { Tcp tcp = new Tcp(); String actual = HealthCheckerFactory.serialize(tcp); assertTrue(actual.contains("\"type\":\"TCP\"")); } @Test - public void testSerializeExtend() { + void testSerializeExtend() { TestChecker testChecker = new TestChecker(); String actual = HealthCheckerFactory.serialize(testChecker); assertTrue(actual.contains("\"type\":\"TEST\"")); } @Test - public void testDeserialize() { + void testDeserialize() { String tcpString = "{\"type\":\"TCP\"}"; AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString); assertEquals(Tcp.class, actual.getClass()); } @Test - public void testDeserializeExtend() { + void testDeserializeExtend() { String tcpString = "{\"type\":\"TEST\",\"testValue\":null}"; AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString); assertEquals(TestChecker.class, actual.getClass()); } @Test - public void testSerializeNoRegister() { + void testSerializeNoRegister() { NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker(); assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register")); } @Test - public void testDeserializeNoRegister() { + void testDeserializeNoRegister() { String tcpString = "{\"type\":\"no register\",\"testValue\":null}"; AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString); assertEquals(AbstractHealthChecker.None.class, actual.getClass()); } - @Test(expected = NacosSerializationException.class) - public void testSerializeFailure() { - SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker(); - System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker)); - } - - @Test(expected = NacosDeserializationException.class) - public void testDeserializeFailure() { - String errorString = "{\"type\"=\"TCP\"}"; - System.out.println(HealthCheckerFactory.deserialize(errorString)); + @Test + void testSerializeFailure() { + assertThrows(NacosSerializationException.class, () -> { + SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker(); + System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker)); + }); } @Test - public void testCreateNoneHealthChecker() { + void testDeserializeFailure() { + assertThrows(NacosDeserializationException.class, () -> { + String errorString = "{\"type\"=\"TCP\"}"; + System.out.println(HealthCheckerFactory.deserialize(errorString)); + }); + } + + @Test + void testCreateNoneHealthChecker() { assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/TestChecker.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/TestChecker.java index 4d2e8c0a2..f570245d0 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/TestChecker.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/TestChecker.java @@ -28,6 +28,10 @@ public class TestChecker extends AbstractHealthChecker { private String testValue; + public TestChecker() { + super(TYPE); + } + public String getTestValue() { return testValue; } @@ -36,10 +40,6 @@ public class TestChecker extends AbstractHealthChecker { this.testValue = testValue; } - public TestChecker() { - super(TYPE); - } - @Override public AbstractHealthChecker clone() throws CloneNotSupportedException { return null; diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/HttpTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/HttpTest.java index f23918d30..5c93e8354 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/HttpTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/HttpTest.java @@ -18,36 +18,37 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Map; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class HttpTest { +class HttpTest { private ObjectMapper objectMapper; private Http http; - @Before - public void setUp() { + @BeforeEach + void setUp() { objectMapper = new ObjectMapper(); http = new Http(); } @Test - public void testGetExpectedResponseCodeWithEmpty() { + void testGetExpectedResponseCodeWithEmpty() { http.setHeaders(""); assertTrue(http.getCustomHeaders().isEmpty()); } @Test - public void testGetExpectedResponseCodeWithoutEmpty() { + void testGetExpectedResponseCodeWithoutEmpty() { http.setHeaders("x:a|y:"); Map actual = http.getCustomHeaders(); assertFalse(actual.isEmpty()); @@ -56,7 +57,7 @@ public class HttpTest { } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { http.setHeaders("x:a|y:"); http.setPath("/x"); String actual = objectMapper.writeValueAsString(http); @@ -67,7 +68,7 @@ public class HttpTest { } @Test - public void testDeserialize() throws IOException { + void testDeserialize() throws IOException { String testChecker = "{\"type\":\"HTTP\",\"path\":\"/x\",\"headers\":\"x:a|y:\",\"expectedResponseCode\":200}"; Http actual = objectMapper.readValue(testChecker, Http.class); assertEquals("x:a|y:", actual.getHeaders()); @@ -78,23 +79,23 @@ public class HttpTest { } @Test - public void testClone() throws CloneNotSupportedException { + void testClone() throws CloneNotSupportedException { Http cloned = http.clone(); assertEquals(http.hashCode(), cloned.hashCode()); - assertTrue(http.equals(cloned)); + assertEquals(http, cloned); } @Test - public void testNotEquals() throws CloneNotSupportedException { - assertFalse(http.equals(new Tcp())); + void testNotEquals() throws CloneNotSupportedException { + assertNotEquals(http, new Tcp()); Http cloned = http.clone(); cloned.setPath("aaa"); - assertFalse(http.equals(cloned)); + assertNotEquals(http, cloned); cloned = http.clone(); cloned.setHeaders("aaa"); - assertFalse(http.equals(cloned)); + assertNotEquals(http, cloned); cloned = http.clone(); cloned.setExpectedResponseCode(500); - assertFalse(http.equals(cloned)); + assertNotEquals(http, cloned); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/MysqlTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/MysqlTest.java index 7dfd6ad92..3e11d8885 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/MysqlTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/MysqlTest.java @@ -18,23 +18,23 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class MysqlTest { +class MysqlTest { private ObjectMapper objectMapper; private Mysql mysql; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mysql = new Mysql(); mysql.setUser("user"); mysql.setPwd("pwd"); @@ -43,7 +43,7 @@ public class MysqlTest { } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { String actual = objectMapper.writeValueAsString(mysql); assertTrue(actual.contains("\"user\":\"user\"")); assertTrue(actual.contains("\"type\":\"MYSQL\"")); @@ -52,7 +52,7 @@ public class MysqlTest { } @Test - public void testDeserialize() throws IOException { + void testDeserialize() throws IOException { String testChecker = "{\"type\":\"MYSQL\",\"user\":\"user\",\"pwd\":\"pwd\",\"cmd\":\"cmd\"}"; Mysql actual = objectMapper.readValue(testChecker, Mysql.class); assertEquals("cmd", actual.getCmd()); @@ -62,23 +62,23 @@ public class MysqlTest { } @Test - public void testClone() throws CloneNotSupportedException { + void testClone() throws CloneNotSupportedException { Mysql cloned = mysql.clone(); assertEquals(mysql.hashCode(), cloned.hashCode()); - assertTrue(mysql.equals(cloned)); + assertEquals(mysql, cloned); } @Test - public void testNotEquals() throws CloneNotSupportedException { - assertFalse(mysql.equals(new Tcp())); + void testNotEquals() throws CloneNotSupportedException { + assertNotEquals(mysql, new Tcp()); Mysql cloned = mysql.clone(); cloned.setUser("aaa"); - assertFalse(mysql.equals(cloned)); + assertNotEquals(mysql, cloned); cloned = mysql.clone(); cloned.setPwd("aaa"); - assertFalse(mysql.equals(cloned)); + assertNotEquals(mysql, cloned); cloned = mysql.clone(); cloned.setCmd("aaa"); - assertFalse(mysql.equals(cloned)); + assertNotEquals(mysql, cloned); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/TcpTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/TcpTest.java index d1c57bc4c..5d02ef946 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/TcpTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/pojo/healthcheck/impl/TcpTest.java @@ -16,18 +16,17 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class TcpTest { +class TcpTest { @Test - public void testClone() throws CloneNotSupportedException { + void testClone() throws CloneNotSupportedException { Tcp original = new Tcp(); Tcp cloned = original.clone(); assertEquals(original.hashCode(), cloned.hashCode()); - assertTrue(original.equals(cloned)); + assertEquals(original, cloned); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BasedNamingRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BasedNamingRequestTest.java index 435b44611..3804dc173 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BasedNamingRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BasedNamingRequestTest.java @@ -19,11 +19,11 @@ package com.alibaba.nacos.api.naming.remote.request; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE; -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; public abstract class BasedNamingRequestTest { @@ -35,7 +35,7 @@ public abstract class BasedNamingRequestTest { protected static ObjectMapper mapper; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BatchInstanceRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BatchInstanceRequestTest.java index af4127ddd..8a48fa101 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BatchInstanceRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/BatchInstanceRequestTest.java @@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.remote.request; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class BatchInstanceRequestTest extends BasedNamingRequestTest { +class BatchInstanceRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { BatchInstanceRequest request = new BatchInstanceRequest(NAMESPACE, SERVICE, GROUP, NamingRemoteConstants.BATCH_REGISTER_INSTANCE, Collections.singletonList(new Instance())); String json = mapper.writeValueAsString(request); @@ -39,7 +39,7 @@ public class BatchInstanceRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"type\":\"batchRegisterInstance\",\"instances\":[{\"port\":0,\"weight\":1.0,\"healthy\":true," + "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\"," diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/InstanceRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/InstanceRequestTest.java index 72c34af4c..5237df646 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/InstanceRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/InstanceRequestTest.java @@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class InstanceRequestTest extends BasedNamingRequestTest { +class InstanceRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { InstanceRequest request = new InstanceRequest(NAMESPACE, SERVICE, GROUP, NamingRemoteConstants.REGISTER_INSTANCE, new Instance()); String json = mapper.writeValueAsString(request); @@ -37,7 +37,7 @@ public class InstanceRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true," + "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\"," diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/NotifySubscriberRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/NotifySubscriberRequestTest.java index e8dd9df46..a60eaf98c 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/NotifySubscriberRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/NotifySubscriberRequestTest.java @@ -21,14 +21,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE; -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; -public class NotifySubscriberRequestTest { +class NotifySubscriberRequestTest { private static final String SERVICE = "service"; @@ -38,15 +38,15 @@ public class NotifySubscriberRequestTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE); NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo); request.setServiceName(SERVICE); @@ -58,7 +58,7 @@ public class NotifySubscriberRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"serviceInfo\":{\"name\":\"service\",\"groupName\":\"group\",\"cacheMillis\":1000,\"hosts\":[]," + "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false," diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/PersistentInstanceRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/PersistentInstanceRequestTest.java index be358447a..41ea9ae5d 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/PersistentInstanceRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/PersistentInstanceRequestTest.java @@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class PersistentInstanceRequestTest extends BasedNamingRequestTest { +class PersistentInstanceRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { PersistentInstanceRequest request = new PersistentInstanceRequest(NAMESPACE, SERVICE, GROUP, NamingRemoteConstants.REGISTER_INSTANCE, new Instance()); String json = mapper.writeValueAsString(request); @@ -37,7 +37,7 @@ public class PersistentInstanceRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true," + "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\"," diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceListRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceListRequestTest.java index 8014e5b60..a0e897495 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceListRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceListRequestTest.java @@ -17,16 +17,16 @@ package com.alibaba.nacos.api.naming.remote.request; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE; -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; -public class ServiceListRequestTest extends BasedNamingRequestTest { +class ServiceListRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10); request.setSelector("label"); String json = mapper.writeValueAsString(request); @@ -39,7 +39,7 @@ public class ServiceListRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"\",\"groupName\":\"group\"," + "\"pageNo\":1,\"pageSize\":10,\"selector\":\"label\",\"module\":\"naming\"}"; ServiceListRequest actual = mapper.readValue(json, ServiceListRequest.class); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceQueryRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceQueryRequestTest.java index 609a33caa..93e039220 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceQueryRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/ServiceQueryRequestTest.java @@ -18,15 +18,15 @@ package com.alibaba.nacos.api.naming.remote.request; import com.alibaba.nacos.api.common.Constants; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class ServiceQueryRequestTest extends BasedNamingRequestTest { +class ServiceQueryRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ServiceQueryRequest request = new ServiceQueryRequest(NAMESPACE, SERVICE, GROUP); request.setCluster(Constants.DEFAULT_CLUSTER_NAME); String json = mapper.writeValueAsString(request); @@ -37,7 +37,7 @@ public class ServiceQueryRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"cluster\":\"DEFAULT\",\"healthyOnly\":true,\"udpPort\":0,\"module\":\"naming\"}"; ServiceQueryRequest actual = mapper.readValue(json, ServiceQueryRequest.class); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/SubscribeServiceRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/SubscribeServiceRequestTest.java index 1eabfb40a..f0a76876b 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/SubscribeServiceRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/request/SubscribeServiceRequestTest.java @@ -17,16 +17,16 @@ package com.alibaba.nacos.api.naming.remote.request; import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class SubscribeServiceRequestTest extends BasedNamingRequestTest { +class SubscribeServiceRequestTest extends BasedNamingRequestTest { @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true); String json = mapper.writeValueAsString(request); checkSerializeBasedInfo(json); @@ -35,7 +35,7 @@ public class SubscribeServiceRequestTest extends BasedNamingRequestTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\"," + "\"subscribe\":false,\"clusters\":\"aa,bb\",\"module\":\"naming\"}"; SubscribeServiceRequest actual = mapper.readValue(json, SubscribeServiceRequest.class); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/BatchInstanceResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/BatchInstanceResponseTest.java index bb8c40987..74e37c332 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/BatchInstanceResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/BatchInstanceResponseTest.java @@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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; -public class BatchInstanceResponseTest { +class BatchInstanceResponseTest { protected static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\"")); } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"registerInstance\",\"success\":true}"; BatchInstanceResponse response = mapper.readValue(json, BatchInstanceResponse.class); assertEquals(NamingRemoteConstants.REGISTER_INSTANCE, response.getType()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponseTest.java index 1f448824a..33dafa785 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponseTest.java @@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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; -public class InstanceResponseTest { +class InstanceResponseTest { protected static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\"")); } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"deregisterInstance\",\"success\":true}"; InstanceResponse response = mapper.readValue(json, InstanceResponse.class); assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, response.getType()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/QueryServiceResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/QueryServiceResponseTest.java index cc98aebf8..a75d7c89e 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/QueryServiceResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/QueryServiceResponseTest.java @@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class QueryServiceResponseTest { +class QueryServiceResponseTest { protected static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerializeSuccessResponse() throws JsonProcessingException { + void testSerializeSuccessResponse() throws JsonProcessingException { QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo()); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"serviceInfo\":{")); @@ -49,7 +49,7 @@ public class QueryServiceResponseTest { } @Test - public void testSerializeFailResponse() throws JsonProcessingException { + void testSerializeFailResponse() throws JsonProcessingException { QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test"); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"resultCode\":500")); @@ -59,7 +59,7 @@ public class QueryServiceResponseTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[]," + "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false," + "\"valid\":true},\"success\":true}"; diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/ServiceListResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/ServiceListResponseTest.java index 8fc59aade..1f9c8b219 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/ServiceListResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/ServiceListResponseTest.java @@ -20,27 +20,27 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class ServiceListResponseTest { +class ServiceListResponseTest { protected static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerializeSuccessResponse() throws JsonProcessingException { + void testSerializeSuccessResponse() throws JsonProcessingException { ServiceListResponse response = ServiceListResponse.buildSuccessResponse(10, Collections.singletonList("a")); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"count\":10")); @@ -51,7 +51,7 @@ public class ServiceListResponseTest { } @Test - public void testSerializeFailResponse() throws JsonProcessingException { + void testSerializeFailResponse() throws JsonProcessingException { ServiceListResponse response = ServiceListResponse.buildFailResponse("test"); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"resultCode\":500")); @@ -61,7 +61,7 @@ public class ServiceListResponseTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"count\":10,\"serviceNames\":[\"a\"],\"success\":true}"; ServiceListResponse response = mapper.readValue(json, ServiceListResponse.class); assertEquals(10, response.getCount()); diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/SubscribeServiceResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/SubscribeServiceResponseTest.java index ba2288bc8..d52902aa8 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/SubscribeServiceResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/remote/response/SubscribeServiceResponseTest.java @@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class SubscribeServiceResponseTest { +class SubscribeServiceResponseTest { protected static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerializeSuccessResponse() throws JsonProcessingException { + void testSerializeSuccessResponse() throws JsonProcessingException { SubscribeServiceResponse response = new SubscribeServiceResponse(200, null, new ServiceInfo()); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"serviceInfo\":{")); @@ -49,7 +49,7 @@ public class SubscribeServiceResponseTest { } @Test - public void testSerializeFailResponse() throws JsonProcessingException { + void testSerializeFailResponse() throws JsonProcessingException { SubscribeServiceResponse response = new SubscribeServiceResponse(500, "test", null); String json = mapper.writeValueAsString(response); assertTrue(json.contains("\"resultCode\":500")); @@ -59,7 +59,7 @@ public class SubscribeServiceResponseTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[]," + "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false," + "\"valid\":true},\"success\":true}"; diff --git a/api/src/test/java/com/alibaba/nacos/api/naming/utils/NamingUtilsTest.java b/api/src/test/java/com/alibaba/nacos/api/naming/utils/NamingUtilsTest.java index 55eb315c6..8b64bb6b1 100644 --- a/api/src/test/java/com/alibaba/nacos/api/naming/utils/NamingUtilsTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/naming/utils/NamingUtilsTest.java @@ -21,107 +21,117 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.utils.StringUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class NamingUtilsTest { +class NamingUtilsTest { @Test - public void testGetGroupedName() { + void testGetGroupedName() { assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group")); } - @Test(expected = IllegalArgumentException.class) - public void testGetGroupedNameWithoutGroup() { - NamingUtils.getGroupedName("serviceName", ""); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetGroupedNameWithoutServiceName() { - NamingUtils.getGroupedName("", "group"); + @Test + void testGetGroupedNameWithoutGroup() { + assertThrows(IllegalArgumentException.class, () -> { + NamingUtils.getGroupedName("serviceName", ""); + }); } @Test - public void testGetServiceName() { + void testGetGroupedNameWithoutServiceName() { + assertThrows(IllegalArgumentException.class, () -> { + NamingUtils.getGroupedName("", "group"); + }); + } + + @Test + void testGetServiceName() { String validServiceName = "group@@serviceName"; assertEquals("serviceName", NamingUtils.getServiceName(validServiceName)); } @Test - public void testGetServiceNameWithoutGroup() { + void testGetServiceNameWithoutGroup() { String serviceName = "serviceName"; assertEquals(serviceName, NamingUtils.getServiceName(serviceName)); } @Test - public void testGetServiceNameWithEmpty() { + void testGetServiceNameWithEmpty() { assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null)); } @Test - public void testGetGroupName() { + void testGetGroupName() { String validServiceName = "group@@serviceName"; assertEquals("group", NamingUtils.getGroupName(validServiceName)); } @Test - public void testGetGroupNameWithoutGroup() { + void testGetGroupNameWithoutGroup() { String serviceName = "serviceName"; assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName)); } @Test - public void testGetGroupNameWithEmpty() { + void testGetGroupNameWithEmpty() { assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null)); } @Test - public void testIsServiceNameCompatibilityMode() { + void testIsServiceNameCompatibilityMode() { String serviceName1 = "group@@serviceName"; assertTrue(NamingUtils.isServiceNameCompatibilityMode(serviceName1)); - + String serviceName2 = "serviceName"; assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName2)); - + String serviceName3 = null; assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName3)); } @Test - public void testCheckServiceNameFormat() { + void testCheckServiceNameFormat() { String validServiceName = "group@@serviceName"; NamingUtils.checkServiceNameFormat(validServiceName); } - @Test(expected = IllegalArgumentException.class) - public void testCheckServiceNameFormatWithoutGroupAndService() { - String validServiceName = "@@"; - NamingUtils.checkServiceNameFormat(validServiceName); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckServiceNameFormatWithoutGroup() { - String validServiceName = "@@service"; - NamingUtils.checkServiceNameFormat(validServiceName); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckServiceNameFormatWithoutService() { - String validServiceName = "group@@"; - NamingUtils.checkServiceNameFormat(validServiceName); + @Test + void testCheckServiceNameFormatWithoutGroupAndService() { + assertThrows(IllegalArgumentException.class, () -> { + String validServiceName = "@@"; + NamingUtils.checkServiceNameFormat(validServiceName); + }); } @Test - public void testGetGroupedNameOptional() { + void testCheckServiceNameFormatWithoutGroup() { + assertThrows(IllegalArgumentException.class, () -> { + String validServiceName = "@@service"; + NamingUtils.checkServiceNameFormat(validServiceName); + }); + } + + @Test + void testCheckServiceNameFormatWithoutService() { + assertThrows(IllegalArgumentException.class, () -> { + String validServiceName = "group@@"; + NamingUtils.checkServiceNameFormat(validServiceName); + }); + } + + @Test + void testGetGroupedNameOptional() { String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA"); assertEquals("groupA@@", onlyGroupName); @@ -133,7 +143,7 @@ public class NamingUtilsTest { } @Test - public void testCheckInstanceIsLegal() throws NacosException { + void testCheckInstanceIsLegal() throws NacosException { // check invalid clusterName Instance instance = new Instance(); instance.setClusterName("cluster1,cluster2"); @@ -151,7 +161,7 @@ public class NamingUtilsTest { instance.setClusterName("cluster1"); NamingUtils.checkInstanceIsLegal(instance); assertTrue(true); - + // check heartBeatTimeout, heartBeatInterval, ipDeleteTimeout Map meta = new HashMap<>(); meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "1"); @@ -163,8 +173,7 @@ public class NamingUtilsTest { assertTrue(false); } catch (Exception e) { assertTrue(e instanceof NacosException); - assertEquals( - "Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.", + assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.", e.getMessage()); } meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "3"); @@ -175,7 +184,7 @@ public class NamingUtilsTest { } @Test - public void testBatchCheckInstanceIsLegal() throws NacosException { + void testBatchCheckInstanceIsLegal() throws NacosException { // check invalid clusterName Instance instance = new Instance(); instance.setClusterName("cluster1,cluster2"); @@ -212,8 +221,7 @@ public class NamingUtilsTest { assertTrue(false); } catch (Exception e) { assertTrue(e instanceof NacosException); - assertEquals( - "Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.", + assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.", e.getMessage()); } instanceList.remove(instance); @@ -228,7 +236,7 @@ public class NamingUtilsTest { } @Test - public void testCheckInstanceIsEphemeral() throws NacosException { + void testCheckInstanceIsEphemeral() throws NacosException { Instance instance = new Instance(); instance.setIp("127.0.0.1"); instance.setPort(9089); @@ -241,12 +249,12 @@ public class NamingUtilsTest { instance.setEphemeral(false); NamingUtils.checkInstanceIsEphemeral(instance); } catch (NacosException e) { - Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM); + assertEquals(NacosException.INVALID_PARAM, e.getErrCode()); } } - + @Test - public void testCheckInstanceIsNull() throws NacosException { + void testCheckInstanceIsNull() throws NacosException { Instance instance = new Instance(); instance.setIp("127.0.0.1"); instance.setPort(9089); @@ -254,15 +262,15 @@ public class NamingUtilsTest { try { NamingUtils.checkInstanceIsLegal(null); } catch (NacosException e) { - Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM); + assertEquals(NacosException.INVALID_PARAM, e.getErrCode()); } } @Test - public void testIsNumber() { + void testIsNumber() { String str1 = "abc"; - assertTrue(!NamingUtils.isNumber(str1)); - + assertFalse(NamingUtils.isNumber(str1)); + String str2 = "123456"; assertTrue(NamingUtils.isNumber(str2)); } diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/AbstractPushCallBackTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/AbstractPushCallBackTest.java index 8ccb82f2a..b415eae67 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/AbstractPushCallBackTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/AbstractPushCallBackTest.java @@ -16,18 +16,18 @@ package com.alibaba.nacos.api.remote; -import org.junit.Test; +import org.junit.jupiter.api.Test; -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; -public class AbstractPushCallBackTest { +class AbstractPushCallBackTest { boolean testValue; @Test - public void testAbstractPushCallBack() { + void testAbstractPushCallBack() { AbstractPushCallBack callBack = new AbstractPushCallBack(2000) { @Override diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/AbstractRequestCallBackTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/AbstractRequestCallBackTest.java index 3af0a9104..4a9d74530 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/AbstractRequestCallBackTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/AbstractRequestCallBackTest.java @@ -18,20 +18,20 @@ package com.alibaba.nacos.api.remote; import com.alibaba.nacos.api.remote.response.ErrorResponse; import com.alibaba.nacos.api.remote.response.Response; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.Executor; -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; -public class AbstractRequestCallBackTest { +class AbstractRequestCallBackTest { boolean testValue; @Test - public void testAbstractPushCallBack() { + void testAbstractPushCallBack() { AbstractRequestCallBack callBack = new AbstractRequestCallBack() { @Override public Executor getExecutor() { diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/DefaultRequestFutureTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/DefaultRequestFutureTest.java index 854e6b465..e8f778a6d 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/DefaultRequestFutureTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/DefaultRequestFutureTest.java @@ -17,27 +17,28 @@ package com.alibaba.nacos.api.remote; import com.alibaba.nacos.api.remote.response.Response; -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.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -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; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; -@RunWith(MockitoJUnitRunner.class) -public class DefaultRequestFutureTest { +@ExtendWith(MockitoExtension.class) +class DefaultRequestFutureTest { private static final String CONNECTION_ID = "1233_1.1.1.1_3306"; @@ -51,17 +52,17 @@ public class DefaultRequestFutureTest { private long timestamp; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { timestamp = System.currentTimeMillis(); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { } @Test - public void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException { + void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException { DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); new Thread(() -> { try { @@ -79,7 +80,7 @@ public class DefaultRequestFutureTest { } @Test - public void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException { + void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException { DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); new Thread(() -> { try { @@ -97,7 +98,7 @@ public class DefaultRequestFutureTest { } @Test - public void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException { + void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException { DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); new Thread(() -> { try { @@ -115,7 +116,7 @@ public class DefaultRequestFutureTest { } @Test - public void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException { + void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException { DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); new Thread(() -> { try { @@ -132,14 +133,16 @@ public class DefaultRequestFutureTest { assertTrue(requestFuture.getTimeStamp() >= timestamp); } - @Test(expected = TimeoutException.class) - public void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException { - DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); - requestFuture.get(100L); + @Test + void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException { + assertThrows(TimeoutException.class, () -> { + DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID); + requestFuture.get(100L); + }); } @Test - public void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException { + void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger); new Thread(() -> { @@ -159,7 +162,7 @@ public class DefaultRequestFutureTest { } @Test - public void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException { + void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger); new Thread(() -> { @@ -179,7 +182,7 @@ public class DefaultRequestFutureTest { } @Test - public void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException { + void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger); new Thread(() -> { @@ -198,19 +201,21 @@ public class DefaultRequestFutureTest { assertFalse(trigger.isTimeout); } - @Test(expected = TimeoutException.class) - public void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException { - MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); - DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger); - try { - requestFuture.get(100L); - } finally { - assertTrue(trigger.isTimeout); - } + @Test + void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException { + assertThrows(TimeoutException.class, () -> { + MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); + DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger); + try { + requestFuture.get(100L); + } finally { + assertTrue(trigger.isTimeout); + } + }); } @Test - public void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException { + void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); MockRequestCallback callback = new MockRequestCallback(200L); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger); @@ -229,7 +234,7 @@ public class DefaultRequestFutureTest { } @Test - public void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException { + void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); MockRequestCallback callback = new MockRequestCallback(executor, 200L); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger); @@ -246,7 +251,7 @@ public class DefaultRequestFutureTest { } @Test - public void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException { + void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); MockRequestCallback callback = new MockRequestCallback(1000L); DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger); @@ -265,10 +270,11 @@ public class DefaultRequestFutureTest { } @Test - public void testASyncGetResponseFailureWithTimeout() throws InterruptedException { + void testASyncGetResponseFailureWithTimeout() throws InterruptedException { MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger(); MockRequestCallback callback = new MockRequestCallback(100L); - final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger); + final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, + trigger); TimeUnit.MILLISECONDS.sleep(500); assertNull(callback.response); assertTrue(callback.exception instanceof TimeoutException); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/RpcScheduledExecutorTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/RpcScheduledExecutorTest.java index 097bd116f..fea7d7c90 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/RpcScheduledExecutorTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/RpcScheduledExecutorTest.java @@ -16,24 +16,24 @@ package com.alibaba.nacos.api.remote; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -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; -public class RpcScheduledExecutorTest { +class RpcScheduledExecutorTest { private static final String NAME = "test.rpc.thread"; Map threadNameMap = new ConcurrentHashMap<>(); @Test - public void testRpcScheduledExecutor() throws InterruptedException { + void testRpcScheduledExecutor() throws InterruptedException { RpcScheduledExecutor executor = new RpcScheduledExecutor(2, NAME); CountDownLatch latch = new CountDownLatch(2); executor.submit(new TestRunner(1, latch)); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/ability/ClientRemoteAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/ability/ClientRemoteAbilityTest.java index 9e84a5d22..21d608729 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/ability/ClientRemoteAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/ability/ClientRemoteAbilityTest.java @@ -20,32 +20,32 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -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; -public class ClientRemoteAbilityTest { +class ClientRemoteAbilityTest { private static ObjectMapper mapper; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { ClientRemoteAbility abilities = new ClientRemoteAbility(); String json = mapper.writeValueAsString(abilities); assertEquals("{\"supportRemoteConnection\":false}", json); } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"supportRemoteConnection\":true}"; ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class); assertTrue(abilities.isSupportRemoteConnection()); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/ability/ServerRemoteAbilityTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/ability/ServerRemoteAbilityTest.java index a2df42324..6265c68bc 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/ability/ServerRemoteAbilityTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/ability/ServerRemoteAbilityTest.java @@ -20,37 +20,37 @@ import com.alibaba.nacos.api.ability.ClientAbilities; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.MapperFeature; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class ServerRemoteAbilityTest { +class ServerRemoteAbilityTest { private static ObjectMapper mapper; private ServerRemoteAbility serverAbilities; - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + static void setUpBeforeClass() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { serverAbilities = new ServerRemoteAbility(); } @Test - public void testSerialize() throws JsonProcessingException { + void testSerialize() throws JsonProcessingException { serverAbilities = new ServerRemoteAbility(); String json = mapper.writeValueAsString(serverAbilities); assertTrue(json.contains("\"supportRemoteConnection\":false")); @@ -58,7 +58,7 @@ public class ServerRemoteAbilityTest { } @Test - public void testDeserialize() throws JsonProcessingException { + void testDeserialize() throws JsonProcessingException { String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}"; ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class); assertTrue(abilities.isSupportRemoteConnection()); @@ -66,10 +66,10 @@ public class ServerRemoteAbilityTest { } @Test - public void testEqualsAndHashCode() { + void testEqualsAndHashCode() { assertEquals(serverAbilities, serverAbilities); assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode()); - assertNotEquals(serverAbilities, null); + assertNotEquals(null, serverAbilities); assertNotEquals(serverAbilities, new ClientAbilities()); ServerRemoteAbility test = new ServerRemoteAbility(); assertEquals(serverAbilities, test); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/BasicRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/BasicRequestTest.java index 336f9af7b..d12af4aef 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/BasicRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/BasicRequestTest.java @@ -19,13 +19,13 @@ package com.alibaba.nacos.api.remote.request; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public abstract class BasicRequestTest { protected ObjectMapper mapper; - @Before + @BeforeEach public void setUp() throws Exception { mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java index d2a7d1192..6356319f7 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java @@ -16,35 +16,38 @@ package com.alibaba.nacos.api.remote.request; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ConnectResetRequestTest extends BasicRequestTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ConnectResetRequestTest extends BasicRequestTest { @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { ConnectResetRequest request = new ConnectResetRequest(); request.setServerIp("127.0.0.1"); request.setServerPort("8888"); request.setRequestId("1"); request.setConnectionId("11111_127.0.0.1_8888"); String json = mapper.writeValueAsString(request); - Assert.assertNotNull(json); - Assert.assertTrue(json.contains("\"serverIp\":\"127.0.0.1\"")); - Assert.assertTrue(json.contains("\"serverPort\":\"8888\"")); - Assert.assertTrue(json.contains("\"module\":\"internal\"")); - Assert.assertTrue(json.contains("\"requestId\":\"1\"")); - Assert.assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\"")); + assertNotNull(json); + assertTrue(json.contains("\"serverIp\":\"127.0.0.1\"")); + assertTrue(json.contains("\"serverPort\":\"8888\"")); + assertTrue(json.contains("\"module\":\"internal\"")); + assertTrue(json.contains("\"requestId\":\"1\"")); + assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\"")); } @Test - public void testDeserialize() throws Exception { + void testDeserialize() throws Exception { String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\"," + "\"module\":\"internal\",\"connectionId\":\"11111_127.0.0.1_8888\"}"; ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class); - Assert.assertNotNull(result); - Assert.assertEquals("127.0.0.1", result.getServerIp()); - Assert.assertEquals("8888", result.getServerPort()); - Assert.assertEquals("11111_127.0.0.1_8888", result.getConnectionId()); + assertNotNull(result); + assertEquals("127.0.0.1", result.getServerIp()); + assertEquals("8888", result.getServerPort()); + assertEquals("11111_127.0.0.1_8888", result.getConnectionId()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java index 03424d50a..81d61dc4b 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java @@ -16,16 +16,19 @@ package com.alibaba.nacos.api.remote.request; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; -public class ConnectionSetupRequestTest extends BasicRequestTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ConnectionSetupRequestTest extends BasicRequestTest { @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { ConnectionSetupRequest request = new ConnectionSetupRequest(); request.setClientVersion("2.2.2"); request.setAbilityTable(new HashMap<>()); @@ -33,27 +36,28 @@ public class ConnectionSetupRequestTest extends BasicRequestTest { request.setLabels(Collections.singletonMap("labelKey", "labelValue")); request.setRequestId("1"); String json = mapper.writeValueAsString(request); - Assert.assertNotNull(json); - Assert.assertTrue(json.contains("\"clientVersion\":\"2.2.2\"")); - Assert.assertTrue(json.contains("\"tenant\":\"testNamespaceId\"")); - Assert.assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}")); - Assert.assertTrue(json.contains("\"abilityTable\":{")); - Assert.assertTrue(json.contains("\"module\":\"internal\"")); - Assert.assertTrue(json.contains("\"requestId\":\"1\"")); + assertNotNull(json); + assertTrue(json.contains("\"clientVersion\":\"2.2.2\"")); + assertTrue(json.contains("\"tenant\":\"testNamespaceId\"")); + assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}")); + assertTrue(json.contains("\"abilityTable\":{")); + assertTrue(json.contains("\"module\":\"internal\"")); + assertTrue(json.contains("\"requestId\":\"1\"")); } @Test - public void testDeserialize() throws Exception { - String json = "{\"headers\":{},\"requestId\":\"1\",\"clientVersion\":\"2.2.2\",\"abilities\":{\"remoteAbility\":" - + "{\"supportRemoteConnection\":false},\"configAbility\":{\"supportRemoteMetrics\":false}," - + "\"namingAbility\":{\"supportDeltaPush\":false,\"supportRemoteMetric\":false}},\"tenant\":\"testNamespaceId\"," - + "\"labels\":{\"labelKey\":\"labelValue\"},\"module\":\"internal\"}"; + void testDeserialize() throws Exception { + String json = + "{\"headers\":{},\"requestId\":\"1\",\"clientVersion\":\"2.2.2\",\"abilities\":{\"remoteAbility\":" + + "{\"supportRemoteConnection\":false},\"configAbility\":{\"supportRemoteMetrics\":false}," + + "\"namingAbility\":{\"supportDeltaPush\":false,\"supportRemoteMetric\":false}},\"tenant\":\"testNamespaceId\"," + + "\"labels\":{\"labelKey\":\"labelValue\"},\"module\":\"internal\"}"; ConnectionSetupRequest result = mapper.readValue(json, ConnectionSetupRequest.class); - Assert.assertNotNull(result); - Assert.assertEquals("2.2.2", result.getClientVersion()); - Assert.assertEquals("testNamespaceId", result.getTenant()); - Assert.assertEquals(1, result.getLabels().size()); - Assert.assertEquals("labelValue", result.getLabels().get("labelKey")); - Assert.assertEquals("1", result.getRequestId()); + assertNotNull(result); + assertEquals("2.2.2", result.getClientVersion()); + assertEquals("testNamespaceId", result.getTenant()); + assertEquals(1, result.getLabels().size()); + assertEquals("labelValue", result.getLabels().get("labelKey")); + assertEquals("1", result.getRequestId()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/EmptyContentRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/EmptyContentRequestTest.java index 61aebc555..5fe22b36e 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/EmptyContentRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/EmptyContentRequestTest.java @@ -19,19 +19,19 @@ package com.alibaba.nacos.api.remote.request; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class EmptyContentRequestTest extends BasicRequestTest { +class EmptyContentRequestTest extends BasicRequestTest { private static final String COMMON_JSON = "{\"headers\":{\"clientIp\":\"1.1.1.1\"},\"requestId\":\"1\",\"module\":\"internal\"}"; private static final String TO_STRING = "%s{headers={clientIp=1.1.1.1}, requestId='1'}"; - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); @@ -39,26 +39,22 @@ public class EmptyContentRequestTest extends BasicRequestTest { } @Test - public void testClientDetectionRequest() - throws JsonProcessingException, InstantiationException, IllegalAccessException { + void testClientDetectionRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException { doTest(ClientDetectionRequest.class); } @Test - public void testHealthCheckRequest() - throws JsonProcessingException, InstantiationException, IllegalAccessException { + void testHealthCheckRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException { doTest(HealthCheckRequest.class); } @Test - public void testServerCheckRequest() - throws JsonProcessingException, InstantiationException, IllegalAccessException { + void testServerCheckRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException { doTest(ServerCheckRequest.class); } @Test - public void testServerLoaderInfoRequest() - throws JsonProcessingException, InstantiationException, IllegalAccessException { + void testServerLoaderInfoRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException { doTest(ServerLoaderInfoRequest.class); } diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/PushAckRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/PushAckRequestTest.java index 2d13f0015..02f0fe4b6 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/PushAckRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/PushAckRequestTest.java @@ -17,31 +17,35 @@ package com.alibaba.nacos.api.remote.request; import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class PushAckRequestTest extends BasicRequestTest { +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; + +class PushAckRequestTest extends BasicRequestTest { @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { PushAckRequest request = PushAckRequest.build("1", false); request.setException(new NacosRuntimeException(500, "test")); String json = mapper.writeValueAsString(request); - Assert.assertNotNull(json); - Assert.assertTrue(json.contains("\"success\":false")); - Assert.assertTrue(json.contains("\"exception\":{")); - Assert.assertTrue(json.contains("\"module\":\"internal\"")); - Assert.assertTrue(json.contains("\"requestId\":\"1\"")); + assertNotNull(json); + assertTrue(json.contains("\"success\":false")); + assertTrue(json.contains("\"exception\":{")); + assertTrue(json.contains("\"module\":\"internal\"")); + assertTrue(json.contains("\"requestId\":\"1\"")); } @Test - public void testDeserialize() throws Exception { + void testDeserialize() throws Exception { String json = "{\"headers\":{},\"requestId\":\"1\",\"success\":false," + "\"exception\":{\"stackTrace\":[],\"errCode\":500,\"message\":\"errCode: 500, errMsg: test \"," + "\"localizedMessage\":\"errCode: 500, errMsg: test \",\"suppressed\":[]},\"module\":\"internal\"}"; PushAckRequest result = mapper.readValue(json, PushAckRequest.class); - Assert.assertNotNull(result); - Assert.assertFalse(result.isSuccess()); - Assert.assertEquals("1", result.getRequestId()); + assertNotNull(result); + assertFalse(result.isSuccess()); + assertEquals("1", result.getRequestId()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java index 13f60b5b3..866e942d8 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java @@ -18,22 +18,22 @@ package com.alibaba.nacos.api.remote.request; import com.alibaba.nacos.api.ability.constant.AbilityKey; import com.alibaba.nacos.api.ability.constant.AbilityStatus; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -public class RequestMetaTest { +class RequestMetaTest { private RequestMeta requestMeta; - @Before - public void setUp() { + @BeforeEach + void setUp() { requestMeta = new RequestMeta(); requestMeta.setClientIp("127.0.0.1"); requestMeta.setClientVersion("1.0.0"); @@ -44,22 +44,22 @@ public class RequestMetaTest { } @Test - public void testGetClientIp() { + void testGetClientIp() { assertEquals("127.0.0.1", requestMeta.getClientIp()); } @Test - public void testGetClientVersion() { + void testGetClientVersion() { assertEquals("1.0.0", requestMeta.getClientVersion()); } @Test - public void testGetConnectionId() { + void testGetConnectionId() { assertEquals("test-connection-id", requestMeta.getConnectionId()); } @Test - public void testGetLabels() { + void testGetLabels() { Map labels = requestMeta.getLabels(); assertNotNull(labels); assertEquals(1, labels.size()); @@ -67,20 +67,20 @@ public class RequestMetaTest { } @Test - public void testToString() { + void testToString() { String expected = "RequestMeta{connectionId='test-connection-id', clientIp='127.0.0.1', clientVersion='1.0.0', labels={env=dev}}"; assertEquals(expected, requestMeta.toString()); } @Test - public void testGetConnectionAbilityForNonExist() { + void testGetConnectionAbilityForNonExist() { assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1)); requestMeta.setAbilityTable(Collections.emptyMap()); assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1)); } @Test - public void testGetConnectionAbilityForExist() { + void testGetConnectionAbilityForExist() { requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.FALSE)); assertEquals(AbilityStatus.NOT_SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1)); requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE)); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestTest.java index f52c3f3a0..24ee28b0a 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestTest.java @@ -16,23 +16,23 @@ package com.alibaba.nacos.api.remote.request; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; -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; -public class RequestTest { +class RequestTest { - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { } @Test - public void testHeader() { + void testHeader() { MockRequest request = new MockRequest(); assertTrue(request.getHeaders().isEmpty()); assertNull(request.getHeader("clientIp")); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/ServerReloadRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ServerReloadRequestTest.java index 8066c2eb0..34c23e91b 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/ServerReloadRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/ServerReloadRequestTest.java @@ -16,35 +16,38 @@ package com.alibaba.nacos.api.remote.request; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ServerReloadRequestTest extends BasicRequestTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ServerReloadRequestTest extends BasicRequestTest { @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { ServerReloadRequest request = new ServerReloadRequest(); request.setReloadCount(10); request.setReloadServer("1.1.1.1"); request.setRequestId("1"); String json = mapper.writeValueAsString(request); System.out.println(json); - Assert.assertNotNull(json); - Assert.assertTrue(json.contains("\"reloadCount\":10")); - Assert.assertTrue(json.contains("\"reloadServer\":\"1.1.1.1\"")); - Assert.assertTrue(json.contains("\"module\":\"internal\"")); - Assert.assertTrue(json.contains("\"requestId\":\"1\"")); + assertNotNull(json); + assertTrue(json.contains("\"reloadCount\":10")); + assertTrue(json.contains("\"reloadServer\":\"1.1.1.1\"")); + assertTrue(json.contains("\"module\":\"internal\"")); + assertTrue(json.contains("\"requestId\":\"1\"")); } @Test - public void testDeserialize() throws Exception { + void testDeserialize() throws Exception { String json = "{\"headers\":{},\"requestId\":\"1\",\"reloadCount\":10,\"reloadServer\":\"1.1.1.1\"," + "\"module\":\"internal\"}"; ServerReloadRequest result = mapper.readValue(json, ServerReloadRequest.class); - Assert.assertNotNull(result); - Assert.assertEquals(10, result.getReloadCount()); - Assert.assertEquals("1.1.1.1", result.getReloadServer()); - Assert.assertEquals("1", result.getRequestId()); - Assert.assertEquals("internal", result.getModule()); + assertNotNull(result); + assertEquals(10, result.getReloadCount()); + assertEquals("1.1.1.1", result.getReloadServer()); + assertEquals("1", result.getRequestId()); + assertEquals("internal", result.getModule()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java index b0697db5e..c98108685 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java @@ -17,34 +17,37 @@ package com.alibaba.nacos.api.remote.request; import com.alibaba.nacos.api.ability.constant.AbilityKey; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; -public class SetupAckRequestTest extends BasicRequestTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SetupAckRequestTest extends BasicRequestTest { @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { SetupAckRequest request = new SetupAckRequest( Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE)); request.setRequestId("1"); String json = mapper.writeValueAsString(request); System.out.println(json); - Assert.assertNotNull(json); - Assert.assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}")); - Assert.assertTrue(json.contains("\"module\":\"internal\"")); - Assert.assertTrue(json.contains("\"requestId\":\"1\"")); + assertNotNull(json); + assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}")); + assertTrue(json.contains("\"module\":\"internal\"")); + assertTrue(json.contains("\"requestId\":\"1\"")); } @Test - public void testDeserialize() throws Exception { + void testDeserialize() throws Exception { String json = "{\"headers\":{},\"requestId\":\"1\",\"abilityTable\":{\"test_1\":true}," + "\"module\":\"internal\"}"; SetupAckRequest result = mapper.readValue(json, SetupAckRequest.class); - Assert.assertNotNull(result); - Assert.assertTrue(result.getAbilityTable().get("test_1")); - Assert.assertEquals("1", result.getRequestId()); - Assert.assertEquals("internal", result.getModule()); + assertNotNull(result); + assertTrue(result.getAbilityTable().get("test_1")); + assertEquals("1", result.getRequestId()); + assertEquals("internal", result.getModule()); } } \ No newline at end of file diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java index 28b23af08..19484416b 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java @@ -20,15 +20,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class EmptyContentResponseTest { +class EmptyContentResponseTest { private static final String COMMON_JSON = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"1\",\"success\":true}"; @@ -36,14 +36,14 @@ public class EmptyContentResponseTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSetErrorInfo() { + void testSetErrorInfo() { Response response = new Response() { }; response.setErrorInfo(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getDesc()); @@ -53,7 +53,7 @@ public class EmptyContentResponseTest { } @Test - public void testClientDetectionResponse() throws JsonProcessingException { + void testClientDetectionResponse() throws JsonProcessingException { ClientDetectionResponse response = new ClientDetectionResponse(); response.setRequestId("1"); String actual = mapper.writeValueAsString(response); @@ -63,7 +63,7 @@ public class EmptyContentResponseTest { } @Test - public void testConnectResetResponse() throws JsonProcessingException { + void testConnectResetResponse() throws JsonProcessingException { ConnectResetResponse response = new ConnectResetResponse(); response.setRequestId("1"); String actual = mapper.writeValueAsString(response); @@ -73,7 +73,7 @@ public class EmptyContentResponseTest { } @Test - public void testHealthCheckResponse() throws JsonProcessingException { + void testHealthCheckResponse() throws JsonProcessingException { HealthCheckResponse response = new HealthCheckResponse(); response.setRequestId("1"); String actual = mapper.writeValueAsString(response); @@ -83,7 +83,7 @@ public class EmptyContentResponseTest { } @Test - public void testServerReloadResponse() throws JsonProcessingException { + void testServerReloadResponse() throws JsonProcessingException { ServerReloadResponse response = new ServerReloadResponse(); response.setRequestId("1"); String actual = mapper.writeValueAsString(response); @@ -93,7 +93,7 @@ public class EmptyContentResponseTest { } @Test - public void testSetupAckResponse() throws JsonProcessingException { + void testSetupAckResponse() throws JsonProcessingException { SetupAckResponse response = new SetupAckResponse(); response.setRequestId("1"); String actual = mapper.writeValueAsString(response); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/ErrorResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/ErrorResponseTest.java index 33392a4c4..4bf169a06 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/response/ErrorResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/ErrorResponseTest.java @@ -18,59 +18,60 @@ package com.alibaba.nacos.api.remote.response; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ErrorResponseTest { +import static org.junit.jupiter.api.Assertions.assertEquals; + +class ErrorResponseTest { @Test - public void testBuildWithErrorCode() { + void testBuildWithErrorCode() { int errorCode = 500; String msg = "err msg"; Response response = ErrorResponse.build(errorCode, msg); - Assert.assertEquals(errorCode, response.getErrorCode()); - Assert.assertEquals(errorCode, response.getResultCode()); - Assert.assertEquals(msg, response.getMessage()); + assertEquals(errorCode, response.getErrorCode()); + assertEquals(errorCode, response.getResultCode()); + assertEquals(msg, response.getMessage()); } @Test - public void testBuildWithThrowable() { + void testBuildWithThrowable() { String errMsg = "exception msg"; RuntimeException runtimeException = new RuntimeException(errMsg); Response response = ErrorResponse.build(runtimeException); - Assert.assertEquals(ResponseCode.FAIL.getCode(), response.getErrorCode()); - Assert.assertEquals(ResponseCode.FAIL.getCode(), response.getResultCode()); - Assert.assertEquals(errMsg, response.getMessage()); + assertEquals(ResponseCode.FAIL.getCode(), response.getErrorCode()); + assertEquals(ResponseCode.FAIL.getCode(), response.getResultCode()); + assertEquals(errMsg, response.getMessage()); } @Test - public void testBuildWithNacosException() { + void testBuildWithNacosException() { int errCode = 500; String errMsg = "nacos exception msg"; NacosException nacosException = new NacosException(errCode, errMsg); Response response = ErrorResponse.build(nacosException); - Assert.assertEquals(errCode, response.getErrorCode()); - Assert.assertEquals(errCode, response.getResultCode()); - Assert.assertEquals(errMsg, response.getMessage()); + assertEquals(errCode, response.getErrorCode()); + assertEquals(errCode, response.getResultCode()); + assertEquals(errMsg, response.getMessage()); } @Test - public void testBuildWithNacosRuntimeException() { + void testBuildWithNacosRuntimeException() { int errCode = 500; String errMsg = "nacos runtime exception msg"; NacosRuntimeException nacosRuntimeException = new NacosRuntimeException(errCode, errMsg); Response response = ErrorResponse.build(nacosRuntimeException); - Assert.assertEquals(errCode, response.getErrorCode()); - Assert.assertEquals(errCode, response.getResultCode()); - Assert.assertEquals("errCode: " + errCode + ", errMsg: " + errMsg + " ", response.getMessage()); + assertEquals(errCode, response.getErrorCode()); + assertEquals(errCode, response.getResultCode()); + assertEquals("errCode: " + errCode + ", errMsg: " + errMsg + " ", response.getMessage()); } - + } diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java index 9a7603435..4497514ed 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java @@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ServerCheckResponseTest { +class ServerCheckResponseTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306", false); String actual = mapper.writeValueAsString(response); assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\"")); @@ -45,7 +45,7 @@ public class ServerCheckResponseTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true," + "\"supportAbilityNegotiation\":true}"; ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class); diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerLoaderInfoResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerLoaderInfoResponseTest.java index 7f5041e73..20c869060 100644 --- a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerLoaderInfoResponseTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerLoaderInfoResponseTest.java @@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ServerLoaderInfoResponseTest { +class ServerLoaderInfoResponseTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { ServerLoaderInfoResponse response = new ServerLoaderInfoResponse(); response.putMetricsValue("test", "testValue"); String actual = mapper.writeValueAsString(response); @@ -46,7 +46,7 @@ public class ServerLoaderInfoResponseTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"resultCode\":200,\"errorCode\":0,\"loaderMetrics\":{\"test\":\"testValue\"},\"success\":true}"; ServerLoaderInfoResponse response = mapper.readValue(json, ServerLoaderInfoResponse.class); assertEquals(1, response.getLoaderMetrics().size()); diff --git a/api/src/test/java/com/alibaba/nacos/api/selector/AbstractCmdbSelectorTest.java b/api/src/test/java/com/alibaba/nacos/api/selector/AbstractCmdbSelectorTest.java index 267e5882b..af9323e97 100644 --- a/api/src/test/java/com/alibaba/nacos/api/selector/AbstractCmdbSelectorTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/selector/AbstractCmdbSelectorTest.java @@ -20,29 +20,29 @@ import com.alibaba.nacos.api.cmdb.pojo.Entity; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.selector.context.CmdbContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import static com.alibaba.nacos.api.common.Constants.Naming.CMDB_CONTEXT_TYPE; -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; -public class AbstractCmdbSelectorTest { +class AbstractCmdbSelectorTest { private AtomicInteger counter; - @Before - public void setUp() { + @BeforeEach + void setUp() { counter = new AtomicInteger(); } @Test - public void testSetExpression() { + void testSetExpression() { MockCmdbSelector cmdbSelector = new MockCmdbSelector(); assertNull(cmdbSelector.getExpression()); cmdbSelector.setExpression("test"); @@ -50,7 +50,7 @@ public class AbstractCmdbSelectorTest { } @Test - public void testParse() throws NacosException { + void testParse() throws NacosException { MockCmdbSelector cmdbSelector = new MockCmdbSelector(); cmdbSelector.parse("test"); assertEquals("test", cmdbSelector.getExpression()); @@ -58,7 +58,7 @@ public class AbstractCmdbSelectorTest { } @Test - public void testSelect() { + void testSelect() { CmdbContext context = new CmdbContext<>(); CmdbContext.CmdbInstance provider = new CmdbContext.CmdbInstance<>(); provider.setInstance(new Instance()); @@ -78,12 +78,12 @@ public class AbstractCmdbSelectorTest { } @Test - public void testGetContextType() { + void testGetContextType() { assertEquals(CMDB_CONTEXT_TYPE, new MockCmdbSelector().getContextType()); } @Test - public void testGetType() { + void testGetType() { assertEquals("mock", new MockCmdbSelector().getType()); } diff --git a/api/src/test/java/com/alibaba/nacos/api/selector/ExpressionSelectorTest.java b/api/src/test/java/com/alibaba/nacos/api/selector/ExpressionSelectorTest.java index 20e813168..f403a227e 100644 --- a/api/src/test/java/com/alibaba/nacos/api/selector/ExpressionSelectorTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/selector/ExpressionSelectorTest.java @@ -21,25 +21,25 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.NamedType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class ExpressionSelectorTest { +class ExpressionSelectorTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerSubtypes(new NamedType(ExpressionSelector.class, SelectorType.label.name())); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { ExpressionSelector selector = new ExpressionSelector(); selector.setExpression("test expression"); String actual = mapper.writeValueAsString(selector); @@ -48,7 +48,7 @@ public class ExpressionSelectorTest { } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"type\":\"label\",\"expression\":\"test expression\"}"; AbstractSelector actual = mapper.readValue(json, AbstractSelector.class); assertEquals(SelectorType.label.name(), actual.getType()); diff --git a/api/src/test/java/com/alibaba/nacos/api/selector/NoneSelectorTest.java b/api/src/test/java/com/alibaba/nacos/api/selector/NoneSelectorTest.java index 8f2f87214..1c6d679b5 100644 --- a/api/src/test/java/com/alibaba/nacos/api/selector/NoneSelectorTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/selector/NoneSelectorTest.java @@ -21,32 +21,32 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.NamedType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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; -public class NoneSelectorTest { +class NoneSelectorTest { ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerSubtypes(new NamedType(NoneSelector.class, SelectorType.none.name())); } @Test - public void testSerialization() throws JsonProcessingException { + void testSerialization() throws JsonProcessingException { NoneSelector selector = new NoneSelector(); String actual = mapper.writeValueAsString(selector); assertTrue(actual.contains("\"type\":\"" + SelectorType.none.name() + "\"")); } @Test - public void testDeserialization() throws JsonProcessingException { + void testDeserialization() throws JsonProcessingException { String json = "{\"type\":\"none\"}"; AbstractSelector actual = mapper.readValue(json, AbstractSelector.class); assertEquals(SelectorType.none.name(), actual.getType()); diff --git a/api/src/test/java/com/alibaba/nacos/api/selector/context/CmdbContextTest.java b/api/src/test/java/com/alibaba/nacos/api/selector/context/CmdbContextTest.java index 90fe6c1fe..f3f3bbfa0 100644 --- a/api/src/test/java/com/alibaba/nacos/api/selector/context/CmdbContextTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/selector/context/CmdbContextTest.java @@ -17,16 +17,16 @@ package com.alibaba.nacos.api.selector.context; import com.alibaba.nacos.api.naming.pojo.Instance; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class CmdbContextTest { +class CmdbContextTest { @Test - public void testToString() { + void testToString() { CmdbContext cmdbContext = new CmdbContext<>(); cmdbContext.setProviders(Collections.singletonList(new CmdbContext.CmdbInstance<>())); cmdbContext.setConsumer(new CmdbContext.CmdbInstance<>()); diff --git a/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java b/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java index a7a88fce3..0812ce187 100644 --- a/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java @@ -18,26 +18,28 @@ package com.alibaba.nacos.api.utils; import com.alibaba.nacos.api.ability.constant.AbilityKey; import com.alibaba.nacos.api.ability.constant.AbilityMode; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -/**. +/** + * . + * * @author Daydreamer * @description Ability key test * @date 2022/9/8 12:27 **/ -public class AbilityKeyTest { +class AbilityKeyTest { @Test - public void testMapStr() { + void testMapStr() { Map enumMap = new HashMap<>(); Map stringBooleanMap = AbilityKey.mapStr(enumMap); assertEquals(0, stringBooleanMap.size()); @@ -47,27 +49,27 @@ public class AbilityKeyTest { enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, false); stringBooleanMap = AbilityKey.mapStr(enumMap); assertEquals(3, stringBooleanMap.size()); - Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName())); - Assert.assertFalse(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName())); - Assert.assertFalse(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName())); + assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName())); + assertFalse(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName())); + assertFalse(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName())); enumMap.put(AbilityKey.SERVER_TEST_2, true); enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true); stringBooleanMap = AbilityKey.mapStr(enumMap); assertEquals(3, stringBooleanMap.size()); - Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName())); - Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName())); - Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName())); + assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName())); + assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName())); + assertTrue(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName())); } @Test - public void testMapEnumForEmpty() { + void testMapEnumForEmpty() { Map actual = AbilityKey.mapEnum(AbilityMode.SERVER, Collections.emptyMap()); assertTrue(actual.isEmpty()); } @Test - public void testMapEnum() { + void testMapEnum() { Map mapStr = new HashMap<>(); mapStr.put("test-no-existed", true); Map enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr); @@ -77,23 +79,23 @@ public class AbilityKeyTest { mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true); mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true); enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr); - Assert.assertFalse(enumMap.get(AbilityKey.SERVER_TEST_2)); - Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1)); - Assert.assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC)); - + assertFalse(enumMap.get(AbilityKey.SERVER_TEST_2)); + assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1)); + assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC)); + mapStr.clear(); mapStr.put(AbilityKey.SERVER_TEST_2.getName(), true); mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true); mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true); enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr); - Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_2)); - Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1)); - Assert.assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC)); + assertTrue(enumMap.get(AbilityKey.SERVER_TEST_2)); + assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1)); + assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC)); } @Test - public void testGetAllValues() { + void testGetAllValues() { Collection actual = AbilityKey.getAllValues(AbilityMode.SERVER); assertEquals(3, actual.size()); actual = AbilityKey.getAllValues(AbilityMode.SDK_CLIENT); @@ -103,7 +105,7 @@ public class AbilityKeyTest { } @Test - public void testGetAllNames() { + void testGetAllNames() { Collection actual = AbilityKey.getAllNames(AbilityMode.SERVER); assertEquals(3, actual.size()); actual = AbilityKey.getAllNames(AbilityMode.SDK_CLIENT); @@ -113,7 +115,7 @@ public class AbilityKeyTest { } @Test - public void testGetDescription() { + void testGetDescription() { assertEquals("just for junit test", AbilityKey.SERVER_TEST_1.getDescription()); } } diff --git a/api/src/test/java/com/alibaba/nacos/api/utils/NetUtilsTest.java b/api/src/test/java/com/alibaba/nacos/api/utils/NetUtilsTest.java index ed9a0f594..42b571033 100644 --- a/api/src/test/java/com/alibaba/nacos/api/utils/NetUtilsTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/utils/NetUtilsTest.java @@ -16,22 +16,22 @@ package com.alibaba.nacos.api.utils; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetAddress; import java.util.Properties; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class NetUtilsTest { +class NetUtilsTest { - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { Class clazz = Class.forName("com.alibaba.nacos.api.utils.NetUtils"); Field field = clazz.getDeclaredField("localIp"); field.setAccessible(true); @@ -42,7 +42,7 @@ public class NetUtilsTest { } @Test - public void testLocalIpWithSpecifiedIp() { + void testLocalIpWithSpecifiedIp() { System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.8"); assertEquals("10.2.8.8", NetUtils.localIP()); System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.9"); @@ -50,7 +50,7 @@ public class NetUtilsTest { } @Test - public void testLocalIpWithPreferHostname() throws Exception { + void testLocalIpWithPreferHostname() throws Exception { InetAddress inetAddress = invokeGetInetAddress(); String hostname = inetAddress.getHostName(); System.setProperty("com.alibaba.nacos.client.local.preferHostname", "true"); @@ -58,14 +58,14 @@ public class NetUtilsTest { } @Test - public void testLocalIpWithoutPreferHostname() throws Exception { + void testLocalIpWithoutPreferHostname() throws Exception { InetAddress inetAddress = invokeGetInetAddress(); String ip = inetAddress.getHostAddress(); assertEquals(ip, NetUtils.localIP()); } @Test - public void testLocalIpWithException() throws Exception { + void testLocalIpWithException() throws Exception { Field field = System.class.getDeclaredField("props"); field.setAccessible(true); Properties properties = (Properties) field.get(null); diff --git a/api/src/test/java/com/alibaba/nacos/api/utils/StringUtilsTest.java b/api/src/test/java/com/alibaba/nacos/api/utils/StringUtilsTest.java index 48a357224..2775f83c4 100644 --- a/api/src/test/java/com/alibaba/nacos/api/utils/StringUtilsTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/utils/StringUtilsTest.java @@ -16,94 +16,98 @@ package com.alibaba.nacos.api.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class StringUtilsTest { +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; + +class StringUtilsTest { @Test - public void testIsEmpty() { - Assert.assertTrue(StringUtils.isEmpty(null)); - Assert.assertTrue(StringUtils.isEmpty("")); - Assert.assertFalse(StringUtils.isEmpty(" ")); - Assert.assertFalse(StringUtils.isEmpty("bob")); - Assert.assertFalse(StringUtils.isEmpty(" bob ")); + void testIsEmpty() { + assertTrue(StringUtils.isEmpty(null)); + assertTrue(StringUtils.isEmpty("")); + assertFalse(StringUtils.isEmpty(" ")); + assertFalse(StringUtils.isEmpty("bob")); + assertFalse(StringUtils.isEmpty(" bob ")); } @Test - public void testIsBlank() { - Assert.assertTrue(StringUtils.isBlank(null)); - Assert.assertTrue(StringUtils.isBlank("")); - Assert.assertTrue(StringUtils.isBlank(" ")); - Assert.assertFalse(StringUtils.isBlank("bob")); - Assert.assertFalse(StringUtils.isBlank(" bob ")); + void testIsBlank() { + assertTrue(StringUtils.isBlank(null)); + assertTrue(StringUtils.isBlank("")); + assertTrue(StringUtils.isBlank(" ")); + assertFalse(StringUtils.isBlank("bob")); + assertFalse(StringUtils.isBlank(" bob ")); } @Test - public void testTrim() { - Assert.assertNull(StringUtils.trim(null)); - Assert.assertEquals(StringUtils.EMPTY, StringUtils.trim("")); - Assert.assertEquals(StringUtils.EMPTY, StringUtils.trim(" ")); - Assert.assertEquals("abc", StringUtils.trim("abc")); - Assert.assertEquals("abc", StringUtils.trim(" abc ")); + void testTrim() { + assertNull(StringUtils.trim(null)); + assertEquals(StringUtils.EMPTY, StringUtils.trim("")); + assertEquals(StringUtils.EMPTY, StringUtils.trim(" ")); + assertEquals("abc", StringUtils.trim("abc")); + assertEquals("abc", StringUtils.trim(" abc ")); } @Test - public void testEquals() { - Assert.assertTrue(StringUtils.equals(null, null)); - Assert.assertFalse(StringUtils.equals(null, "abc")); - Assert.assertFalse(StringUtils.equals("abc", null)); - Assert.assertTrue(StringUtils.equals("abc", "abc")); - Assert.assertFalse(StringUtils.equals("abc", "ABC")); - Assert.assertTrue(StringUtils.equals(new StringBuilder("abc"), "abc")); - Assert.assertFalse(StringUtils.equals(new StringBuilder("ABC"), "abc")); + void testEquals() { + assertTrue(StringUtils.equals(null, null)); + assertFalse(StringUtils.equals(null, "abc")); + assertFalse(StringUtils.equals("abc", null)); + assertTrue(StringUtils.equals("abc", "abc")); + assertFalse(StringUtils.equals("abc", "ABC")); + assertTrue(StringUtils.equals(new StringBuilder("abc"), "abc")); + assertFalse(StringUtils.equals(new StringBuilder("ABC"), "abc")); } @Test - public void testRegionMatchesEqualsCaseSensitive() { - Assert.assertTrue(StringUtils.regionMatches("abc", false, 0, "xabc", 1, 3)); - - } - - @Test - public void testRegionMatchesEqualsCaseInsensitive() { - Assert.assertTrue(StringUtils.regionMatches("abc", true, 0, "xabc", 1, 3)); - Assert.assertTrue(StringUtils.regionMatches("abc", true, 0, "xAbc", 1, 3)); - } - - @Test - public void testRegionMatchesNotEqualsCaseSensitive() { - Assert.assertFalse(StringUtils.regionMatches("abc", false, 0, "xAbc", 1, 3)); - Assert.assertFalse(StringUtils.regionMatches("abc", false, 0, "xCbc", 1, 3)); + void testRegionMatchesEqualsCaseSensitive() { + assertTrue(StringUtils.regionMatches("abc", false, 0, "xabc", 1, 3)); } @Test - public void testRegionMatchesNotEqualsCaseInsensitive() { - Assert.assertFalse(StringUtils.regionMatches("abc", true, 0, "xCab", 1, 3)); + void testRegionMatchesEqualsCaseInsensitive() { + assertTrue(StringUtils.regionMatches("abc", true, 0, "xabc", 1, 3)); + assertTrue(StringUtils.regionMatches("abc", true, 0, "xAbc", 1, 3)); } @Test - public void testRegionMatchesEqualsCaseSensitiveForNonString() { - Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xabc", 1, 3)); + void testRegionMatchesNotEqualsCaseSensitive() { + assertFalse(StringUtils.regionMatches("abc", false, 0, "xAbc", 1, 3)); + assertFalse(StringUtils.regionMatches("abc", false, 0, "xCbc", 1, 3)); } @Test - public void testRegionMatchesEqualsCaseInsensitiveForNonString() { - Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xabc", 1, 3)); - Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xAbc", 1, 3)); + void testRegionMatchesNotEqualsCaseInsensitive() { + assertFalse(StringUtils.regionMatches("abc", true, 0, "xCab", 1, 3)); } @Test - public void testRegionMatchesNotEqualsCaseSensitiveForNonString() { - Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xAbc", 1, 3)); - Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xCbc", 1, 3)); + void testRegionMatchesEqualsCaseSensitiveForNonString() { + assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xabc", 1, 3)); } @Test - public void testRegionMatchesNotEqualsCaseInsensitiveForNonString() { - Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xCab", 1, 3)); + void testRegionMatchesEqualsCaseInsensitiveForNonString() { + assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xabc", 1, 3)); + assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xAbc", 1, 3)); + } + + @Test + void testRegionMatchesNotEqualsCaseSensitiveForNonString() { + assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xAbc", 1, 3)); + assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xCbc", 1, 3)); + + } + + @Test + void testRegionMatchesNotEqualsCaseInsensitiveForNonString() { + assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xCab", 1, 3)); } }