MCPcopy Create free account
hub / github.com/LFYSec/MScan / AbstractMapTest

Class AbstractMapTest

src/test/java/pascal/taie/util/collection/AbstractMapTest.java:36–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34import static org.junit.jupiter.api.Assertions.assertTrue;
35
36@SuppressWarnings("ALL")
37abstract class AbstractMapTest {
38
39 protected abstract <K, V> Map<K, V> newMap();
40
41 @Test
42 void testPut() {
43 Map<Integer, String> map = newMap();
44 map.put(1, "a");
45 map.put(1, "b");
46 map.put(2, "c");
47 map.put(3, "d");
48 assertEquals(3, map.size());
49 assertEquals("b", map.get(1));
50 }
51
52 @Test
53 void testPutNullKey() {
54 assertThrows(NullPointerException.class, () -> {
55 Map<String, Object> map = newMap();
56 map.put("x", new Object());
57 map.put(null, new Object());
58 });
59 }
60
61 @Test
62 void testKeySet() {
63 Map<Integer, String> map = newMap();
64 Set<Integer> keySet = map.keySet();
65 assertEquals(0, keySet.size());
66 map.put(1, "x");
67 map.put(2, "y");
68 assertEquals(2, keySet.size());
69 keySet.remove(1);
70 assertEquals(1, map.size());
71 }
72
73 @Test
74 void testKeySet20() {
75 testKeySetN(newMap(), 20);
76 }
77
78 void testKeySetN(Map<Integer, String> map, int n) {
79 map.clear();
80 Set<Integer> keySet = map.keySet();
81 for (int i = 0; i < n; ++i) {
82 map.put(i, "");
83 }
84 assertEquals(n, keySet.size());
85 }
86
87 @Test
88 void testKeySetIterator() {
89 Map<Integer, String> map = newMap();
90 map.put(1, "x");
91 map.put(2, "y");
92 map.put(3, "z");
93 assertEquals(3, map.size());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected