Spring - MultiValueMap

即一个键对应多个值,Spring的内部实现是LinkedMultiValueMap。

public class LinkedMultiValueMapTests {

    private LinkedMultiValueMap map;

    @Before
    public void setUp() {
        map = new LinkedMultiValueMap();
    }

    @Test
    public void add() {
        map.add("key", "value1");
        map.add("key", "value2");
        assertEquals(1, map.size());
        List expected = new ArrayList(2);
        expected.add("value1");
        expected.add("value2");
        assertEquals(expected, map.get("key"));
    }

    @Test
    public void getFirst() {
        List values = new ArrayList(2);
        values.add("value1");
        values.add("value2");
        map.put("key", values);
        assertEquals("value1", map.getFirst("key"));
        assertNull(map.getFirst("other"));
    }

    @Test
    public void set() {
        map.set("key", "value1");
        map.set("key", "value2");
        assertEquals(1, map.size());
        assertEquals(Collections.singletonList("value2"), map.get("key"));
    }

    @Test
    public void equals() {
        map.set("key1", "value1");
        assertEquals(map, map);
        MultiValueMap o1 = new LinkedMultiValueMap();
        o1.set("key1", "value1");
        assertEquals(map, o1);
        assertEquals(o1, map);
        Map> o2 = new HashMap>();
        o2.put("key1", Collections.singletonList("value1"));
        assertEquals(map, o2);
        assertEquals(o2, map);
    }
}

 

最后欢迎大家访问我的个人网站:1024s​​​​​​​

你可能感兴趣的:(秒扒Spring)