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.assertTrue;
21
22 import java.util.HashMap;
23
24 import org.apache.commons.collections4.BoundedMap;
25 import org.apache.commons.collections4.KeyValue;
26 import org.apache.commons.collections4.OrderedMap;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class SingletonMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
33
34 private static final Integer ONE = Integer.valueOf(1);
35 private static final Integer TWO = Integer.valueOf(2);
36 private static final String TEN = "10";
37
38 public SingletonMapTest() {
39 super(SingletonMapTest.class.getSimpleName());
40 }
41
42 @Override
43 public String getCompatibilityVersion() {
44 return "4";
45 }
46
47 @Override
48 @SuppressWarnings("unchecked")
49 public V[] getNewSampleValues() {
50 return (V[]) new Object[] { TEN };
51 }
52
53 @Override
54 @SuppressWarnings("unchecked")
55 public K[] getSampleKeys() {
56 return (K[]) new Object[] { ONE };
57 }
58
59 @Override
60 @SuppressWarnings("unchecked")
61 public V[] getSampleValues() {
62 return (V[]) new Object[] { TWO };
63 }
64
65 @Override
66 public String[] ignoredTests() {
67
68
69 return new String[] {
70 "SingletonMapTest.bulkTestMapIterator.testEmptyMapIterator",
71 "SingletonMapTest.bulkTestOrderedMapIterator.testEmptyMapIterator",
72 };
73 }
74
75 @Override
76 public boolean isPutAddSupported() {
77 return false;
78 }
79
80 @Override
81 public boolean isRemoveSupported() {
82 return false;
83 }
84
85 @Override
86 @SuppressWarnings("unchecked")
87 public SingletonMap<K, V> makeFullMap() {
88 return new SingletonMap<>((K) ONE, (V) TWO);
89 }
90
91 @Override
92 public OrderedMap<K, V> makeObject() {
93
94
95 return UnmodifiableOrderedMap.unmodifiableOrderedMap(ListOrderedMap.listOrderedMap(new HashMap<>()));
96 }
97
98 @Test
99 public void testBoundedMap() {
100 final SingletonMap<K, V> map = makeFullMap();
101 assertEquals(1, map.size());
102 assertTrue(map.isFull());
103 assertEquals(1, map.maxSize());
104 assertTrue(map instanceof BoundedMap);
105 }
106
107 @Test
108 public void testClone() {
109 final SingletonMap<K, V> map = makeFullMap();
110 assertEquals(1, map.size());
111 final SingletonMap<K, V> cloned = map.clone();
112 assertEquals(1, cloned.size());
113 assertTrue(cloned.containsKey(ONE));
114 assertTrue(cloned.containsValue(TWO));
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 @Test
165 public void testKeyValue() {
166 final SingletonMap<K, V> map = makeFullMap();
167 assertEquals(1, map.size());
168 assertEquals(ONE, map.getKey());
169 assertEquals(TWO, map.getValue());
170 assertTrue(map instanceof KeyValue);
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184 }