|
|
@ -26,12 +26,12 @@ 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.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.fail;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Test for {@link JacksonUtils}.
|
|
|
|
* Test for {@link JacksonUtils}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author lepdou, Haotian Zhang
|
|
|
|
* @author lepdou, Haotian Zhang, cheese8
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
|
public class JacksonUtilsTest {
|
|
|
|
public class JacksonUtilsTest {
|
|
|
@ -42,10 +42,7 @@ public class JacksonUtilsTest {
|
|
|
|
sourceMap.put("k1", "v1");
|
|
|
|
sourceMap.put("k1", "v1");
|
|
|
|
sourceMap.put("k2", "v2");
|
|
|
|
sourceMap.put("k2", "v2");
|
|
|
|
sourceMap.put("k3", "v3");
|
|
|
|
sourceMap.put("k3", "v3");
|
|
|
|
|
|
|
|
assertThat(JacksonUtils.serialize2Json(sourceMap)).isEqualTo("{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}");
|
|
|
|
String jsonStr = JacksonUtils.serialize2Json(sourceMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(jsonStr).isEqualTo("{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -56,20 +53,19 @@ public class JacksonUtilsTest {
|
|
|
|
assertThat(map.get("k1")).isEqualTo("v1");
|
|
|
|
assertThat(map.get("k1")).isEqualTo("v1");
|
|
|
|
assertThat(map.get("k2")).isEqualTo("v2");
|
|
|
|
assertThat(map.get("k2")).isEqualTo("v2");
|
|
|
|
assertThat(map.get("k3")).isEqualTo("v3");
|
|
|
|
assertThat(map.get("k3")).isEqualTo("v3");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(JacksonUtils.deserialize2Map("")).isNotNull();
|
|
|
|
@Test
|
|
|
|
assertThat(JacksonUtils.deserialize2Map("")).isEmpty();
|
|
|
|
public void testDeserializeBlankIntoEmptyMap() {
|
|
|
|
|
|
|
|
Map<String, String> map = JacksonUtils.deserialize2Map("");
|
|
|
|
|
|
|
|
assertThat(map).isNotNull();
|
|
|
|
|
|
|
|
assertThat(map).isEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"";
|
|
|
|
@Test
|
|
|
|
try {
|
|
|
|
public void testDeserializeThrowsRuntimeException() {
|
|
|
|
JacksonUtils.deserialize2Map(jsonStr);
|
|
|
|
String jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"";
|
|
|
|
fail("RuntimeException should be thrown.");
|
|
|
|
assertThatThrownBy(() -> JacksonUtils.deserialize2Map(jsonStr))
|
|
|
|
}
|
|
|
|
.isExactlyInstanceOf(RuntimeException.class).hasMessage("Json to map failed.");
|
|
|
|
catch (RuntimeException exception) {
|
|
|
|
|
|
|
|
assertThat(exception.getMessage()).isEqualTo("Json to map failed.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
fail("RuntimeException should be thrown.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|