1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
7 |
> |
import java.util.ArrayList; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.Collection; |
10 |
> |
import java.util.Iterator; |
11 |
> |
import java.util.Map; |
12 |
> |
import java.util.NavigableMap; |
13 |
> |
import java.util.Set; |
14 |
> |
import java.util.SortedMap; |
15 |
> |
import java.util.concurrent.ConcurrentNavigableMap; |
16 |
> |
import java.util.concurrent.ConcurrentSkipListMap; |
17 |
> |
|
18 |
> |
import junit.framework.Test; |
19 |
> |
import junit.framework.TestSuite; |
20 |
|
|
21 |
|
public class ConcurrentSkipListSubMapTest extends JSR166TestCase { |
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run (suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
public static Test suite() { |
26 |
|
return new TestSuite(ConcurrentSkipListSubMapTest.class); |
27 |
|
} |
28 |
|
|
29 |
|
/** |
30 |
< |
* Create a map from Integers 1-5 to Strings "A"-"E". |
30 |
> |
* Returns a new map from Integers 1-5 to Strings "A"-"E". |
31 |
|
*/ |
32 |
|
private static ConcurrentNavigableMap map5() { |
33 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
45 |
|
} |
46 |
|
|
47 |
|
/** |
48 |
< |
* Create a map from Integers -5 to -1 to Strings "A"-"E". |
48 |
> |
* Returns a new map from Integers -5 to -1 to Strings "A"-"E". |
49 |
|
*/ |
50 |
|
private static ConcurrentNavigableMap dmap5() { |
51 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
73 |
|
} |
74 |
|
|
75 |
|
/** |
76 |
< |
* clear removes all pairs |
76 |
> |
* clear removes all pairs |
77 |
|
*/ |
78 |
|
public void testClear() { |
79 |
|
ConcurrentNavigableMap map = map5(); |
80 |
|
map.clear(); |
81 |
< |
assertEquals(map.size(), 0); |
81 |
> |
assertEquals(0, map.size()); |
82 |
|
} |
83 |
|
|
75 |
– |
|
84 |
|
/** |
85 |
< |
* Maps with same contents are equal |
85 |
> |
* Maps with same contents are equal |
86 |
|
*/ |
87 |
|
public void testEquals() { |
88 |
|
ConcurrentNavigableMap map1 = map5(); |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
< |
* containsKey returns true for contained key |
98 |
> |
* containsKey returns true for contained key |
99 |
|
*/ |
100 |
|
public void testContainsKey() { |
101 |
|
ConcurrentNavigableMap map = map5(); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
< |
* containsValue returns true for held values |
107 |
> |
* containsValue returns true for held values |
108 |
|
*/ |
109 |
|
public void testContainsValue() { |
110 |
|
ConcurrentNavigableMap map = map5(); |
113 |
|
} |
114 |
|
|
115 |
|
/** |
116 |
< |
* get returns the correct element at the given key, |
117 |
< |
* or null if not present |
116 |
> |
* get returns the correct element at the given key, |
117 |
> |
* or null if not present |
118 |
|
*/ |
119 |
|
public void testGet() { |
120 |
|
ConcurrentNavigableMap map = map5(); |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
< |
* isEmpty is true of empty map and false for non-empty |
127 |
> |
* isEmpty is true of empty map and false for non-empty |
128 |
|
*/ |
129 |
|
public void testIsEmpty() { |
130 |
|
ConcurrentNavigableMap empty = map0(); |
134 |
|
} |
135 |
|
|
136 |
|
/** |
137 |
< |
* firstKey returns first key |
137 |
> |
* firstKey returns first key |
138 |
|
*/ |
139 |
|
public void testFirstKey() { |
140 |
|
ConcurrentNavigableMap map = map5(); |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
< |
* lastKey returns last key |
145 |
> |
* lastKey returns last key |
146 |
|
*/ |
147 |
|
public void testLastKey() { |
148 |
|
ConcurrentNavigableMap map = map5(); |
149 |
|
assertEquals(five, map.lastKey()); |
150 |
|
} |
151 |
|
|
144 |
– |
|
152 |
|
/** |
153 |
< |
* keySet returns a Set containing all the keys |
153 |
> |
* keySet returns a Set containing all the keys |
154 |
|
*/ |
155 |
|
public void testKeySet() { |
156 |
|
ConcurrentNavigableMap map = map5(); |
164 |
|
} |
165 |
|
|
166 |
|
/** |
167 |
< |
* keySet is ordered |
167 |
> |
* keySet is ordered |
168 |
|
*/ |
169 |
|
public void testKeySetOrder() { |
170 |
|
ConcurrentNavigableMap map = map5(); |
194 |
|
} |
195 |
|
|
196 |
|
/** |
197 |
< |
* keySet.toArray returns contains all keys |
197 |
> |
* keySet.toArray returns contains all keys |
198 |
|
*/ |
199 |
|
public void testKeySetToArray() { |
200 |
|
ConcurrentNavigableMap map = map5(); |
207 |
|
} |
208 |
|
|
209 |
|
/** |
210 |
< |
* descendingkeySet.toArray returns contains all keys |
210 |
> |
* descendingkeySet.toArray returns contains all keys |
211 |
|
*/ |
212 |
|
public void testDescendingKeySetToArray() { |
213 |
|
ConcurrentNavigableMap map = map5(); |
220 |
|
} |
221 |
|
|
222 |
|
/** |
223 |
< |
* Values.toArray contains all values |
223 |
> |
* Values.toArray contains all values |
224 |
|
*/ |
225 |
|
public void testValuesToArray() { |
226 |
|
ConcurrentNavigableMap map = map5(); |
235 |
|
assertTrue(s.contains("E")); |
236 |
|
} |
237 |
|
|
231 |
– |
|
238 |
|
/** |
239 |
|
* entrySet contains all pairs |
240 |
|
*/ |
255 |
|
} |
256 |
|
|
257 |
|
/** |
258 |
< |
* putAll adds all key-value pairs from the given map |
258 |
> |
* putAll adds all key-value pairs from the given map |
259 |
|
*/ |
260 |
|
public void testPutAll() { |
261 |
|
ConcurrentNavigableMap empty = map0(); |
270 |
|
} |
271 |
|
|
272 |
|
/** |
273 |
< |
* putIfAbsent works when the given key is not present |
273 |
> |
* putIfAbsent works when the given key is not present |
274 |
|
*/ |
275 |
|
public void testPutIfAbsent() { |
276 |
|
ConcurrentNavigableMap map = map5(); |
279 |
|
} |
280 |
|
|
281 |
|
/** |
282 |
< |
* putIfAbsent does not add the pair if the key is already present |
282 |
> |
* putIfAbsent does not add the pair if the key is already present |
283 |
|
*/ |
284 |
|
public void testPutIfAbsent2() { |
285 |
|
ConcurrentNavigableMap map = map5(); |
287 |
|
} |
288 |
|
|
289 |
|
/** |
290 |
< |
* replace fails when the given key is not present |
290 |
> |
* replace fails when the given key is not present |
291 |
|
*/ |
292 |
|
public void testReplace() { |
293 |
|
ConcurrentNavigableMap map = map5(); |
296 |
|
} |
297 |
|
|
298 |
|
/** |
299 |
< |
* replace succeeds if the key is already present |
299 |
> |
* replace succeeds if the key is already present |
300 |
|
*/ |
301 |
|
public void testReplace2() { |
302 |
|
ConcurrentNavigableMap map = map5(); |
304 |
|
assertEquals("Z", map.get(one)); |
305 |
|
} |
306 |
|
|
301 |
– |
|
307 |
|
/** |
308 |
|
* replace value fails when the given key not mapped to expected value |
309 |
|
*/ |
324 |
|
assertEquals("Z", map.get(one)); |
325 |
|
} |
326 |
|
|
322 |
– |
|
327 |
|
/** |
328 |
< |
* remove removes the correct key-value pair from the map |
328 |
> |
* remove removes the correct key-value pair from the map |
329 |
|
*/ |
330 |
|
public void testRemove() { |
331 |
|
ConcurrentNavigableMap map = map5(); |
347 |
|
map.remove(four, "A"); |
348 |
|
assertEquals(4, map.size()); |
349 |
|
assertTrue(map.containsKey(four)); |
346 |
– |
|
350 |
|
} |
351 |
|
|
352 |
|
/** |
365 |
|
|
366 |
|
Map.Entry e4 = map.lowerEntry(zero); |
367 |
|
assertNull(e4); |
365 |
– |
|
368 |
|
} |
369 |
|
|
370 |
|
/** |
383 |
|
|
384 |
|
Map.Entry e4 = map.higherEntry(six); |
385 |
|
assertNull(e4); |
384 |
– |
|
386 |
|
} |
387 |
|
|
388 |
|
/** |
401 |
|
|
402 |
|
Map.Entry e4 = map.floorEntry(zero); |
403 |
|
assertNull(e4); |
403 |
– |
|
404 |
|
} |
405 |
|
|
406 |
|
/** |
419 |
|
|
420 |
|
Map.Entry e4 = map.ceilingEntry(six); |
421 |
|
assertNull(e4); |
422 |
– |
|
422 |
|
} |
423 |
|
|
424 |
|
/** |
443 |
|
try { |
444 |
|
e.setValue("A"); |
445 |
|
shouldThrow(); |
446 |
< |
} catch (Exception ok) { |
448 |
< |
} |
446 |
> |
} catch (UnsupportedOperationException success) {} |
447 |
|
e = map.pollFirstEntry(); |
448 |
|
assertNull(e); |
449 |
|
} |
470 |
|
try { |
471 |
|
e.setValue("E"); |
472 |
|
shouldThrow(); |
473 |
< |
} catch (Exception ok) { |
476 |
< |
} |
473 |
> |
} catch (UnsupportedOperationException success) {} |
474 |
|
e = map.pollLastEntry(); |
475 |
|
assertNull(e); |
476 |
|
} |
477 |
|
|
478 |
|
/** |
479 |
< |
* size returns the correct values |
479 |
> |
* size returns the correct values |
480 |
|
*/ |
481 |
|
public void testSize() { |
482 |
|
ConcurrentNavigableMap map = map5(); |
492 |
|
ConcurrentNavigableMap map = map5(); |
493 |
|
String s = map.toString(); |
494 |
|
for (int i = 1; i <= 5; ++i) { |
495 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
495 |
> |
assertTrue(s.contains(String.valueOf(i))); |
496 |
|
} |
497 |
|
} |
498 |
|
|
506 |
|
ConcurrentNavigableMap c = map5(); |
507 |
|
c.get(null); |
508 |
|
shouldThrow(); |
509 |
< |
} catch (NullPointerException e) {} |
509 |
> |
} catch (NullPointerException success) {} |
510 |
|
} |
511 |
|
|
512 |
|
/** |
517 |
|
ConcurrentNavigableMap c = map5(); |
518 |
|
c.containsKey(null); |
519 |
|
shouldThrow(); |
520 |
< |
} catch (NullPointerException e) {} |
520 |
> |
} catch (NullPointerException success) {} |
521 |
|
} |
522 |
|
|
523 |
|
/** |
528 |
|
ConcurrentNavigableMap c = map0(); |
529 |
|
c.containsValue(null); |
530 |
|
shouldThrow(); |
531 |
< |
} catch (NullPointerException e) {} |
531 |
> |
} catch (NullPointerException success) {} |
532 |
|
} |
533 |
|
|
537 |
– |
|
534 |
|
/** |
535 |
|
* put(null,x) throws NPE |
536 |
|
*/ |
539 |
|
ConcurrentNavigableMap c = map5(); |
540 |
|
c.put(null, "whatever"); |
541 |
|
shouldThrow(); |
542 |
< |
} catch (NullPointerException e) {} |
542 |
> |
} catch (NullPointerException success) {} |
543 |
|
} |
544 |
|
|
545 |
|
/** |
550 |
|
ConcurrentNavigableMap c = map5(); |
551 |
|
c.putIfAbsent(null, "whatever"); |
552 |
|
shouldThrow(); |
553 |
< |
} catch (NullPointerException e) {} |
553 |
> |
} catch (NullPointerException success) {} |
554 |
|
} |
555 |
|
|
556 |
|
/** |
561 |
|
ConcurrentNavigableMap c = map5(); |
562 |
|
c.replace(null, "whatever"); |
563 |
|
shouldThrow(); |
564 |
< |
} catch (NullPointerException e) {} |
564 |
> |
} catch (NullPointerException success) {} |
565 |
|
} |
566 |
|
|
567 |
|
/** |
572 |
|
ConcurrentNavigableMap c = map5(); |
573 |
|
c.replace(null, one, "whatever"); |
574 |
|
shouldThrow(); |
575 |
< |
} catch (NullPointerException e) {} |
575 |
> |
} catch (NullPointerException success) {} |
576 |
|
} |
577 |
|
|
578 |
|
/** |
583 |
|
ConcurrentNavigableMap c = map5(); |
584 |
|
c.remove(null); |
585 |
|
shouldThrow(); |
586 |
< |
} catch (NullPointerException e) {} |
586 |
> |
} catch (NullPointerException success) {} |
587 |
|
} |
588 |
|
|
589 |
|
/** |
594 |
|
ConcurrentNavigableMap c = map5(); |
595 |
|
c.remove(null, "whatever"); |
596 |
|
shouldThrow(); |
597 |
< |
} catch (NullPointerException e) {} |
597 |
> |
} catch (NullPointerException success) {} |
598 |
|
} |
599 |
|
|
600 |
|
/** |
601 |
|
* A deserialized map equals original |
602 |
|
*/ |
603 |
|
public void testSerialization() throws Exception { |
604 |
< |
ConcurrentNavigableMap q = map5(); |
604 |
> |
NavigableMap x = map5(); |
605 |
> |
NavigableMap y = serialClone(x); |
606 |
|
|
607 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
608 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
609 |
< |
out.writeObject(q); |
610 |
< |
out.close(); |
611 |
< |
|
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)); |
607 |
> |
assertNotSame(x, y); |
608 |
> |
assertEquals(x.size(), y.size()); |
609 |
> |
assertEquals(x.toString(), y.toString()); |
610 |
> |
assertEquals(x, y); |
611 |
> |
assertEquals(y, x); |
612 |
|
} |
613 |
|
|
623 |
– |
|
624 |
– |
|
614 |
|
/** |
615 |
|
* subMap returns map with keys in requested range |
616 |
|
*/ |
640 |
|
assertEquals(1, sm.size()); |
641 |
|
assertEquals(three, sm.firstKey()); |
642 |
|
assertEquals(three, sm.lastKey()); |
643 |
< |
assertTrue(sm.remove(three) != null); |
643 |
> |
assertEquals("C", sm.remove(three)); |
644 |
|
assertTrue(sm.isEmpty()); |
645 |
|
assertEquals(3, map.size()); |
646 |
|
} |
668 |
|
assertEquals(4, map.size()); |
669 |
|
assertEquals(0, sm.size()); |
670 |
|
assertTrue(sm.isEmpty()); |
671 |
< |
assertTrue(sm.remove(three) == null); |
671 |
> |
assertSame(sm.remove(three), null); |
672 |
|
assertEquals(4, map.size()); |
673 |
|
} |
674 |
|
|
740 |
|
SortedMap ssm = sm.tailMap(four); |
741 |
|
assertEquals(four, ssm.firstKey()); |
742 |
|
assertEquals(five, ssm.lastKey()); |
743 |
< |
assertTrue(ssm.remove(four) != null); |
743 |
> |
assertEquals("D", ssm.remove(four)); |
744 |
|
assertEquals(1, ssm.size()); |
745 |
|
assertEquals(3, sm.size()); |
746 |
|
assertEquals(4, map.size()); |
747 |
|
} |
748 |
|
|
749 |
|
/** |
750 |
< |
* clear removes all pairs |
750 |
> |
* clear removes all pairs |
751 |
|
*/ |
752 |
|
public void testDescendingClear() { |
753 |
|
ConcurrentNavigableMap map = dmap5(); |
754 |
|
map.clear(); |
755 |
< |
assertEquals(map.size(), 0); |
755 |
> |
assertEquals(0, map.size()); |
756 |
|
} |
757 |
|
|
769 |
– |
|
758 |
|
/** |
759 |
< |
* Maps with same contents are equal |
759 |
> |
* Maps with same contents are equal |
760 |
|
*/ |
761 |
|
public void testDescendingEquals() { |
762 |
|
ConcurrentNavigableMap map1 = dmap5(); |
769 |
|
} |
770 |
|
|
771 |
|
/** |
772 |
< |
* containsKey returns true for contained key |
772 |
> |
* containsKey returns true for contained key |
773 |
|
*/ |
774 |
|
public void testDescendingContainsKey() { |
775 |
|
ConcurrentNavigableMap map = dmap5(); |
778 |
|
} |
779 |
|
|
780 |
|
/** |
781 |
< |
* containsValue returns true for held values |
781 |
> |
* containsValue returns true for held values |
782 |
|
*/ |
783 |
|
public void testDescendingContainsValue() { |
784 |
|
ConcurrentNavigableMap map = dmap5(); |
787 |
|
} |
788 |
|
|
789 |
|
/** |
790 |
< |
* get returns the correct element at the given key, |
791 |
< |
* or null if not present |
790 |
> |
* get returns the correct element at the given key, |
791 |
> |
* or null if not present |
792 |
|
*/ |
793 |
|
public void testDescendingGet() { |
794 |
|
ConcurrentNavigableMap map = dmap5(); |
798 |
|
} |
799 |
|
|
800 |
|
/** |
801 |
< |
* isEmpty is true of empty map and false for non-empty |
801 |
> |
* isEmpty is true of empty map and false for non-empty |
802 |
|
*/ |
803 |
|
public void testDescendingIsEmpty() { |
804 |
|
ConcurrentNavigableMap empty = dmap0(); |
808 |
|
} |
809 |
|
|
810 |
|
/** |
811 |
< |
* firstKey returns first key |
811 |
> |
* firstKey returns first key |
812 |
|
*/ |
813 |
|
public void testDescendingFirstKey() { |
814 |
|
ConcurrentNavigableMap map = dmap5(); |
816 |
|
} |
817 |
|
|
818 |
|
/** |
819 |
< |
* lastKey returns last key |
819 |
> |
* lastKey returns last key |
820 |
|
*/ |
821 |
|
public void testDescendingLastKey() { |
822 |
|
ConcurrentNavigableMap map = dmap5(); |
823 |
|
assertEquals(m5, map.lastKey()); |
824 |
|
} |
825 |
|
|
838 |
– |
|
826 |
|
/** |
827 |
< |
* keySet returns a Set containing all the keys |
827 |
> |
* keySet returns a Set containing all the keys |
828 |
|
*/ |
829 |
|
public void testDescendingKeySet() { |
830 |
|
ConcurrentNavigableMap map = dmap5(); |
838 |
|
} |
839 |
|
|
840 |
|
/** |
841 |
< |
* keySet is ordered |
841 |
> |
* keySet is ordered |
842 |
|
*/ |
843 |
|
public void testDescendingKeySetOrder() { |
844 |
|
ConcurrentNavigableMap map = dmap5(); |
868 |
|
} |
869 |
|
|
870 |
|
/** |
871 |
< |
* keySet.toArray returns contains all keys |
871 |
> |
* keySet.toArray returns contains all keys |
872 |
|
*/ |
873 |
|
public void testDescendingAscendingKeySetToArray() { |
874 |
|
ConcurrentNavigableMap map = dmap5(); |
881 |
|
} |
882 |
|
|
883 |
|
/** |
884 |
< |
* descendingkeySet.toArray returns contains all keys |
884 |
> |
* descendingkeySet.toArray returns contains all keys |
885 |
|
*/ |
886 |
|
public void testDescendingDescendingKeySetToArray() { |
887 |
|
ConcurrentNavigableMap map = dmap5(); |
894 |
|
} |
895 |
|
|
896 |
|
/** |
897 |
< |
* Values.toArray contains all values |
897 |
> |
* Values.toArray contains all values |
898 |
|
*/ |
899 |
|
public void testDescendingValuesToArray() { |
900 |
|
ConcurrentNavigableMap map = dmap5(); |
909 |
|
assertTrue(s.contains("E")); |
910 |
|
} |
911 |
|
|
925 |
– |
|
912 |
|
/** |
913 |
|
* entrySet contains all pairs |
914 |
|
*/ |
929 |
|
} |
930 |
|
|
931 |
|
/** |
932 |
< |
* putAll adds all key-value pairs from the given map |
932 |
> |
* putAll adds all key-value pairs from the given map |
933 |
|
*/ |
934 |
|
public void testDescendingPutAll() { |
935 |
|
ConcurrentNavigableMap empty = dmap0(); |
944 |
|
} |
945 |
|
|
946 |
|
/** |
947 |
< |
* putIfAbsent works when the given key is not present |
947 |
> |
* putIfAbsent works when the given key is not present |
948 |
|
*/ |
949 |
|
public void testDescendingPutIfAbsent() { |
950 |
|
ConcurrentNavigableMap map = dmap5(); |
953 |
|
} |
954 |
|
|
955 |
|
/** |
956 |
< |
* putIfAbsent does not add the pair if the key is already present |
956 |
> |
* putIfAbsent does not add the pair if the key is already present |
957 |
|
*/ |
958 |
|
public void testDescendingPutIfAbsent2() { |
959 |
|
ConcurrentNavigableMap map = dmap5(); |
961 |
|
} |
962 |
|
|
963 |
|
/** |
964 |
< |
* replace fails when the given key is not present |
964 |
> |
* replace fails when the given key is not present |
965 |
|
*/ |
966 |
|
public void testDescendingReplace() { |
967 |
|
ConcurrentNavigableMap map = dmap5(); |
970 |
|
} |
971 |
|
|
972 |
|
/** |
973 |
< |
* replace succeeds if the key is already present |
973 |
> |
* replace succeeds if the key is already present |
974 |
|
*/ |
975 |
|
public void testDescendingReplace2() { |
976 |
|
ConcurrentNavigableMap map = dmap5(); |
978 |
|
assertEquals("Z", map.get(m1)); |
979 |
|
} |
980 |
|
|
995 |
– |
|
981 |
|
/** |
982 |
|
* replace value fails when the given key not mapped to expected value |
983 |
|
*/ |
998 |
|
assertEquals("Z", map.get(m1)); |
999 |
|
} |
1000 |
|
|
1016 |
– |
|
1001 |
|
/** |
1002 |
< |
* remove removes the correct key-value pair from the map |
1002 |
> |
* remove removes the correct key-value pair from the map |
1003 |
|
*/ |
1004 |
|
public void testDescendingRemove() { |
1005 |
|
ConcurrentNavigableMap map = dmap5(); |
1021 |
|
map.remove(m4, "A"); |
1022 |
|
assertEquals(4, map.size()); |
1023 |
|
assertTrue(map.containsKey(m4)); |
1040 |
– |
|
1024 |
|
} |
1025 |
|
|
1026 |
|
/** |
1039 |
|
|
1040 |
|
Map.Entry e4 = map.lowerEntry(zero); |
1041 |
|
assertNull(e4); |
1059 |
– |
|
1042 |
|
} |
1043 |
|
|
1044 |
|
/** |
1057 |
|
|
1058 |
|
Map.Entry e4 = map.higherEntry(m6); |
1059 |
|
assertNull(e4); |
1078 |
– |
|
1060 |
|
} |
1061 |
|
|
1062 |
|
/** |
1075 |
|
|
1076 |
|
Map.Entry e4 = map.floorEntry(zero); |
1077 |
|
assertNull(e4); |
1097 |
– |
|
1078 |
|
} |
1079 |
|
|
1080 |
|
/** |
1093 |
|
|
1094 |
|
Map.Entry e4 = map.ceilingEntry(m6); |
1095 |
|
assertNull(e4); |
1116 |
– |
|
1096 |
|
} |
1097 |
|
|
1098 |
|
/** |
1117 |
|
try { |
1118 |
|
e.setValue("A"); |
1119 |
|
shouldThrow(); |
1120 |
< |
} catch (Exception ok) { |
1142 |
< |
} |
1120 |
> |
} catch (UnsupportedOperationException success) {} |
1121 |
|
e = map.pollFirstEntry(); |
1122 |
|
assertNull(e); |
1123 |
|
} |
1144 |
|
try { |
1145 |
|
e.setValue("E"); |
1146 |
|
shouldThrow(); |
1147 |
< |
} catch (Exception ok) { |
1170 |
< |
} |
1147 |
> |
} catch (UnsupportedOperationException success) {} |
1148 |
|
e = map.pollLastEntry(); |
1149 |
|
assertNull(e); |
1150 |
|
} |
1151 |
|
|
1152 |
|
/** |
1153 |
< |
* size returns the correct values |
1153 |
> |
* size returns the correct values |
1154 |
|
*/ |
1155 |
|
public void testDescendingSize() { |
1156 |
|
ConcurrentNavigableMap map = dmap5(); |
1166 |
|
ConcurrentNavigableMap map = dmap5(); |
1167 |
|
String s = map.toString(); |
1168 |
|
for (int i = 1; i <= 5; ++i) { |
1169 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
1169 |
> |
assertTrue(s.contains(String.valueOf(i))); |
1170 |
|
} |
1171 |
|
} |
1172 |
|
|
1173 |
|
// Exception testDescendings |
1174 |
|
|
1175 |
|
/** |
1176 |
< |
* get(null) of nm1mpty map throws NPE |
1176 |
> |
* get(null) of empty map throws NPE |
1177 |
|
*/ |
1178 |
|
public void testDescendingGet_NullPointerException() { |
1179 |
|
try { |
1180 |
|
ConcurrentNavigableMap c = dmap5(); |
1181 |
|
c.get(null); |
1182 |
|
shouldThrow(); |
1183 |
< |
} catch (NullPointerException e) {} |
1183 |
> |
} catch (NullPointerException success) {} |
1184 |
|
} |
1185 |
|
|
1186 |
|
/** |
1187 |
< |
* containsKey(null) of nm1mpty map throws NPE |
1187 |
> |
* containsKey(null) of empty map throws NPE |
1188 |
|
*/ |
1189 |
|
public void testDescendingContainsKey_NullPointerException() { |
1190 |
|
try { |
1191 |
|
ConcurrentNavigableMap c = dmap5(); |
1192 |
|
c.containsKey(null); |
1193 |
|
shouldThrow(); |
1194 |
< |
} catch (NullPointerException e) {} |
1194 |
> |
} catch (NullPointerException success) {} |
1195 |
|
} |
1196 |
|
|
1197 |
|
/** |
1202 |
|
ConcurrentNavigableMap c = dmap0(); |
1203 |
|
c.containsValue(null); |
1204 |
|
shouldThrow(); |
1205 |
< |
} catch (NullPointerException e) {} |
1205 |
> |
} catch (NullPointerException success) {} |
1206 |
|
} |
1207 |
|
|
1231 |
– |
|
1208 |
|
/** |
1209 |
|
* put(null,x) throws NPE |
1210 |
|
*/ |
1213 |
|
ConcurrentNavigableMap c = dmap5(); |
1214 |
|
c.put(null, "whatever"); |
1215 |
|
shouldThrow(); |
1216 |
< |
} catch (NullPointerException e) {} |
1216 |
> |
} catch (NullPointerException success) {} |
1217 |
|
} |
1218 |
|
|
1219 |
|
/** |
1224 |
|
ConcurrentNavigableMap c = dmap5(); |
1225 |
|
c.putIfAbsent(null, "whatever"); |
1226 |
|
shouldThrow(); |
1227 |
< |
} catch (NullPointerException e) {} |
1227 |
> |
} catch (NullPointerException success) {} |
1228 |
|
} |
1229 |
|
|
1230 |
|
/** |
1235 |
|
ConcurrentNavigableMap c = dmap5(); |
1236 |
|
c.replace(null, "whatever"); |
1237 |
|
shouldThrow(); |
1238 |
< |
} catch (NullPointerException e) {} |
1238 |
> |
} catch (NullPointerException success) {} |
1239 |
|
} |
1240 |
|
|
1241 |
|
/** |
1246 |
|
ConcurrentNavigableMap c = dmap5(); |
1247 |
|
c.replace(null, m1, "whatever"); |
1248 |
|
shouldThrow(); |
1249 |
< |
} catch (NullPointerException e) {} |
1249 |
> |
} catch (NullPointerException success) {} |
1250 |
|
} |
1251 |
|
|
1252 |
|
/** |
1257 |
|
ConcurrentNavigableMap c = dmap5(); |
1258 |
|
c.remove(null); |
1259 |
|
shouldThrow(); |
1260 |
< |
} catch (NullPointerException e) {} |
1260 |
> |
} catch (NullPointerException success) {} |
1261 |
|
} |
1262 |
|
|
1263 |
|
/** |
1268 |
|
ConcurrentNavigableMap c = dmap5(); |
1269 |
|
c.remove(null, "whatever"); |
1270 |
|
shouldThrow(); |
1271 |
< |
} catch (NullPointerException e) {} |
1271 |
> |
} catch (NullPointerException success) {} |
1272 |
|
} |
1273 |
|
|
1274 |
|
/** |
1275 |
|
* A deserialized map equals original |
1276 |
|
*/ |
1277 |
|
public void testDescendingSerialization() throws Exception { |
1278 |
< |
ConcurrentNavigableMap q = dmap5(); |
1278 |
> |
NavigableMap x = dmap5(); |
1279 |
> |
NavigableMap y = serialClone(x); |
1280 |
|
|
1281 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1282 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1283 |
< |
out.writeObject(q); |
1284 |
< |
out.close(); |
1285 |
< |
|
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)); |
1281 |
> |
assertNotSame(x, y); |
1282 |
> |
assertEquals(x.size(), y.size()); |
1283 |
> |
assertEquals(x.toString(), y.toString()); |
1284 |
> |
assertEquals(x, y); |
1285 |
> |
assertEquals(y, x); |
1286 |
|
} |
1287 |
|
|
1317 |
– |
|
1288 |
|
/** |
1289 |
|
* subMap returns map with keys in requested range |
1290 |
|
*/ |
1314 |
|
assertEquals(1, sm.size()); |
1315 |
|
assertEquals(m3, sm.firstKey()); |
1316 |
|
assertEquals(m3, sm.lastKey()); |
1317 |
< |
assertTrue(sm.remove(m3) != null); |
1317 |
> |
assertEquals("C", sm.remove(m3)); |
1318 |
|
assertTrue(sm.isEmpty()); |
1319 |
|
assertEquals(3, map.size()); |
1320 |
|
} |
1342 |
|
assertEquals(4, map.size()); |
1343 |
|
assertEquals(0, sm.size()); |
1344 |
|
assertTrue(sm.isEmpty()); |
1345 |
< |
assertTrue(sm.remove(m3) == null); |
1345 |
> |
assertSame(sm.remove(m3), null); |
1346 |
|
assertEquals(4, map.size()); |
1347 |
|
} |
1348 |
|
|
1414 |
|
SortedMap ssm = sm.tailMap(m4); |
1415 |
|
assertEquals(m4, ssm.firstKey()); |
1416 |
|
assertEquals(m5, ssm.lastKey()); |
1417 |
< |
assertTrue(ssm.remove(m4) != null); |
1417 |
> |
assertEquals("D", ssm.remove(m4)); |
1418 |
|
assertEquals(1, ssm.size()); |
1419 |
|
assertEquals(3, sm.size()); |
1420 |
|
assertEquals(4, map.size()); |