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 java.util.HashMap;
20
21 import junit.framework.Test;
22 import org.apache.commons.collections4.BoundedMap;
23 import org.apache.commons.collections4.BulkTest;
24 import org.apache.commons.collections4.KeyValue;
25 import org.apache.commons.collections4.OrderedMap;
26
27
28
29
30
31 public class SingletonMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
32
33 private static final Integer ONE = Integer.valueOf(1);
34 private static final Integer TWO = Integer.valueOf(2);
35 private static final String TEN = "10";
36
37 public SingletonMapTest(final String testName) {
38 super(testName);
39 }
40
41 public static Test suite() {
42 return BulkTest.makeSuite(SingletonMapTest.class);
43 }
44
45
46 @Override
47 public OrderedMap<K, V> makeObject() {
48
49
50 return UnmodifiableOrderedMap.unmodifiableOrderedMap(ListOrderedMap.listOrderedMap(new HashMap<K, V>()));
51 }
52
53 @Override
54 public String[] ignoredTests() {
55
56
57 return new String[] {
58 "SingletonMapTest.bulkTestMapIterator.testEmptyMapIterator",
59 "SingletonMapTest.bulkTestOrderedMapIterator.testEmptyMapIterator",
60 };
61 }
62
63 @Override
64 @SuppressWarnings("unchecked")
65 public SingletonMap<K, V> makeFullMap() {
66 return new SingletonMap<>((K) ONE, (V) TWO);
67 }
68
69 @Override
70 public boolean isPutAddSupported() {
71 return false;
72 }
73
74 @Override
75 public boolean isRemoveSupported() {
76 return false;
77 }
78
79 @Override
80 @SuppressWarnings("unchecked")
81 public K[] getSampleKeys() {
82 return (K[]) new Object[] { ONE };
83 }
84
85 @Override
86 @SuppressWarnings("unchecked")
87 public V[] getSampleValues() {
88 return (V[]) new Object[] { TWO };
89 }
90
91 @Override
92 @SuppressWarnings("unchecked")
93 public V[] getNewSampleValues() {
94 return (V[]) new Object[] { TEN };
95 }
96
97
98 public void testClone() {
99 final SingletonMap<K, V> map = makeFullMap();
100 assertEquals(1, map.size());
101 final SingletonMap<K, V> cloned = map.clone();
102 assertEquals(1, cloned.size());
103 assertEquals(true, cloned.containsKey(ONE));
104 assertEquals(true, cloned.containsValue(TWO));
105 }
106
107 public void testKeyValue() {
108 final SingletonMap<K, V> map = makeFullMap();
109 assertEquals(1, map.size());
110 assertEquals(ONE, map.getKey());
111 assertEquals(TWO, map.getValue());
112 assertTrue(map instanceof KeyValue);
113 }
114
115 public void testBoundedMap() {
116 final SingletonMap<K, V> map = makeFullMap();
117 assertEquals(1, map.size());
118 assertEquals(true, map.isFull());
119 assertEquals(1, map.maxSize());
120 assertTrue(map instanceof BoundedMap);
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
165
166
167
168
169
170
171 @Override
172 public String getCompatibilityVersion() {
173 return "4";
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 }