1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21
22 import org.junit.Test;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 public class CommonMultiMapTest extends Ini4jCase
28 {
29 private static final String KEY = "key";
30 private static final String VALUE = "value";
31 private static final String COMMENT = "comment";
32
33 @Test public void testClearAndRemove() throws Exception
34 {
35 CommonMultiMap<String, String> map = new CommonMultiMap<String, String>();
36
37 assertNull(map.removeComment(KEY));
38
39
40 map.put(KEY, VALUE);
41 map.clear();
42 assertTrue(map.isEmpty());
43
44
45 map.put(KEY, VALUE);
46 map.remove(KEY);
47 assertNull(map.getComment(KEY));
48
49
50 map.put(KEY, VALUE);
51 map.remove(KEY, 0);
52 assertNull(map.getComment(KEY));
53
54
55 map.add(KEY, VALUE);
56 map.add(KEY, VALUE);
57 map.putComment(KEY, COMMENT);
58 map.remove(KEY, 0);
59 assertEquals(COMMENT, map.getComment(KEY));
60
61
62 map.put(KEY, VALUE);
63 map.putComment(KEY, COMMENT);
64 assertEquals(COMMENT, map.getComment(KEY));
65 map.clear();
66 assertNull(map.getComment(KEY));
67
68
69 map.put(KEY, VALUE);
70 map.putComment(KEY, COMMENT);
71 map.remove(KEY);
72 assertNull(map.getComment(KEY));
73
74
75 map.put(KEY, VALUE);
76 map.putComment(KEY, COMMENT);
77 assertEquals(COMMENT, map.removeComment(KEY));
78 assertNull(map.getComment(KEY));
79
80
81 map.put(KEY, VALUE);
82 map.putComment(KEY, COMMENT);
83 map.remove(KEY, 0);
84 assertNull(map.getComment(KEY));
85 }
86
87 @Test public void testPutAll() throws Exception
88 {
89 CommonMultiMap<String, String> map = new CommonMultiMap<String, String>();
90 CommonMultiMap<String, String> copy = new CommonMultiMap<String, String>();
91
92 map.put(KEY, VALUE);
93 map.putComment(KEY, COMMENT);
94 copy.putAll(map);
95 assertEquals(COMMENT, copy.getComment(KEY));
96 Map<String, String> simple = new HashMap<String, String>();
97
98 simple.put(KEY, VALUE);
99 copy.clear();
100 assertTrue(copy.isEmpty());
101 copy.putAll(simple);
102 assertNull(copy.getComment(KEY));
103 assertEquals(VALUE, copy.get(KEY));
104
105
106 map = new CommonMultiMap<String, String>();
107 map.put(KEY, VALUE);
108 copy.clear();
109 copy.putAll(map);
110 assertEquals(VALUE, copy.get(KEY));
111 assertNull(copy.getComment(KEY));
112 }
113 }