Skip to content

Commit

Permalink
[issue #12081] module api upgrade junit4 to junit5 (#12082)
Browse files Browse the repository at this point in the history
* refact(api): remove junit4 to junit5

* format with code style
  • Loading branch information
shalk committed May 20, 2024
1 parent 9363a08 commit 366c88e
Show file tree
Hide file tree
Showing 96 changed files with 1,113 additions and 1,069 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@
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\":{"));
Expand All @@ -47,7 +47,7 @@ public void testSerialize() throws JsonProcessingException {
}

@Test
public void testDeserialize() throws JsonProcessingException {
void testDeserialize() throws JsonProcessingException {
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
+ "\"supportRemoteMetric\":false}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@
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\":{"));
Expand All @@ -57,7 +57,7 @@ public void testSerialize() throws JsonProcessingException {
}

@Test
public void testDeserialize() throws JsonProcessingException {
void testDeserialize() throws JsonProcessingException {
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
+ "\"supportRemoteMetric\":false}}";
Expand All @@ -68,10 +68,10 @@ public void testDeserialize() throws JsonProcessingException {
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,23 +27,24 @@
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", "");

Expand Down Expand Up @@ -75,11 +75,11 @@ private void testResolvePlaceholder(String placeholder, String propertyName, Str
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() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
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");
Expand All @@ -50,7 +50,7 @@ public void testSerialization() throws JsonProcessingException {
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
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());
Expand All @@ -51,7 +51,7 @@ public void testSerialization() throws JsonProcessingException {
}

@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());
Expand Down
18 changes: 9 additions & 9 deletions api/src/test/java/com/alibaba/nacos/api/cmdb/pojo/LabelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
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");
Expand All @@ -52,7 +52,7 @@ public void testSerialization() throws JsonProcessingException {
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ConfigChangeItem> mockData = new HashMap<>();
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
Expand Down

0 comments on commit 366c88e

Please sign in to comment.