11 |
|
|
12 |
|
public class ConcurrentSkipListSubMapTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
< |
return new TestSuite(ConcurrentSkipListSubMapTest.class); |
17 |
> |
return new TestSuite(ConcurrentSkipListSubMapTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
/** |
21 |
|
* Create a map from Integers 1-5 to Strings "A"-"E". |
22 |
|
*/ |
23 |
< |
private static ConcurrentNavigableMap map5() { |
24 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
23 |
> |
private static ConcurrentNavigableMap map5() { |
24 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
25 |
|
assertTrue(map.isEmpty()); |
26 |
< |
map.put(zero, "Z"); |
27 |
< |
map.put(one, "A"); |
28 |
< |
map.put(five, "E"); |
29 |
< |
map.put(three, "C"); |
30 |
< |
map.put(two, "B"); |
31 |
< |
map.put(four, "D"); |
32 |
< |
map.put(seven, "F"); |
26 |
> |
map.put(zero, "Z"); |
27 |
> |
map.put(one, "A"); |
28 |
> |
map.put(five, "E"); |
29 |
> |
map.put(three, "C"); |
30 |
> |
map.put(two, "B"); |
31 |
> |
map.put(four, "D"); |
32 |
> |
map.put(seven, "F"); |
33 |
|
assertFalse(map.isEmpty()); |
34 |
|
assertEquals(7, map.size()); |
35 |
|
return map.subMap(one, true, seven, false); |
38 |
|
/** |
39 |
|
* Create a map from Integers -5 to -1 to Strings "A"-"E". |
40 |
|
*/ |
41 |
< |
private static ConcurrentNavigableMap dmap5() { |
42 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
41 |
> |
private static ConcurrentNavigableMap dmap5() { |
42 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
43 |
|
assertTrue(map.isEmpty()); |
44 |
< |
map.put(m1, "A"); |
45 |
< |
map.put(m5, "E"); |
46 |
< |
map.put(m3, "C"); |
47 |
< |
map.put(m2, "B"); |
48 |
< |
map.put(m4, "D"); |
44 |
> |
map.put(m1, "A"); |
45 |
> |
map.put(m5, "E"); |
46 |
> |
map.put(m3, "C"); |
47 |
> |
map.put(m2, "B"); |
48 |
> |
map.put(m4, "D"); |
49 |
|
assertFalse(map.isEmpty()); |
50 |
|
assertEquals(5, map.size()); |
51 |
< |
return map.descendingMap(); |
51 |
> |
return map.descendingMap(); |
52 |
|
} |
53 |
|
|
54 |
< |
private static ConcurrentNavigableMap map0() { |
55 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
54 |
> |
private static ConcurrentNavigableMap map0() { |
55 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
56 |
|
assertTrue(map.isEmpty()); |
57 |
|
return map.tailMap(one, true); |
58 |
|
} |
59 |
|
|
60 |
< |
private static ConcurrentNavigableMap dmap0() { |
61 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
60 |
> |
private static ConcurrentNavigableMap dmap0() { |
61 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
62 |
|
assertTrue(map.isEmpty()); |
63 |
|
return map; |
64 |
|
} |
68 |
|
*/ |
69 |
|
public void testClear() { |
70 |
|
ConcurrentNavigableMap map = map5(); |
71 |
< |
map.clear(); |
72 |
< |
assertEquals(map.size(), 0); |
71 |
> |
map.clear(); |
72 |
> |
assertEquals(map.size(), 0); |
73 |
|
} |
74 |
|
|
75 |
|
|
81 |
|
ConcurrentNavigableMap map2 = map5(); |
82 |
|
assertEquals(map1, map2); |
83 |
|
assertEquals(map2, map1); |
84 |
< |
map1.clear(); |
84 |
> |
map1.clear(); |
85 |
|
assertFalse(map1.equals(map2)); |
86 |
|
assertFalse(map2.equals(map1)); |
87 |
|
} |
91 |
|
*/ |
92 |
|
public void testContainsKey() { |
93 |
|
ConcurrentNavigableMap map = map5(); |
94 |
< |
assertTrue(map.containsKey(one)); |
94 |
> |
assertTrue(map.containsKey(one)); |
95 |
|
assertFalse(map.containsKey(zero)); |
96 |
|
} |
97 |
|
|
100 |
|
*/ |
101 |
|
public void testContainsValue() { |
102 |
|
ConcurrentNavigableMap map = map5(); |
103 |
< |
assertTrue(map.containsValue("A")); |
103 |
> |
assertTrue(map.containsValue("A")); |
104 |
|
assertFalse(map.containsValue("Z")); |
105 |
|
} |
106 |
|
|
110 |
|
*/ |
111 |
|
public void testGet() { |
112 |
|
ConcurrentNavigableMap map = map5(); |
113 |
< |
assertEquals("A", (String)map.get(one)); |
113 |
> |
assertEquals("A", (String)map.get(one)); |
114 |
|
ConcurrentNavigableMap empty = map0(); |
115 |
|
assertNull(empty.get(one)); |
116 |
|
} |
121 |
|
public void testIsEmpty() { |
122 |
|
ConcurrentNavigableMap empty = map0(); |
123 |
|
ConcurrentNavigableMap map = map5(); |
124 |
< |
assertTrue(empty.isEmpty()); |
124 |
> |
assertTrue(empty.isEmpty()); |
125 |
|
assertFalse(map.isEmpty()); |
126 |
|
} |
127 |
|
|
130 |
|
*/ |
131 |
|
public void testFirstKey() { |
132 |
|
ConcurrentNavigableMap map = map5(); |
133 |
< |
assertEquals(one, map.firstKey()); |
133 |
> |
assertEquals(one, map.firstKey()); |
134 |
|
} |
135 |
|
|
136 |
|
/** |
138 |
|
*/ |
139 |
|
public void testLastKey() { |
140 |
|
ConcurrentNavigableMap map = map5(); |
141 |
< |
assertEquals(five, map.lastKey()); |
141 |
> |
assertEquals(five, map.lastKey()); |
142 |
|
} |
143 |
|
|
144 |
|
|
147 |
|
*/ |
148 |
|
public void testKeySet() { |
149 |
|
ConcurrentNavigableMap map = map5(); |
150 |
< |
Set s = map.keySet(); |
151 |
< |
assertEquals(5, s.size()); |
152 |
< |
assertTrue(s.contains(one)); |
153 |
< |
assertTrue(s.contains(two)); |
154 |
< |
assertTrue(s.contains(three)); |
155 |
< |
assertTrue(s.contains(four)); |
156 |
< |
assertTrue(s.contains(five)); |
150 |
> |
Set s = map.keySet(); |
151 |
> |
assertEquals(5, s.size()); |
152 |
> |
assertTrue(s.contains(one)); |
153 |
> |
assertTrue(s.contains(two)); |
154 |
> |
assertTrue(s.contains(three)); |
155 |
> |
assertTrue(s.contains(four)); |
156 |
> |
assertTrue(s.contains(five)); |
157 |
|
} |
158 |
|
|
159 |
|
/** |
161 |
|
*/ |
162 |
|
public void testKeySetOrder() { |
163 |
|
ConcurrentNavigableMap map = map5(); |
164 |
< |
Set s = map.keySet(); |
164 |
> |
Set s = map.keySet(); |
165 |
|
Iterator i = s.iterator(); |
166 |
|
Integer last = (Integer)i.next(); |
167 |
|
assertEquals(last, one); |
177 |
|
*/ |
178 |
|
public void testValues() { |
179 |
|
ConcurrentNavigableMap map = map5(); |
180 |
< |
Collection s = map.values(); |
181 |
< |
assertEquals(5, s.size()); |
182 |
< |
assertTrue(s.contains("A")); |
183 |
< |
assertTrue(s.contains("B")); |
184 |
< |
assertTrue(s.contains("C")); |
185 |
< |
assertTrue(s.contains("D")); |
186 |
< |
assertTrue(s.contains("E")); |
180 |
> |
Collection s = map.values(); |
181 |
> |
assertEquals(5, s.size()); |
182 |
> |
assertTrue(s.contains("A")); |
183 |
> |
assertTrue(s.contains("B")); |
184 |
> |
assertTrue(s.contains("C")); |
185 |
> |
assertTrue(s.contains("D")); |
186 |
> |
assertTrue(s.contains("E")); |
187 |
|
} |
188 |
|
|
189 |
|
/** |
191 |
|
*/ |
192 |
|
public void testKeySetToArray() { |
193 |
|
ConcurrentNavigableMap map = map5(); |
194 |
< |
Set s = map.keySet(); |
194 |
> |
Set s = map.keySet(); |
195 |
|
Object[] ar = s.toArray(); |
196 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
197 |
< |
assertEquals(5, ar.length); |
197 |
> |
assertEquals(5, ar.length); |
198 |
|
ar[0] = m10; |
199 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
200 |
|
} |
204 |
|
*/ |
205 |
|
public void testDescendingKeySetToArray() { |
206 |
|
ConcurrentNavigableMap map = map5(); |
207 |
< |
Set s = map.descendingKeySet(); |
207 |
> |
Set s = map.descendingKeySet(); |
208 |
|
Object[] ar = s.toArray(); |
209 |
< |
assertEquals(5, ar.length); |
209 |
> |
assertEquals(5, ar.length); |
210 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
211 |
|
ar[0] = m10; |
212 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
217 |
|
*/ |
218 |
|
public void testValuesToArray() { |
219 |
|
ConcurrentNavigableMap map = map5(); |
220 |
< |
Collection v = map.values(); |
220 |
> |
Collection v = map.values(); |
221 |
|
Object[] ar = v.toArray(); |
222 |
|
ArrayList s = new ArrayList(Arrays.asList(ar)); |
223 |
< |
assertEquals(5, ar.length); |
224 |
< |
assertTrue(s.contains("A")); |
225 |
< |
assertTrue(s.contains("B")); |
226 |
< |
assertTrue(s.contains("C")); |
227 |
< |
assertTrue(s.contains("D")); |
228 |
< |
assertTrue(s.contains("E")); |
223 |
> |
assertEquals(5, ar.length); |
224 |
> |
assertTrue(s.contains("A")); |
225 |
> |
assertTrue(s.contains("B")); |
226 |
> |
assertTrue(s.contains("C")); |
227 |
> |
assertTrue(s.contains("D")); |
228 |
> |
assertTrue(s.contains("E")); |
229 |
|
} |
230 |
|
|
231 |
|
|
234 |
|
*/ |
235 |
|
public void testEntrySet() { |
236 |
|
ConcurrentNavigableMap map = map5(); |
237 |
< |
Set s = map.entrySet(); |
238 |
< |
assertEquals(5, s.size()); |
237 |
> |
Set s = map.entrySet(); |
238 |
> |
assertEquals(5, s.size()); |
239 |
|
Iterator it = s.iterator(); |
240 |
|
while (it.hasNext()) { |
241 |
|
Map.Entry e = (Map.Entry) it.next(); |
242 |
< |
assertTrue( |
242 |
> |
assertTrue( |
243 |
|
(e.getKey().equals(one) && e.getValue().equals("A")) || |
244 |
|
(e.getKey().equals(two) && e.getValue().equals("B")) || |
245 |
|
(e.getKey().equals(three) && e.getValue().equals("C")) || |
254 |
|
public void testPutAll() { |
255 |
|
ConcurrentNavigableMap empty = map0(); |
256 |
|
ConcurrentNavigableMap map = map5(); |
257 |
< |
empty.putAll(map); |
258 |
< |
assertEquals(5, empty.size()); |
259 |
< |
assertTrue(empty.containsKey(one)); |
260 |
< |
assertTrue(empty.containsKey(two)); |
261 |
< |
assertTrue(empty.containsKey(three)); |
262 |
< |
assertTrue(empty.containsKey(four)); |
263 |
< |
assertTrue(empty.containsKey(five)); |
257 |
> |
empty.putAll(map); |
258 |
> |
assertEquals(5, empty.size()); |
259 |
> |
assertTrue(empty.containsKey(one)); |
260 |
> |
assertTrue(empty.containsKey(two)); |
261 |
> |
assertTrue(empty.containsKey(three)); |
262 |
> |
assertTrue(empty.containsKey(four)); |
263 |
> |
assertTrue(empty.containsKey(five)); |
264 |
|
} |
265 |
|
|
266 |
|
/** |
268 |
|
*/ |
269 |
|
public void testPutIfAbsent() { |
270 |
|
ConcurrentNavigableMap map = map5(); |
271 |
< |
map.putIfAbsent(six, "Z"); |
271 |
> |
map.putIfAbsent(six, "Z"); |
272 |
|
assertTrue(map.containsKey(six)); |
273 |
|
} |
274 |
|
|
285 |
|
*/ |
286 |
|
public void testReplace() { |
287 |
|
ConcurrentNavigableMap map = map5(); |
288 |
< |
assertNull(map.replace(six, "Z")); |
288 |
> |
assertNull(map.replace(six, "Z")); |
289 |
|
assertFalse(map.containsKey(six)); |
290 |
|
} |
291 |
|
|
305 |
|
public void testReplaceValue() { |
306 |
|
ConcurrentNavigableMap map = map5(); |
307 |
|
assertEquals("A", map.get(one)); |
308 |
< |
assertFalse(map.replace(one, "Z", "Z")); |
308 |
> |
assertFalse(map.replace(one, "Z", "Z")); |
309 |
|
assertEquals("A", map.get(one)); |
310 |
|
} |
311 |
|
|
315 |
|
public void testReplaceValue2() { |
316 |
|
ConcurrentNavigableMap map = map5(); |
317 |
|
assertEquals("A", map.get(one)); |
318 |
< |
assertTrue(map.replace(one, "A", "Z")); |
318 |
> |
assertTrue(map.replace(one, "A", "Z")); |
319 |
|
assertEquals("Z", map.get(one)); |
320 |
|
} |
321 |
|
|
325 |
|
*/ |
326 |
|
public void testRemove() { |
327 |
|
ConcurrentNavigableMap map = map5(); |
328 |
< |
map.remove(five); |
329 |
< |
assertEquals(4, map.size()); |
330 |
< |
assertFalse(map.containsKey(five)); |
328 |
> |
map.remove(five); |
329 |
> |
assertEquals(4, map.size()); |
330 |
> |
assertFalse(map.containsKey(five)); |
331 |
|
} |
332 |
|
|
333 |
|
/** |
335 |
|
*/ |
336 |
|
public void testRemove2() { |
337 |
|
ConcurrentNavigableMap map = map5(); |
338 |
< |
assertTrue(map.containsKey(five)); |
338 |
> |
assertTrue(map.containsKey(five)); |
339 |
|
assertEquals("E", map.get(five)); |
340 |
< |
map.remove(five, "E"); |
341 |
< |
assertEquals(4, map.size()); |
342 |
< |
assertFalse(map.containsKey(five)); |
343 |
< |
map.remove(four, "A"); |
344 |
< |
assertEquals(4, map.size()); |
345 |
< |
assertTrue(map.containsKey(four)); |
340 |
> |
map.remove(five, "E"); |
341 |
> |
assertEquals(4, map.size()); |
342 |
> |
assertFalse(map.containsKey(five)); |
343 |
> |
map.remove(four, "A"); |
344 |
> |
assertEquals(4, map.size()); |
345 |
> |
assertTrue(map.containsKey(four)); |
346 |
|
|
347 |
|
} |
348 |
|
|
484 |
|
public void testSize() { |
485 |
|
ConcurrentNavigableMap map = map5(); |
486 |
|
ConcurrentNavigableMap empty = map0(); |
487 |
< |
assertEquals(0, empty.size()); |
488 |
< |
assertEquals(5, map.size()); |
487 |
> |
assertEquals(0, empty.size()); |
488 |
> |
assertEquals(5, map.size()); |
489 |
|
} |
490 |
|
|
491 |
|
/** |
497 |
|
for (int i = 1; i <= 5; ++i) { |
498 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
499 |
|
} |
500 |
< |
} |
500 |
> |
} |
501 |
|
|
502 |
|
// Exception tests |
503 |
|
|
509 |
|
ConcurrentNavigableMap c = map5(); |
510 |
|
c.get(null); |
511 |
|
shouldThrow(); |
512 |
< |
} catch(NullPointerException e){} |
512 |
> |
} catch (NullPointerException e) {} |
513 |
|
} |
514 |
|
|
515 |
|
/** |
520 |
|
ConcurrentNavigableMap c = map5(); |
521 |
|
c.containsKey(null); |
522 |
|
shouldThrow(); |
523 |
< |
} catch(NullPointerException e){} |
523 |
> |
} catch (NullPointerException e) {} |
524 |
|
} |
525 |
|
|
526 |
|
/** |
531 |
|
ConcurrentNavigableMap c = map0(); |
532 |
|
c.containsValue(null); |
533 |
|
shouldThrow(); |
534 |
< |
} catch(NullPointerException e){} |
534 |
> |
} catch (NullPointerException e) {} |
535 |
|
} |
536 |
|
|
537 |
|
|
543 |
|
ConcurrentNavigableMap c = map5(); |
544 |
|
c.put(null, "whatever"); |
545 |
|
shouldThrow(); |
546 |
< |
} catch(NullPointerException e){} |
546 |
> |
} catch (NullPointerException e) {} |
547 |
|
} |
548 |
|
|
549 |
|
/** |
554 |
|
ConcurrentNavigableMap c = map5(); |
555 |
|
c.putIfAbsent(null, "whatever"); |
556 |
|
shouldThrow(); |
557 |
< |
} catch(NullPointerException e){} |
557 |
> |
} catch (NullPointerException e) {} |
558 |
|
} |
559 |
|
|
560 |
|
/** |
565 |
|
ConcurrentNavigableMap c = map5(); |
566 |
|
c.replace(null, "whatever"); |
567 |
|
shouldThrow(); |
568 |
< |
} catch(NullPointerException e){} |
568 |
> |
} catch (NullPointerException e) {} |
569 |
|
} |
570 |
|
|
571 |
|
/** |
576 |
|
ConcurrentNavigableMap c = map5(); |
577 |
|
c.replace(null, one, "whatever"); |
578 |
|
shouldThrow(); |
579 |
< |
} catch(NullPointerException e){} |
579 |
> |
} catch (NullPointerException e) {} |
580 |
|
} |
581 |
|
|
582 |
|
/** |
587 |
|
ConcurrentNavigableMap c = map5(); |
588 |
|
c.remove(null); |
589 |
|
shouldThrow(); |
590 |
< |
} catch(NullPointerException e){} |
590 |
> |
} catch (NullPointerException e) {} |
591 |
|
} |
592 |
|
|
593 |
|
/** |
598 |
|
ConcurrentNavigableMap c = map5(); |
599 |
|
c.remove(null, "whatever"); |
600 |
|
shouldThrow(); |
601 |
< |
} catch(NullPointerException e){} |
601 |
> |
} catch (NullPointerException e) {} |
602 |
|
} |
603 |
|
|
604 |
|
/** |
605 |
|
* A deserialized map equals original |
606 |
|
*/ |
607 |
< |
public void testSerialization() { |
607 |
> |
public void testSerialization() throws Exception { |
608 |
|
ConcurrentNavigableMap q = map5(); |
609 |
|
|
610 |
< |
try { |
611 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
612 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
613 |
< |
out.writeObject(q); |
614 |
< |
out.close(); |
615 |
< |
|
616 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
617 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
618 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
619 |
< |
assertEquals(q.size(), r.size()); |
620 |
< |
assertTrue(q.equals(r)); |
621 |
< |
assertTrue(r.equals(q)); |
622 |
< |
} catch(Exception e){ |
623 |
< |
e.printStackTrace(); |
624 |
< |
unexpectedException(); |
625 |
< |
} |
610 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
611 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
612 |
> |
out.writeObject(q); |
613 |
> |
out.close(); |
614 |
> |
|
615 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
616 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
617 |
> |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
618 |
> |
assertEquals(q.size(), r.size()); |
619 |
> |
assertTrue(q.equals(r)); |
620 |
> |
assertTrue(r.equals(q)); |
621 |
|
} |
622 |
|
|
623 |
|
|
762 |
|
*/ |
763 |
|
public void testDescendingClear() { |
764 |
|
ConcurrentNavigableMap map = dmap5(); |
765 |
< |
map.clear(); |
766 |
< |
assertEquals(map.size(), 0); |
765 |
> |
map.clear(); |
766 |
> |
assertEquals(map.size(), 0); |
767 |
|
} |
768 |
|
|
769 |
|
|
775 |
|
ConcurrentNavigableMap map2 = dmap5(); |
776 |
|
assertEquals(map1, map2); |
777 |
|
assertEquals(map2, map1); |
778 |
< |
map1.clear(); |
778 |
> |
map1.clear(); |
779 |
|
assertFalse(map1.equals(map2)); |
780 |
|
assertFalse(map2.equals(map1)); |
781 |
|
} |
785 |
|
*/ |
786 |
|
public void testDescendingContainsKey() { |
787 |
|
ConcurrentNavigableMap map = dmap5(); |
788 |
< |
assertTrue(map.containsKey(m1)); |
788 |
> |
assertTrue(map.containsKey(m1)); |
789 |
|
assertFalse(map.containsKey(zero)); |
790 |
|
} |
791 |
|
|
794 |
|
*/ |
795 |
|
public void testDescendingContainsValue() { |
796 |
|
ConcurrentNavigableMap map = dmap5(); |
797 |
< |
assertTrue(map.containsValue("A")); |
797 |
> |
assertTrue(map.containsValue("A")); |
798 |
|
assertFalse(map.containsValue("Z")); |
799 |
|
} |
800 |
|
|
804 |
|
*/ |
805 |
|
public void testDescendingGet() { |
806 |
|
ConcurrentNavigableMap map = dmap5(); |
807 |
< |
assertEquals("A", (String)map.get(m1)); |
807 |
> |
assertEquals("A", (String)map.get(m1)); |
808 |
|
ConcurrentNavigableMap empty = dmap0(); |
809 |
|
assertNull(empty.get(m1)); |
810 |
|
} |
815 |
|
public void testDescendingIsEmpty() { |
816 |
|
ConcurrentNavigableMap empty = dmap0(); |
817 |
|
ConcurrentNavigableMap map = dmap5(); |
818 |
< |
assertTrue(empty.isEmpty()); |
818 |
> |
assertTrue(empty.isEmpty()); |
819 |
|
assertFalse(map.isEmpty()); |
820 |
|
} |
821 |
|
|
824 |
|
*/ |
825 |
|
public void testDescendingFirstKey() { |
826 |
|
ConcurrentNavigableMap map = dmap5(); |
827 |
< |
assertEquals(m1, map.firstKey()); |
827 |
> |
assertEquals(m1, map.firstKey()); |
828 |
|
} |
829 |
|
|
830 |
|
/** |
832 |
|
*/ |
833 |
|
public void testDescendingLastKey() { |
834 |
|
ConcurrentNavigableMap map = dmap5(); |
835 |
< |
assertEquals(m5, map.lastKey()); |
835 |
> |
assertEquals(m5, map.lastKey()); |
836 |
|
} |
837 |
|
|
838 |
|
|
841 |
|
*/ |
842 |
|
public void testDescendingKeySet() { |
843 |
|
ConcurrentNavigableMap map = dmap5(); |
844 |
< |
Set s = map.keySet(); |
845 |
< |
assertEquals(5, s.size()); |
846 |
< |
assertTrue(s.contains(m1)); |
847 |
< |
assertTrue(s.contains(m2)); |
848 |
< |
assertTrue(s.contains(m3)); |
849 |
< |
assertTrue(s.contains(m4)); |
850 |
< |
assertTrue(s.contains(m5)); |
844 |
> |
Set s = map.keySet(); |
845 |
> |
assertEquals(5, s.size()); |
846 |
> |
assertTrue(s.contains(m1)); |
847 |
> |
assertTrue(s.contains(m2)); |
848 |
> |
assertTrue(s.contains(m3)); |
849 |
> |
assertTrue(s.contains(m4)); |
850 |
> |
assertTrue(s.contains(m5)); |
851 |
|
} |
852 |
|
|
853 |
|
/** |
855 |
|
*/ |
856 |
|
public void testDescendingKeySetOrder() { |
857 |
|
ConcurrentNavigableMap map = dmap5(); |
858 |
< |
Set s = map.keySet(); |
858 |
> |
Set s = map.keySet(); |
859 |
|
Iterator i = s.iterator(); |
860 |
|
Integer last = (Integer)i.next(); |
861 |
|
assertEquals(last, m1); |
871 |
|
*/ |
872 |
|
public void testDescendingValues() { |
873 |
|
ConcurrentNavigableMap map = dmap5(); |
874 |
< |
Collection s = map.values(); |
875 |
< |
assertEquals(5, s.size()); |
876 |
< |
assertTrue(s.contains("A")); |
877 |
< |
assertTrue(s.contains("B")); |
878 |
< |
assertTrue(s.contains("C")); |
879 |
< |
assertTrue(s.contains("D")); |
880 |
< |
assertTrue(s.contains("E")); |
874 |
> |
Collection s = map.values(); |
875 |
> |
assertEquals(5, s.size()); |
876 |
> |
assertTrue(s.contains("A")); |
877 |
> |
assertTrue(s.contains("B")); |
878 |
> |
assertTrue(s.contains("C")); |
879 |
> |
assertTrue(s.contains("D")); |
880 |
> |
assertTrue(s.contains("E")); |
881 |
|
} |
882 |
|
|
883 |
|
/** |
885 |
|
*/ |
886 |
|
public void testDescendingAscendingKeySetToArray() { |
887 |
|
ConcurrentNavigableMap map = dmap5(); |
888 |
< |
Set s = map.keySet(); |
888 |
> |
Set s = map.keySet(); |
889 |
|
Object[] ar = s.toArray(); |
890 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
891 |
< |
assertEquals(5, ar.length); |
891 |
> |
assertEquals(5, ar.length); |
892 |
|
ar[0] = m10; |
893 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
894 |
|
} |
898 |
|
*/ |
899 |
|
public void testDescendingDescendingKeySetToArray() { |
900 |
|
ConcurrentNavigableMap map = dmap5(); |
901 |
< |
Set s = map.descendingKeySet(); |
901 |
> |
Set s = map.descendingKeySet(); |
902 |
|
Object[] ar = s.toArray(); |
903 |
< |
assertEquals(5, ar.length); |
903 |
> |
assertEquals(5, ar.length); |
904 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
905 |
|
ar[0] = m10; |
906 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
911 |
|
*/ |
912 |
|
public void testDescendingValuesToArray() { |
913 |
|
ConcurrentNavigableMap map = dmap5(); |
914 |
< |
Collection v = map.values(); |
914 |
> |
Collection v = map.values(); |
915 |
|
Object[] ar = v.toArray(); |
916 |
|
ArrayList s = new ArrayList(Arrays.asList(ar)); |
917 |
< |
assertEquals(5, ar.length); |
918 |
< |
assertTrue(s.contains("A")); |
919 |
< |
assertTrue(s.contains("B")); |
920 |
< |
assertTrue(s.contains("C")); |
921 |
< |
assertTrue(s.contains("D")); |
922 |
< |
assertTrue(s.contains("E")); |
917 |
> |
assertEquals(5, ar.length); |
918 |
> |
assertTrue(s.contains("A")); |
919 |
> |
assertTrue(s.contains("B")); |
920 |
> |
assertTrue(s.contains("C")); |
921 |
> |
assertTrue(s.contains("D")); |
922 |
> |
assertTrue(s.contains("E")); |
923 |
|
} |
924 |
|
|
925 |
|
|
928 |
|
*/ |
929 |
|
public void testDescendingEntrySet() { |
930 |
|
ConcurrentNavigableMap map = dmap5(); |
931 |
< |
Set s = map.entrySet(); |
932 |
< |
assertEquals(5, s.size()); |
931 |
> |
Set s = map.entrySet(); |
932 |
> |
assertEquals(5, s.size()); |
933 |
|
Iterator it = s.iterator(); |
934 |
|
while (it.hasNext()) { |
935 |
|
Map.Entry e = (Map.Entry) it.next(); |
936 |
< |
assertTrue( |
936 |
> |
assertTrue( |
937 |
|
(e.getKey().equals(m1) && e.getValue().equals("A")) || |
938 |
|
(e.getKey().equals(m2) && e.getValue().equals("B")) || |
939 |
|
(e.getKey().equals(m3) && e.getValue().equals("C")) || |
948 |
|
public void testDescendingPutAll() { |
949 |
|
ConcurrentNavigableMap empty = dmap0(); |
950 |
|
ConcurrentNavigableMap map = dmap5(); |
951 |
< |
empty.putAll(map); |
952 |
< |
assertEquals(5, empty.size()); |
953 |
< |
assertTrue(empty.containsKey(m1)); |
954 |
< |
assertTrue(empty.containsKey(m2)); |
955 |
< |
assertTrue(empty.containsKey(m3)); |
956 |
< |
assertTrue(empty.containsKey(m4)); |
957 |
< |
assertTrue(empty.containsKey(m5)); |
951 |
> |
empty.putAll(map); |
952 |
> |
assertEquals(5, empty.size()); |
953 |
> |
assertTrue(empty.containsKey(m1)); |
954 |
> |
assertTrue(empty.containsKey(m2)); |
955 |
> |
assertTrue(empty.containsKey(m3)); |
956 |
> |
assertTrue(empty.containsKey(m4)); |
957 |
> |
assertTrue(empty.containsKey(m5)); |
958 |
|
} |
959 |
|
|
960 |
|
/** |
962 |
|
*/ |
963 |
|
public void testDescendingPutIfAbsent() { |
964 |
|
ConcurrentNavigableMap map = dmap5(); |
965 |
< |
map.putIfAbsent(six, "Z"); |
965 |
> |
map.putIfAbsent(six, "Z"); |
966 |
|
assertTrue(map.containsKey(six)); |
967 |
|
} |
968 |
|
|
979 |
|
*/ |
980 |
|
public void testDescendingReplace() { |
981 |
|
ConcurrentNavigableMap map = dmap5(); |
982 |
< |
assertNull(map.replace(six, "Z")); |
982 |
> |
assertNull(map.replace(six, "Z")); |
983 |
|
assertFalse(map.containsKey(six)); |
984 |
|
} |
985 |
|
|
999 |
|
public void testDescendingReplaceValue() { |
1000 |
|
ConcurrentNavigableMap map = dmap5(); |
1001 |
|
assertEquals("A", map.get(m1)); |
1002 |
< |
assertFalse(map.replace(m1, "Z", "Z")); |
1002 |
> |
assertFalse(map.replace(m1, "Z", "Z")); |
1003 |
|
assertEquals("A", map.get(m1)); |
1004 |
|
} |
1005 |
|
|
1009 |
|
public void testDescendingReplaceValue2() { |
1010 |
|
ConcurrentNavigableMap map = dmap5(); |
1011 |
|
assertEquals("A", map.get(m1)); |
1012 |
< |
assertTrue(map.replace(m1, "A", "Z")); |
1012 |
> |
assertTrue(map.replace(m1, "A", "Z")); |
1013 |
|
assertEquals("Z", map.get(m1)); |
1014 |
|
} |
1015 |
|
|
1019 |
|
*/ |
1020 |
|
public void testDescendingRemove() { |
1021 |
|
ConcurrentNavigableMap map = dmap5(); |
1022 |
< |
map.remove(m5); |
1023 |
< |
assertEquals(4, map.size()); |
1024 |
< |
assertFalse(map.containsKey(m5)); |
1022 |
> |
map.remove(m5); |
1023 |
> |
assertEquals(4, map.size()); |
1024 |
> |
assertFalse(map.containsKey(m5)); |
1025 |
|
} |
1026 |
|
|
1027 |
|
/** |
1029 |
|
*/ |
1030 |
|
public void testDescendingRemove2() { |
1031 |
|
ConcurrentNavigableMap map = dmap5(); |
1032 |
< |
assertTrue(map.containsKey(m5)); |
1032 |
> |
assertTrue(map.containsKey(m5)); |
1033 |
|
assertEquals("E", map.get(m5)); |
1034 |
< |
map.remove(m5, "E"); |
1035 |
< |
assertEquals(4, map.size()); |
1036 |
< |
assertFalse(map.containsKey(m5)); |
1037 |
< |
map.remove(m4, "A"); |
1038 |
< |
assertEquals(4, map.size()); |
1039 |
< |
assertTrue(map.containsKey(m4)); |
1034 |
> |
map.remove(m5, "E"); |
1035 |
> |
assertEquals(4, map.size()); |
1036 |
> |
assertFalse(map.containsKey(m5)); |
1037 |
> |
map.remove(m4, "A"); |
1038 |
> |
assertEquals(4, map.size()); |
1039 |
> |
assertTrue(map.containsKey(m4)); |
1040 |
|
|
1041 |
|
} |
1042 |
|
|
1178 |
|
public void testDescendingSize() { |
1179 |
|
ConcurrentNavigableMap map = dmap5(); |
1180 |
|
ConcurrentNavigableMap empty = dmap0(); |
1181 |
< |
assertEquals(0, empty.size()); |
1182 |
< |
assertEquals(5, map.size()); |
1181 |
> |
assertEquals(0, empty.size()); |
1182 |
> |
assertEquals(5, map.size()); |
1183 |
|
} |
1184 |
|
|
1185 |
|
/** |
1191 |
|
for (int i = 1; i <= 5; ++i) { |
1192 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
1193 |
|
} |
1194 |
< |
} |
1194 |
> |
} |
1195 |
|
|
1196 |
|
// Exception testDescendings |
1197 |
|
|
1203 |
|
ConcurrentNavigableMap c = dmap5(); |
1204 |
|
c.get(null); |
1205 |
|
shouldThrow(); |
1206 |
< |
} catch(NullPointerException e){} |
1206 |
> |
} catch (NullPointerException e) {} |
1207 |
|
} |
1208 |
|
|
1209 |
|
/** |
1214 |
|
ConcurrentNavigableMap c = dmap5(); |
1215 |
|
c.containsKey(null); |
1216 |
|
shouldThrow(); |
1217 |
< |
} catch(NullPointerException e){} |
1217 |
> |
} catch (NullPointerException e) {} |
1218 |
|
} |
1219 |
|
|
1220 |
|
/** |
1225 |
|
ConcurrentNavigableMap c = dmap0(); |
1226 |
|
c.containsValue(null); |
1227 |
|
shouldThrow(); |
1228 |
< |
} catch(NullPointerException e){} |
1228 |
> |
} catch (NullPointerException e) {} |
1229 |
|
} |
1230 |
|
|
1231 |
|
|
1237 |
|
ConcurrentNavigableMap c = dmap5(); |
1238 |
|
c.put(null, "whatever"); |
1239 |
|
shouldThrow(); |
1240 |
< |
} catch(NullPointerException e){} |
1240 |
> |
} catch (NullPointerException e) {} |
1241 |
|
} |
1242 |
|
|
1243 |
|
/** |
1248 |
|
ConcurrentNavigableMap c = dmap5(); |
1249 |
|
c.putIfAbsent(null, "whatever"); |
1250 |
|
shouldThrow(); |
1251 |
< |
} catch(NullPointerException e){} |
1251 |
> |
} catch (NullPointerException e) {} |
1252 |
|
} |
1253 |
|
|
1254 |
|
/** |
1259 |
|
ConcurrentNavigableMap c = dmap5(); |
1260 |
|
c.replace(null, "whatever"); |
1261 |
|
shouldThrow(); |
1262 |
< |
} catch(NullPointerException e){} |
1262 |
> |
} catch (NullPointerException e) {} |
1263 |
|
} |
1264 |
|
|
1265 |
|
/** |
1270 |
|
ConcurrentNavigableMap c = dmap5(); |
1271 |
|
c.replace(null, m1, "whatever"); |
1272 |
|
shouldThrow(); |
1273 |
< |
} catch(NullPointerException e){} |
1273 |
> |
} catch (NullPointerException e) {} |
1274 |
|
} |
1275 |
|
|
1276 |
|
/** |
1281 |
|
ConcurrentNavigableMap c = dmap5(); |
1282 |
|
c.remove(null); |
1283 |
|
shouldThrow(); |
1284 |
< |
} catch(NullPointerException e){} |
1284 |
> |
} catch (NullPointerException e) {} |
1285 |
|
} |
1286 |
|
|
1287 |
|
/** |
1292 |
|
ConcurrentNavigableMap c = dmap5(); |
1293 |
|
c.remove(null, "whatever"); |
1294 |
|
shouldThrow(); |
1295 |
< |
} catch(NullPointerException e){} |
1295 |
> |
} catch (NullPointerException e) {} |
1296 |
|
} |
1297 |
|
|
1298 |
|
/** |
1299 |
|
* A deserialized map equals original |
1300 |
|
*/ |
1301 |
< |
public void testDescendingSerialization() { |
1301 |
> |
public void testDescendingSerialization() throws Exception { |
1302 |
|
ConcurrentNavigableMap q = dmap5(); |
1303 |
|
|
1304 |
< |
try { |
1305 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1306 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1307 |
< |
out.writeObject(q); |
1308 |
< |
out.close(); |
1309 |
< |
|
1310 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1311 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1312 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1313 |
< |
assertEquals(q.size(), r.size()); |
1314 |
< |
assertTrue(q.equals(r)); |
1320 |
< |
assertTrue(r.equals(q)); |
1321 |
< |
} catch(Exception e){ |
1322 |
< |
e.printStackTrace(); |
1323 |
< |
unexpectedException(); |
1324 |
< |
} |
1304 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1305 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1306 |
> |
out.writeObject(q); |
1307 |
> |
out.close(); |
1308 |
> |
|
1309 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1310 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1311 |
> |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1312 |
> |
assertEquals(q.size(), r.size()); |
1313 |
> |
assertTrue(q.equals(r)); |
1314 |
> |
assertTrue(r.equals(q)); |
1315 |
|
} |
1316 |
|
|
1317 |
|
|
1328 |
– |
|
1318 |
|
/** |
1319 |
|
* subMap returns map with keys in requested range |
1320 |
|
*/ |
1449 |
|
assertEquals(3, sm.size()); |
1450 |
|
assertEquals(4, map.size()); |
1451 |
|
} |
1452 |
< |
|
1452 |
> |
|
1453 |
|
} |