潘志宝
5 天以前 bab43330bf6f48bdb7bfb258611f51bb05ef56fe
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.admin.core.util;
H 2
3 import org.junit.jupiter.api.Test;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 import static com.xxl.job.admin.core.util.JacksonUtil.writeValueAsString;
9 import static org.junit.jupiter.api.Assertions.assertEquals;
10
11 public class JacksonUtilTest {
12
13     @Test
14     public void shouldWriteValueAsString() {
15         //given
16         Map<String, String> map = new HashMap<>();
17         map.put("aaa", "111");
18         map.put("bbb", "222");
19
20         //when
21         String json = writeValueAsString(map);
22
23         //then
24         assertEquals(json, "{\"aaa\":\"111\",\"bbb\":\"222\"}");
25     }
26
27     @Test
28     public void shouldReadValueAsObject() {
29         //given
30         String jsonString = "{\"aaa\":\"111\",\"bbb\":\"222\"}";
31
32         //when
33         Map result = JacksonUtil.readValue(jsonString, Map.class);
34
35         //then
36         assertEquals(result.get("aaa"), "111");
37         assertEquals(result.get("bbb"),"222");
38
39     }
40 }