1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.map;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertSame;
21
22 import org.junit.jupiter.api.Test;
23
24
25
26
27 public class HashedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
28
29 public HashedMapTest() {
30 super(HashedMapTest.class.getSimpleName());
31 }
32
33 @Override
34 public String getCompatibilityVersion() {
35 return "4";
36 }
37
38 @Override
39 public HashedMap<K, V> makeObject() {
40 return new HashedMap<>();
41 }
42
43 @Test
44 @SuppressWarnings("unchecked")
45 public void testClone() {
46 final HashedMap<K, V> map = new HashedMap<>(10);
47 map.put((K) "1", (V) "1");
48 final HashedMap<K, V> cloned = map.clone();
49 assertEquals(map.size(), cloned.size());
50 assertSame(map.get("1"), cloned.get("1"));
51 }
52
53
54
55
56 @Test
57 public void testInitialCapacityZero() {
58 final HashedMap<String, String> map = new HashedMap<>(0);
59 assertEquals(1, map.data.length);
60 }
61
62
63
64
65
66
67
68
69 @Test
70 public void testInternalState() {
71 final HashedMap<Integer, Integer> map = new HashedMap<>(42, 0.75f);
72 assertEquals(0.75f, map.loadFactor, 0.1f);
73 assertEquals(0, map.size);
74 assertEquals(64, map.data.length);
75 assertEquals(48, map.threshold);
76 assertEquals(0, map.modCount);
77
78
79 final HashedMap<Integer, Integer> tmpMap = new HashedMap<>();
80
81
82 for (int i = 1; i <= map.threshold; i++) {
83 tmpMap.put(i, i);
84 }
85 map.putAll(tmpMap);
86
87 assertEquals(96, map.threshold);
88 }
89 }