86183
2022-09-09 0d999e33085c0a25c5525242748f6aa62a401159
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.xxl.job.admin.core.util;
 
import org.hamcrest.core.Is;
import org.junit.Test;
 
import java.util.HashMap;
import java.util.Map;
 
import static com.xxl.job.admin.core.util.JacksonUtil.writeValueAsString;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
 
public class JacksonUtilTest {
 
    @Test
    public void shouldWriteValueAsString() {
        //given
        Map<String, String> map = new HashMap<>();
        map.put("aaa", "111");
        map.put("bbb", "222");
 
        //when
        String json = writeValueAsString(map);
 
        //then
        assertThat(json, is("{\"aaa\":\"111\",\"bbb\":\"222\"}"));
    }
 
    @Test
    public void shouldReadValueAsObject() {
        //given
        String jsonString = "{\"aaa\":\"111\",\"bbb\":\"222\"}";
 
        //when
        Map result = JacksonUtil.readValue(jsonString, Map.class);
 
        //then
        assertThat(result.get("aaa"), Is.<Object>is("111"));
        assertThat(result.get("bbb"), Is.<Object>is("222"));
 
    }
}