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(); |
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); |
39 |
|
* Create a map from Integers -5 to -1 to Strings "A"-"E". |
40 |
|
*/ |
41 |
|
private static ConcurrentNavigableMap dmap5() { |
42 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
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(); |
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(); |
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(); |
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 |
|
|
444 |
|
try { |
445 |
|
e.setValue("A"); |
446 |
|
shouldThrow(); |
447 |
< |
} catch (Exception ok) { |
448 |
< |
} |
447 |
> |
} catch (UnsupportedOperationException success) {} |
448 |
|
e = map.pollFirstEntry(); |
449 |
|
assertNull(e); |
450 |
|
} |
471 |
|
try { |
472 |
|
e.setValue("E"); |
473 |
|
shouldThrow(); |
474 |
< |
} catch (Exception ok) { |
476 |
< |
} |
474 |
> |
} catch (UnsupportedOperationException success) {} |
475 |
|
e = map.pollLastEntry(); |
476 |
|
assertNull(e); |
477 |
|
} |
482 |
|
public void testSize() { |
483 |
|
ConcurrentNavigableMap map = map5(); |
484 |
|
ConcurrentNavigableMap empty = map0(); |
485 |
< |
assertEquals(0, empty.size()); |
486 |
< |
assertEquals(5, map.size()); |
485 |
> |
assertEquals(0, empty.size()); |
486 |
> |
assertEquals(5, map.size()); |
487 |
|
} |
488 |
|
|
489 |
|
/** |
507 |
|
ConcurrentNavigableMap c = map5(); |
508 |
|
c.get(null); |
509 |
|
shouldThrow(); |
510 |
< |
} catch(NullPointerException e){} |
510 |
> |
} catch (NullPointerException success) {} |
511 |
|
} |
512 |
|
|
513 |
|
/** |
518 |
|
ConcurrentNavigableMap c = map5(); |
519 |
|
c.containsKey(null); |
520 |
|
shouldThrow(); |
521 |
< |
} catch(NullPointerException e){} |
521 |
> |
} catch (NullPointerException success) {} |
522 |
|
} |
523 |
|
|
524 |
|
/** |
529 |
|
ConcurrentNavigableMap c = map0(); |
530 |
|
c.containsValue(null); |
531 |
|
shouldThrow(); |
532 |
< |
} catch(NullPointerException e){} |
532 |
> |
} catch (NullPointerException success) {} |
533 |
|
} |
534 |
|
|
535 |
|
|
541 |
|
ConcurrentNavigableMap c = map5(); |
542 |
|
c.put(null, "whatever"); |
543 |
|
shouldThrow(); |
544 |
< |
} catch(NullPointerException e){} |
544 |
> |
} catch (NullPointerException success) {} |
545 |
|
} |
546 |
|
|
547 |
|
/** |
552 |
|
ConcurrentNavigableMap c = map5(); |
553 |
|
c.putIfAbsent(null, "whatever"); |
554 |
|
shouldThrow(); |
555 |
< |
} catch(NullPointerException e){} |
555 |
> |
} catch (NullPointerException success) {} |
556 |
|
} |
557 |
|
|
558 |
|
/** |
563 |
|
ConcurrentNavigableMap c = map5(); |
564 |
|
c.replace(null, "whatever"); |
565 |
|
shouldThrow(); |
566 |
< |
} catch(NullPointerException e){} |
566 |
> |
} catch (NullPointerException success) {} |
567 |
|
} |
568 |
|
|
569 |
|
/** |
574 |
|
ConcurrentNavigableMap c = map5(); |
575 |
|
c.replace(null, one, "whatever"); |
576 |
|
shouldThrow(); |
577 |
< |
} catch(NullPointerException e){} |
577 |
> |
} catch (NullPointerException success) {} |
578 |
|
} |
579 |
|
|
580 |
|
/** |
585 |
|
ConcurrentNavigableMap c = map5(); |
586 |
|
c.remove(null); |
587 |
|
shouldThrow(); |
588 |
< |
} catch(NullPointerException e){} |
588 |
> |
} catch (NullPointerException success) {} |
589 |
|
} |
590 |
|
|
591 |
|
/** |
596 |
|
ConcurrentNavigableMap c = map5(); |
597 |
|
c.remove(null, "whatever"); |
598 |
|
shouldThrow(); |
599 |
< |
} catch(NullPointerException e){} |
599 |
> |
} catch (NullPointerException success) {} |
600 |
|
} |
601 |
|
|
602 |
|
/** |
603 |
|
* A deserialized map equals original |
604 |
|
*/ |
605 |
< |
public void testSerialization() { |
605 |
> |
public void testSerialization() throws Exception { |
606 |
|
ConcurrentNavigableMap q = map5(); |
607 |
|
|
608 |
< |
try { |
609 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
610 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
611 |
< |
out.writeObject(q); |
612 |
< |
out.close(); |
613 |
< |
|
614 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
615 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
616 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
617 |
< |
assertEquals(q.size(), r.size()); |
618 |
< |
assertTrue(q.equals(r)); |
621 |
< |
assertTrue(r.equals(q)); |
622 |
< |
} catch(Exception e){ |
623 |
< |
e.printStackTrace(); |
624 |
< |
unexpectedException(); |
625 |
< |
} |
608 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
609 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
610 |
> |
out.writeObject(q); |
611 |
> |
out.close(); |
612 |
> |
|
613 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
614 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
615 |
> |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
616 |
> |
assertEquals(q.size(), r.size()); |
617 |
> |
assertTrue(q.equals(r)); |
618 |
> |
assertTrue(r.equals(q)); |
619 |
|
} |
620 |
|
|
621 |
|
|
760 |
|
*/ |
761 |
|
public void testDescendingClear() { |
762 |
|
ConcurrentNavigableMap map = dmap5(); |
763 |
< |
map.clear(); |
764 |
< |
assertEquals(map.size(), 0); |
763 |
> |
map.clear(); |
764 |
> |
assertEquals(map.size(), 0); |
765 |
|
} |
766 |
|
|
767 |
|
|
773 |
|
ConcurrentNavigableMap map2 = dmap5(); |
774 |
|
assertEquals(map1, map2); |
775 |
|
assertEquals(map2, map1); |
776 |
< |
map1.clear(); |
776 |
> |
map1.clear(); |
777 |
|
assertFalse(map1.equals(map2)); |
778 |
|
assertFalse(map2.equals(map1)); |
779 |
|
} |
783 |
|
*/ |
784 |
|
public void testDescendingContainsKey() { |
785 |
|
ConcurrentNavigableMap map = dmap5(); |
786 |
< |
assertTrue(map.containsKey(m1)); |
786 |
> |
assertTrue(map.containsKey(m1)); |
787 |
|
assertFalse(map.containsKey(zero)); |
788 |
|
} |
789 |
|
|
792 |
|
*/ |
793 |
|
public void testDescendingContainsValue() { |
794 |
|
ConcurrentNavigableMap map = dmap5(); |
795 |
< |
assertTrue(map.containsValue("A")); |
795 |
> |
assertTrue(map.containsValue("A")); |
796 |
|
assertFalse(map.containsValue("Z")); |
797 |
|
} |
798 |
|
|
802 |
|
*/ |
803 |
|
public void testDescendingGet() { |
804 |
|
ConcurrentNavigableMap map = dmap5(); |
805 |
< |
assertEquals("A", (String)map.get(m1)); |
805 |
> |
assertEquals("A", (String)map.get(m1)); |
806 |
|
ConcurrentNavigableMap empty = dmap0(); |
807 |
|
assertNull(empty.get(m1)); |
808 |
|
} |
813 |
|
public void testDescendingIsEmpty() { |
814 |
|
ConcurrentNavigableMap empty = dmap0(); |
815 |
|
ConcurrentNavigableMap map = dmap5(); |
816 |
< |
assertTrue(empty.isEmpty()); |
816 |
> |
assertTrue(empty.isEmpty()); |
817 |
|
assertFalse(map.isEmpty()); |
818 |
|
} |
819 |
|
|
822 |
|
*/ |
823 |
|
public void testDescendingFirstKey() { |
824 |
|
ConcurrentNavigableMap map = dmap5(); |
825 |
< |
assertEquals(m1, map.firstKey()); |
825 |
> |
assertEquals(m1, map.firstKey()); |
826 |
|
} |
827 |
|
|
828 |
|
/** |
830 |
|
*/ |
831 |
|
public void testDescendingLastKey() { |
832 |
|
ConcurrentNavigableMap map = dmap5(); |
833 |
< |
assertEquals(m5, map.lastKey()); |
833 |
> |
assertEquals(m5, map.lastKey()); |
834 |
|
} |
835 |
|
|
836 |
|
|
839 |
|
*/ |
840 |
|
public void testDescendingKeySet() { |
841 |
|
ConcurrentNavigableMap map = dmap5(); |
842 |
< |
Set s = map.keySet(); |
843 |
< |
assertEquals(5, s.size()); |
844 |
< |
assertTrue(s.contains(m1)); |
845 |
< |
assertTrue(s.contains(m2)); |
846 |
< |
assertTrue(s.contains(m3)); |
847 |
< |
assertTrue(s.contains(m4)); |
848 |
< |
assertTrue(s.contains(m5)); |
842 |
> |
Set s = map.keySet(); |
843 |
> |
assertEquals(5, s.size()); |
844 |
> |
assertTrue(s.contains(m1)); |
845 |
> |
assertTrue(s.contains(m2)); |
846 |
> |
assertTrue(s.contains(m3)); |
847 |
> |
assertTrue(s.contains(m4)); |
848 |
> |
assertTrue(s.contains(m5)); |
849 |
|
} |
850 |
|
|
851 |
|
/** |
853 |
|
*/ |
854 |
|
public void testDescendingKeySetOrder() { |
855 |
|
ConcurrentNavigableMap map = dmap5(); |
856 |
< |
Set s = map.keySet(); |
856 |
> |
Set s = map.keySet(); |
857 |
|
Iterator i = s.iterator(); |
858 |
|
Integer last = (Integer)i.next(); |
859 |
|
assertEquals(last, m1); |
869 |
|
*/ |
870 |
|
public void testDescendingValues() { |
871 |
|
ConcurrentNavigableMap map = dmap5(); |
872 |
< |
Collection s = map.values(); |
873 |
< |
assertEquals(5, s.size()); |
874 |
< |
assertTrue(s.contains("A")); |
875 |
< |
assertTrue(s.contains("B")); |
876 |
< |
assertTrue(s.contains("C")); |
877 |
< |
assertTrue(s.contains("D")); |
878 |
< |
assertTrue(s.contains("E")); |
872 |
> |
Collection s = map.values(); |
873 |
> |
assertEquals(5, s.size()); |
874 |
> |
assertTrue(s.contains("A")); |
875 |
> |
assertTrue(s.contains("B")); |
876 |
> |
assertTrue(s.contains("C")); |
877 |
> |
assertTrue(s.contains("D")); |
878 |
> |
assertTrue(s.contains("E")); |
879 |
|
} |
880 |
|
|
881 |
|
/** |
883 |
|
*/ |
884 |
|
public void testDescendingAscendingKeySetToArray() { |
885 |
|
ConcurrentNavigableMap map = dmap5(); |
886 |
< |
Set s = map.keySet(); |
886 |
> |
Set s = map.keySet(); |
887 |
|
Object[] ar = s.toArray(); |
888 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
889 |
< |
assertEquals(5, ar.length); |
889 |
> |
assertEquals(5, ar.length); |
890 |
|
ar[0] = m10; |
891 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
892 |
|
} |
896 |
|
*/ |
897 |
|
public void testDescendingDescendingKeySetToArray() { |
898 |
|
ConcurrentNavigableMap map = dmap5(); |
899 |
< |
Set s = map.descendingKeySet(); |
899 |
> |
Set s = map.descendingKeySet(); |
900 |
|
Object[] ar = s.toArray(); |
901 |
< |
assertEquals(5, ar.length); |
901 |
> |
assertEquals(5, ar.length); |
902 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
903 |
|
ar[0] = m10; |
904 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
909 |
|
*/ |
910 |
|
public void testDescendingValuesToArray() { |
911 |
|
ConcurrentNavigableMap map = dmap5(); |
912 |
< |
Collection v = map.values(); |
912 |
> |
Collection v = map.values(); |
913 |
|
Object[] ar = v.toArray(); |
914 |
|
ArrayList s = new ArrayList(Arrays.asList(ar)); |
915 |
< |
assertEquals(5, ar.length); |
916 |
< |
assertTrue(s.contains("A")); |
917 |
< |
assertTrue(s.contains("B")); |
918 |
< |
assertTrue(s.contains("C")); |
919 |
< |
assertTrue(s.contains("D")); |
920 |
< |
assertTrue(s.contains("E")); |
915 |
> |
assertEquals(5, ar.length); |
916 |
> |
assertTrue(s.contains("A")); |
917 |
> |
assertTrue(s.contains("B")); |
918 |
> |
assertTrue(s.contains("C")); |
919 |
> |
assertTrue(s.contains("D")); |
920 |
> |
assertTrue(s.contains("E")); |
921 |
|
} |
922 |
|
|
923 |
|
|
926 |
|
*/ |
927 |
|
public void testDescendingEntrySet() { |
928 |
|
ConcurrentNavigableMap map = dmap5(); |
929 |
< |
Set s = map.entrySet(); |
930 |
< |
assertEquals(5, s.size()); |
929 |
> |
Set s = map.entrySet(); |
930 |
> |
assertEquals(5, s.size()); |
931 |
|
Iterator it = s.iterator(); |
932 |
|
while (it.hasNext()) { |
933 |
|
Map.Entry e = (Map.Entry) it.next(); |
946 |
|
public void testDescendingPutAll() { |
947 |
|
ConcurrentNavigableMap empty = dmap0(); |
948 |
|
ConcurrentNavigableMap map = dmap5(); |
949 |
< |
empty.putAll(map); |
950 |
< |
assertEquals(5, empty.size()); |
951 |
< |
assertTrue(empty.containsKey(m1)); |
952 |
< |
assertTrue(empty.containsKey(m2)); |
953 |
< |
assertTrue(empty.containsKey(m3)); |
954 |
< |
assertTrue(empty.containsKey(m4)); |
955 |
< |
assertTrue(empty.containsKey(m5)); |
949 |
> |
empty.putAll(map); |
950 |
> |
assertEquals(5, empty.size()); |
951 |
> |
assertTrue(empty.containsKey(m1)); |
952 |
> |
assertTrue(empty.containsKey(m2)); |
953 |
> |
assertTrue(empty.containsKey(m3)); |
954 |
> |
assertTrue(empty.containsKey(m4)); |
955 |
> |
assertTrue(empty.containsKey(m5)); |
956 |
|
} |
957 |
|
|
958 |
|
/** |
960 |
|
*/ |
961 |
|
public void testDescendingPutIfAbsent() { |
962 |
|
ConcurrentNavigableMap map = dmap5(); |
963 |
< |
map.putIfAbsent(six, "Z"); |
963 |
> |
map.putIfAbsent(six, "Z"); |
964 |
|
assertTrue(map.containsKey(six)); |
965 |
|
} |
966 |
|
|
977 |
|
*/ |
978 |
|
public void testDescendingReplace() { |
979 |
|
ConcurrentNavigableMap map = dmap5(); |
980 |
< |
assertNull(map.replace(six, "Z")); |
980 |
> |
assertNull(map.replace(six, "Z")); |
981 |
|
assertFalse(map.containsKey(six)); |
982 |
|
} |
983 |
|
|
997 |
|
public void testDescendingReplaceValue() { |
998 |
|
ConcurrentNavigableMap map = dmap5(); |
999 |
|
assertEquals("A", map.get(m1)); |
1000 |
< |
assertFalse(map.replace(m1, "Z", "Z")); |
1000 |
> |
assertFalse(map.replace(m1, "Z", "Z")); |
1001 |
|
assertEquals("A", map.get(m1)); |
1002 |
|
} |
1003 |
|
|
1007 |
|
public void testDescendingReplaceValue2() { |
1008 |
|
ConcurrentNavigableMap map = dmap5(); |
1009 |
|
assertEquals("A", map.get(m1)); |
1010 |
< |
assertTrue(map.replace(m1, "A", "Z")); |
1010 |
> |
assertTrue(map.replace(m1, "A", "Z")); |
1011 |
|
assertEquals("Z", map.get(m1)); |
1012 |
|
} |
1013 |
|
|
1017 |
|
*/ |
1018 |
|
public void testDescendingRemove() { |
1019 |
|
ConcurrentNavigableMap map = dmap5(); |
1020 |
< |
map.remove(m5); |
1021 |
< |
assertEquals(4, map.size()); |
1022 |
< |
assertFalse(map.containsKey(m5)); |
1020 |
> |
map.remove(m5); |
1021 |
> |
assertEquals(4, map.size()); |
1022 |
> |
assertFalse(map.containsKey(m5)); |
1023 |
|
} |
1024 |
|
|
1025 |
|
/** |
1027 |
|
*/ |
1028 |
|
public void testDescendingRemove2() { |
1029 |
|
ConcurrentNavigableMap map = dmap5(); |
1030 |
< |
assertTrue(map.containsKey(m5)); |
1030 |
> |
assertTrue(map.containsKey(m5)); |
1031 |
|
assertEquals("E", map.get(m5)); |
1032 |
< |
map.remove(m5, "E"); |
1033 |
< |
assertEquals(4, map.size()); |
1034 |
< |
assertFalse(map.containsKey(m5)); |
1035 |
< |
map.remove(m4, "A"); |
1036 |
< |
assertEquals(4, map.size()); |
1037 |
< |
assertTrue(map.containsKey(m4)); |
1032 |
> |
map.remove(m5, "E"); |
1033 |
> |
assertEquals(4, map.size()); |
1034 |
> |
assertFalse(map.containsKey(m5)); |
1035 |
> |
map.remove(m4, "A"); |
1036 |
> |
assertEquals(4, map.size()); |
1037 |
> |
assertTrue(map.containsKey(m4)); |
1038 |
|
|
1039 |
|
} |
1040 |
|
|
1136 |
|
try { |
1137 |
|
e.setValue("A"); |
1138 |
|
shouldThrow(); |
1139 |
< |
} catch (Exception ok) { |
1147 |
< |
} |
1139 |
> |
} catch (UnsupportedOperationException success) {} |
1140 |
|
e = map.pollFirstEntry(); |
1141 |
|
assertNull(e); |
1142 |
|
} |
1163 |
|
try { |
1164 |
|
e.setValue("E"); |
1165 |
|
shouldThrow(); |
1166 |
< |
} catch (Exception ok) { |
1175 |
< |
} |
1166 |
> |
} catch (UnsupportedOperationException success) {} |
1167 |
|
e = map.pollLastEntry(); |
1168 |
|
assertNull(e); |
1169 |
|
} |
1174 |
|
public void testDescendingSize() { |
1175 |
|
ConcurrentNavigableMap map = dmap5(); |
1176 |
|
ConcurrentNavigableMap empty = dmap0(); |
1177 |
< |
assertEquals(0, empty.size()); |
1178 |
< |
assertEquals(5, map.size()); |
1177 |
> |
assertEquals(0, empty.size()); |
1178 |
> |
assertEquals(5, map.size()); |
1179 |
|
} |
1180 |
|
|
1181 |
|
/** |
1199 |
|
ConcurrentNavigableMap c = dmap5(); |
1200 |
|
c.get(null); |
1201 |
|
shouldThrow(); |
1202 |
< |
} catch(NullPointerException e){} |
1202 |
> |
} catch (NullPointerException success) {} |
1203 |
|
} |
1204 |
|
|
1205 |
|
/** |
1210 |
|
ConcurrentNavigableMap c = dmap5(); |
1211 |
|
c.containsKey(null); |
1212 |
|
shouldThrow(); |
1213 |
< |
} catch(NullPointerException e){} |
1213 |
> |
} catch (NullPointerException success) {} |
1214 |
|
} |
1215 |
|
|
1216 |
|
/** |
1221 |
|
ConcurrentNavigableMap c = dmap0(); |
1222 |
|
c.containsValue(null); |
1223 |
|
shouldThrow(); |
1224 |
< |
} catch(NullPointerException e){} |
1224 |
> |
} catch (NullPointerException success) {} |
1225 |
|
} |
1226 |
|
|
1227 |
|
|
1233 |
|
ConcurrentNavigableMap c = dmap5(); |
1234 |
|
c.put(null, "whatever"); |
1235 |
|
shouldThrow(); |
1236 |
< |
} catch(NullPointerException e){} |
1236 |
> |
} catch (NullPointerException success) {} |
1237 |
|
} |
1238 |
|
|
1239 |
|
/** |
1244 |
|
ConcurrentNavigableMap c = dmap5(); |
1245 |
|
c.putIfAbsent(null, "whatever"); |
1246 |
|
shouldThrow(); |
1247 |
< |
} catch(NullPointerException e){} |
1247 |
> |
} catch (NullPointerException success) {} |
1248 |
|
} |
1249 |
|
|
1250 |
|
/** |
1255 |
|
ConcurrentNavigableMap c = dmap5(); |
1256 |
|
c.replace(null, "whatever"); |
1257 |
|
shouldThrow(); |
1258 |
< |
} catch(NullPointerException e){} |
1258 |
> |
} catch (NullPointerException success) {} |
1259 |
|
} |
1260 |
|
|
1261 |
|
/** |
1266 |
|
ConcurrentNavigableMap c = dmap5(); |
1267 |
|
c.replace(null, m1, "whatever"); |
1268 |
|
shouldThrow(); |
1269 |
< |
} catch(NullPointerException e){} |
1269 |
> |
} catch (NullPointerException success) {} |
1270 |
|
} |
1271 |
|
|
1272 |
|
/** |
1277 |
|
ConcurrentNavigableMap c = dmap5(); |
1278 |
|
c.remove(null); |
1279 |
|
shouldThrow(); |
1280 |
< |
} catch(NullPointerException e){} |
1280 |
> |
} catch (NullPointerException success) {} |
1281 |
|
} |
1282 |
|
|
1283 |
|
/** |
1288 |
|
ConcurrentNavigableMap c = dmap5(); |
1289 |
|
c.remove(null, "whatever"); |
1290 |
|
shouldThrow(); |
1291 |
< |
} catch(NullPointerException e){} |
1291 |
> |
} catch (NullPointerException success) {} |
1292 |
|
} |
1293 |
|
|
1294 |
|
/** |
1295 |
|
* A deserialized map equals original |
1296 |
|
*/ |
1297 |
< |
public void testDescendingSerialization() { |
1297 |
> |
public void testDescendingSerialization() throws Exception { |
1298 |
|
ConcurrentNavigableMap q = dmap5(); |
1299 |
|
|
1300 |
< |
try { |
1301 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1302 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1303 |
< |
out.writeObject(q); |
1304 |
< |
out.close(); |
1305 |
< |
|
1306 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1307 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1308 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1309 |
< |
assertEquals(q.size(), r.size()); |
1310 |
< |
assertTrue(q.equals(r)); |
1320 |
< |
assertTrue(r.equals(q)); |
1321 |
< |
} catch(Exception e){ |
1322 |
< |
e.printStackTrace(); |
1323 |
< |
unexpectedException(); |
1324 |
< |
} |
1300 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1301 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1302 |
> |
out.writeObject(q); |
1303 |
> |
out.close(); |
1304 |
> |
|
1305 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1306 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1307 |
> |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1308 |
> |
assertEquals(q.size(), r.size()); |
1309 |
> |
assertTrue(q.equals(r)); |
1310 |
> |
assertTrue(r.equals(q)); |
1311 |
|
} |
1312 |
|
|
1313 |
|
|
1328 |
– |
|
1314 |
|
/** |
1315 |
|
* subMap returns map with keys in requested range |
1316 |
|
*/ |