fix:use 1.6.1 version of polaris-java and fix some bug. (#222)

pull/284/head
Haotian Zhang 3 years ago committed by GitHub
parent 3b0eea0033
commit 350b5d4ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,5 @@
# Change Log # Change Log
--- ---
- [fix:use 1.6.1 version of polaris-java and fix some bug.](https://github.com/Tencent/spring-cloud-tencent/pull/222)

@ -40,8 +40,8 @@ public class ApplicationContextAwareUtils implements ApplicationContextAware {
return applicationContext; return applicationContext;
} }
public void setApplicationContext(ApplicationContext applicationContext) @Override
throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ApplicationContextAwareUtils.applicationContext = applicationContext; ApplicationContextAwareUtils.applicationContext = applicationContext;
} }

@ -21,30 +21,55 @@ package com.tencent.cloud.common.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/** /**
* test for {@link JacksonUtils} * Test for {@link JacksonUtils}.
*@author lepdou 2022-05-27 *
* @author lepdou, Haotian Zhang
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class JacksonUtilsTest { public class JacksonUtilsTest {
@Test @Test
public void test() { public void testSerialize2Json() {
Map<String, String> sourceMap = new HashMap<>(); Map<String, String> sourceMap = new HashMap<>();
sourceMap.put("k1", "v1"); sourceMap.put("k1", "v1");
sourceMap.put("k2", "v2"); sourceMap.put("k2", "v2");
sourceMap.put("k3", "v3"); sourceMap.put("k3", "v3");
Map<String, String> map = JacksonUtils.deserialize2Map(JacksonUtils.serialize2Json(sourceMap)); String jsonStr = JacksonUtils.serialize2Json(sourceMap);
assertThat(jsonStr).isEqualTo("{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}");
}
@Test
public void testDeserialize2Map() {
String jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}";
Map<String, String> map = JacksonUtils.deserialize2Map(jsonStr);
assertThat(map.size()).isEqualTo(3);
assertThat(map.get("k1")).isEqualTo("v1");
assertThat(map.get("k2")).isEqualTo("v2");
assertThat(map.get("k3")).isEqualTo("v3");
assertThat(JacksonUtils.deserialize2Map("")).isNotNull();
assertThat(JacksonUtils.deserialize2Map("")).isEmpty();
Assert.assertEquals(sourceMap.size(), map.size()); jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"";
Assert.assertEquals(sourceMap.get("k1"), map.get("k1")); try {
Assert.assertEquals(sourceMap.get("k2"), map.get("k2")); JacksonUtils.deserialize2Map(jsonStr);
Assert.assertEquals(sourceMap.get("k3"), map.get("k3")); fail("RuntimeException should be thrown.");
}
catch (RuntimeException exception) {
assertThat(exception.getMessage()).isEqualTo("Json to map failed.");
}
catch (Throwable throwable) {
fail("RuntimeException should be thrown.");
}
} }
} }

Loading…
Cancel
Save