ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java (file contents):
Revision 1.7 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.24 by jsr166, Wed Dec 31 19:05:42 2014 UTC

# Line 1 | Line 1
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 >        junit.textui.TestRunner.run(suite());
24      }
25      public static Test suite() {
26 <        return new TestSuite(ConcurrentSkipListSubMapTest.class);
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();
33 >        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
34          assertTrue(map.isEmpty());
35 <        map.put(zero, "Z");
36 <        map.put(one, "A");
37 <        map.put(five, "E");
38 <        map.put(three, "C");
39 <        map.put(two, "B");
40 <        map.put(four, "D");
41 <        map.put(seven, "F");
35 >        map.put(zero, "Z");
36 >        map.put(one, "A");
37 >        map.put(five, "E");
38 >        map.put(three, "C");
39 >        map.put(two, "B");
40 >        map.put(four, "D");
41 >        map.put(seven, "F");
42          assertFalse(map.isEmpty());
43          assertEquals(7, map.size());
44          return map.subMap(one, true, seven, false);
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();
51 >        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
52          assertTrue(map.isEmpty());
53 <        map.put(m1, "A");
54 <        map.put(m5, "E");
55 <        map.put(m3, "C");
56 <        map.put(m2, "B");
57 <        map.put(m4, "D");
53 >        map.put(m1, "A");
54 >        map.put(m5, "E");
55 >        map.put(m3, "C");
56 >        map.put(m2, "B");
57 >        map.put(m4, "D");
58          assertFalse(map.isEmpty());
59          assertEquals(5, map.size());
60 <        return map.descendingMap();
60 >        return map.descendingMap();
61      }
62  
63      private static ConcurrentNavigableMap map0() {
64 <        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
64 >        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
65          assertTrue(map.isEmpty());
66          return map.tailMap(one, true);
67      }
68  
69      private static ConcurrentNavigableMap dmap0() {
70 <        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
70 >        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
71          assertTrue(map.isEmpty());
72          return map;
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);
80 >        map.clear();
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();
89          ConcurrentNavigableMap map2 = map5();
90          assertEquals(map1, map2);
91          assertEquals(map2, map1);
92 <        map1.clear();
92 >        map1.clear();
93          assertFalse(map1.equals(map2));
94          assertFalse(map2.equals(map1));
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();
102 <        assertTrue(map.containsKey(one));
102 >        assertTrue(map.containsKey(one));
103          assertFalse(map.containsKey(zero));
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();
111 <        assertTrue(map.containsValue("A"));
111 >        assertTrue(map.containsValue("A"));
112          assertFalse(map.containsValue("Z"));
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();
121 <        assertEquals("A", (String)map.get(one));
121 >        assertEquals("A", (String)map.get(one));
122          ConcurrentNavigableMap empty = map0();
123          assertNull(empty.get(one));
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();
131          ConcurrentNavigableMap map = map5();
132 <        assertTrue(empty.isEmpty());
132 >        assertTrue(empty.isEmpty());
133          assertFalse(map.isEmpty());
134      }
135  
136      /**
137 <     *   firstKey returns first key
137 >     * firstKey returns first key
138       */
139      public void testFirstKey() {
140          ConcurrentNavigableMap map = map5();
141 <        assertEquals(one, map.firstKey());
141 >        assertEquals(one, map.firstKey());
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());
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();
157 <        Set s = map.keySet();
158 <        assertEquals(5, s.size());
159 <        assertTrue(s.contains(one));
160 <        assertTrue(s.contains(two));
161 <        assertTrue(s.contains(three));
162 <        assertTrue(s.contains(four));
163 <        assertTrue(s.contains(five));
157 >        Set s = map.keySet();
158 >        assertEquals(5, s.size());
159 >        assertTrue(s.contains(one));
160 >        assertTrue(s.contains(two));
161 >        assertTrue(s.contains(three));
162 >        assertTrue(s.contains(four));
163 >        assertTrue(s.contains(five));
164      }
165  
166      /**
167 <     *   keySet is ordered
167 >     * keySet is ordered
168       */
169      public void testKeySetOrder() {
170          ConcurrentNavigableMap map = map5();
171 <        Set s = map.keySet();
171 >        Set s = map.keySet();
172          Iterator i = s.iterator();
173          Integer last = (Integer)i.next();
174          assertEquals(last, one);
# Line 177 | Line 184 | public class ConcurrentSkipListSubMapTes
184       */
185      public void testValues() {
186          ConcurrentNavigableMap map = map5();
187 <        Collection s = map.values();
188 <        assertEquals(5, s.size());
189 <        assertTrue(s.contains("A"));
190 <        assertTrue(s.contains("B"));
191 <        assertTrue(s.contains("C"));
192 <        assertTrue(s.contains("D"));
193 <        assertTrue(s.contains("E"));
187 >        Collection s = map.values();
188 >        assertEquals(5, s.size());
189 >        assertTrue(s.contains("A"));
190 >        assertTrue(s.contains("B"));
191 >        assertTrue(s.contains("C"));
192 >        assertTrue(s.contains("D"));
193 >        assertTrue(s.contains("E"));
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();
201 <        Set s = map.keySet();
201 >        Set s = map.keySet();
202          Object[] ar = s.toArray();
203          assertTrue(s.containsAll(Arrays.asList(ar)));
204 <        assertEquals(5, ar.length);
204 >        assertEquals(5, ar.length);
205          ar[0] = m10;
206          assertFalse(s.containsAll(Arrays.asList(ar)));
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();
214 <        Set s = map.descendingKeySet();
214 >        Set s = map.descendingKeySet();
215          Object[] ar = s.toArray();
216 <        assertEquals(5, ar.length);
216 >        assertEquals(5, ar.length);
217          assertTrue(s.containsAll(Arrays.asList(ar)));
218          ar[0] = m10;
219          assertFalse(s.containsAll(Arrays.asList(ar)));
220      }
221  
222      /**
223 <     *  Values.toArray contains all values
223 >     * Values.toArray contains all values
224       */
225      public void testValuesToArray() {
226          ConcurrentNavigableMap map = map5();
227 <        Collection v = map.values();
227 >        Collection v = map.values();
228          Object[] ar = v.toArray();
229          ArrayList s = new ArrayList(Arrays.asList(ar));
230 <        assertEquals(5, ar.length);
231 <        assertTrue(s.contains("A"));
232 <        assertTrue(s.contains("B"));
233 <        assertTrue(s.contains("C"));
234 <        assertTrue(s.contains("D"));
235 <        assertTrue(s.contains("E"));
230 >        assertEquals(5, ar.length);
231 >        assertTrue(s.contains("A"));
232 >        assertTrue(s.contains("B"));
233 >        assertTrue(s.contains("C"));
234 >        assertTrue(s.contains("D"));
235 >        assertTrue(s.contains("E"));
236      }
237  
231
238      /**
239       * entrySet contains all pairs
240       */
241      public void testEntrySet() {
242          ConcurrentNavigableMap map = map5();
243 <        Set s = map.entrySet();
244 <        assertEquals(5, s.size());
243 >        Set s = map.entrySet();
244 >        assertEquals(5, s.size());
245          Iterator it = s.iterator();
246          while (it.hasNext()) {
247              Map.Entry e = (Map.Entry) it.next();
# Line 249 | Line 255 | public class ConcurrentSkipListSubMapTes
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();
262          ConcurrentNavigableMap map = map5();
263 <        empty.putAll(map);
264 <        assertEquals(5, empty.size());
265 <        assertTrue(empty.containsKey(one));
266 <        assertTrue(empty.containsKey(two));
267 <        assertTrue(empty.containsKey(three));
268 <        assertTrue(empty.containsKey(four));
269 <        assertTrue(empty.containsKey(five));
263 >        empty.putAll(map);
264 >        assertEquals(5, empty.size());
265 >        assertTrue(empty.containsKey(one));
266 >        assertTrue(empty.containsKey(two));
267 >        assertTrue(empty.containsKey(three));
268 >        assertTrue(empty.containsKey(four));
269 >        assertTrue(empty.containsKey(five));
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();
277 <        map.putIfAbsent(six, "Z");
277 >        map.putIfAbsent(six, "Z");
278          assertTrue(map.containsKey(six));
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();
# Line 281 | Line 287 | public class ConcurrentSkipListSubMapTes
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();
294 <        assertNull(map.replace(six, "Z"));
294 >        assertNull(map.replace(six, "Z"));
295          assertFalse(map.containsKey(six));
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();
# Line 298 | Line 304 | public class ConcurrentSkipListSubMapTes
304          assertEquals("Z", map.get(one));
305      }
306  
301
307      /**
308       * replace value fails when the given key not mapped to expected value
309       */
310      public void testReplaceValue() {
311          ConcurrentNavigableMap map = map5();
312          assertEquals("A", map.get(one));
313 <        assertFalse(map.replace(one, "Z", "Z"));
313 >        assertFalse(map.replace(one, "Z", "Z"));
314          assertEquals("A", map.get(one));
315      }
316  
# Line 315 | Line 320 | public class ConcurrentSkipListSubMapTes
320      public void testReplaceValue2() {
321          ConcurrentNavigableMap map = map5();
322          assertEquals("A", map.get(one));
323 <        assertTrue(map.replace(one, "A", "Z"));
323 >        assertTrue(map.replace(one, "A", "Z"));
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();
332 <        map.remove(five);
333 <        assertEquals(4, map.size());
334 <        assertFalse(map.containsKey(five));
332 >        map.remove(five);
333 >        assertEquals(4, map.size());
334 >        assertFalse(map.containsKey(five));
335      }
336  
337      /**
# Line 335 | Line 339 | public class ConcurrentSkipListSubMapTes
339       */
340      public void testRemove2() {
341          ConcurrentNavigableMap map = map5();
342 <        assertTrue(map.containsKey(five));
342 >        assertTrue(map.containsKey(five));
343          assertEquals("E", map.get(five));
344 <        map.remove(five, "E");
345 <        assertEquals(4, map.size());
346 <        assertFalse(map.containsKey(five));
347 <        map.remove(four, "A");
348 <        assertEquals(4, map.size());
349 <        assertTrue(map.containsKey(four));
346 <
344 >        map.remove(five, "E");
345 >        assertEquals(4, map.size());
346 >        assertFalse(map.containsKey(five));
347 >        map.remove(four, "A");
348 >        assertEquals(4, map.size());
349 >        assertTrue(map.containsKey(four));
350      }
351  
352      /**
# Line 362 | Line 365 | public class ConcurrentSkipListSubMapTes
365  
366          Map.Entry e4 = map.lowerEntry(zero);
367          assertNull(e4);
365
368      }
369  
370      /**
# Line 381 | Line 383 | public class ConcurrentSkipListSubMapTes
383  
384          Map.Entry e4 = map.higherEntry(six);
385          assertNull(e4);
384
386      }
387  
388      /**
# Line 400 | Line 401 | public class ConcurrentSkipListSubMapTes
401  
402          Map.Entry e4 = map.floorEntry(zero);
403          assertNull(e4);
403
404      }
405  
406      /**
# Line 419 | Line 419 | public class ConcurrentSkipListSubMapTes
419  
420          Map.Entry e4 = map.ceilingEntry(six);
421          assertNull(e4);
422
422      }
423  
424      /**
# Line 444 | Line 443 | public class ConcurrentSkipListSubMapTes
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      }
# Line 472 | Line 470 | public class ConcurrentSkipListSubMapTes
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();
483          ConcurrentNavigableMap empty = map0();
484 <        assertEquals(0, empty.size());
485 <        assertEquals(5, map.size());
484 >        assertEquals(0, empty.size());
485 >        assertEquals(5, map.size());
486      }
487  
488      /**
# Line 495 | Line 492 | public class ConcurrentSkipListSubMapTes
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  
# Line 509 | Line 506 | public class ConcurrentSkipListSubMapTes
506              ConcurrentNavigableMap c = map5();
507              c.get(null);
508              shouldThrow();
509 <        } catch (NullPointerException e){}
509 >        } catch (NullPointerException success) {}
510      }
511  
512      /**
# Line 520 | Line 517 | public class ConcurrentSkipListSubMapTes
517              ConcurrentNavigableMap c = map5();
518              c.containsKey(null);
519              shouldThrow();
520 <        } catch (NullPointerException e){}
520 >        } catch (NullPointerException success) {}
521      }
522  
523      /**
# Line 531 | Line 528 | public class ConcurrentSkipListSubMapTes
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       */
# Line 543 | Line 539 | public class ConcurrentSkipListSubMapTes
539              ConcurrentNavigableMap c = map5();
540              c.put(null, "whatever");
541              shouldThrow();
542 <        } catch (NullPointerException e){}
542 >        } catch (NullPointerException success) {}
543      }
544  
545      /**
# Line 554 | Line 550 | public class ConcurrentSkipListSubMapTes
550              ConcurrentNavigableMap c = map5();
551              c.putIfAbsent(null, "whatever");
552              shouldThrow();
553 <        } catch (NullPointerException e){}
553 >        } catch (NullPointerException success) {}
554      }
555  
556      /**
# Line 565 | Line 561 | public class ConcurrentSkipListSubMapTes
561              ConcurrentNavigableMap c = map5();
562              c.replace(null, "whatever");
563              shouldThrow();
564 <        } catch (NullPointerException e){}
564 >        } catch (NullPointerException success) {}
565      }
566  
567      /**
# Line 576 | Line 572 | public class ConcurrentSkipListSubMapTes
572              ConcurrentNavigableMap c = map5();
573              c.replace(null, one, "whatever");
574              shouldThrow();
575 <        } catch (NullPointerException e){}
575 >        } catch (NullPointerException success) {}
576      }
577  
578      /**
# Line 587 | Line 583 | public class ConcurrentSkipListSubMapTes
583              ConcurrentNavigableMap c = map5();
584              c.remove(null);
585              shouldThrow();
586 <        } catch (NullPointerException e){}
586 >        } catch (NullPointerException success) {}
587      }
588  
589      /**
# Line 598 | Line 594 | public class ConcurrentSkipListSubMapTes
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() {
604 <        ConcurrentNavigableMap q = map5();
605 <
606 <        try {
607 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
608 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
609 <            out.writeObject(q);
610 <            out.close();
611 <
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 <        }
603 >    public void testSerialization() throws Exception {
604 >        NavigableMap x = map5();
605 >        NavigableMap y = serialClone(x);
606 >
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  
628
629
614      /**
615       * subMap returns map with keys in requested range
616       */
# Line 656 | Line 640 | public class ConcurrentSkipListSubMapTes
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      }
# Line 684 | Line 668 | public class ConcurrentSkipListSubMapTes
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  
# Line 756 | Line 740 | public class ConcurrentSkipListSubMapTes
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);
754 >        map.clear();
755 >        assertEquals(0, map.size());
756      }
757  
774
758      /**
759 <     *  Maps with same contents are equal
759 >     * Maps with same contents are equal
760       */
761      public void testDescendingEquals() {
762          ConcurrentNavigableMap map1 = dmap5();
763          ConcurrentNavigableMap map2 = dmap5();
764          assertEquals(map1, map2);
765          assertEquals(map2, map1);
766 <        map1.clear();
766 >        map1.clear();
767          assertFalse(map1.equals(map2));
768          assertFalse(map2.equals(map1));
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();
776 <        assertTrue(map.containsKey(m1));
776 >        assertTrue(map.containsKey(m1));
777          assertFalse(map.containsKey(zero));
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();
785 <        assertTrue(map.containsValue("A"));
785 >        assertTrue(map.containsValue("A"));
786          assertFalse(map.containsValue("Z"));
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();
795 <        assertEquals("A", (String)map.get(m1));
795 >        assertEquals("A", (String)map.get(m1));
796          ConcurrentNavigableMap empty = dmap0();
797          assertNull(empty.get(m1));
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();
805          ConcurrentNavigableMap map = dmap5();
806 <        assertTrue(empty.isEmpty());
806 >        assertTrue(empty.isEmpty());
807          assertFalse(map.isEmpty());
808      }
809  
810      /**
811 <     *   firstKey returns first key
811 >     * firstKey returns first key
812       */
813      public void testDescendingFirstKey() {
814          ConcurrentNavigableMap map = dmap5();
815 <        assertEquals(m1, map.firstKey());
815 >        assertEquals(m1, map.firstKey());
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());
823 >        assertEquals(m5, map.lastKey());
824      }
825  
843
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();
831 <        Set s = map.keySet();
832 <        assertEquals(5, s.size());
833 <        assertTrue(s.contains(m1));
834 <        assertTrue(s.contains(m2));
835 <        assertTrue(s.contains(m3));
836 <        assertTrue(s.contains(m4));
837 <        assertTrue(s.contains(m5));
831 >        Set s = map.keySet();
832 >        assertEquals(5, s.size());
833 >        assertTrue(s.contains(m1));
834 >        assertTrue(s.contains(m2));
835 >        assertTrue(s.contains(m3));
836 >        assertTrue(s.contains(m4));
837 >        assertTrue(s.contains(m5));
838      }
839  
840      /**
841 <     *   keySet is ordered
841 >     * keySet is ordered
842       */
843      public void testDescendingKeySetOrder() {
844          ConcurrentNavigableMap map = dmap5();
845 <        Set s = map.keySet();
845 >        Set s = map.keySet();
846          Iterator i = s.iterator();
847          Integer last = (Integer)i.next();
848          assertEquals(last, m1);
# Line 876 | Line 858 | public class ConcurrentSkipListSubMapTes
858       */
859      public void testDescendingValues() {
860          ConcurrentNavigableMap map = dmap5();
861 <        Collection s = map.values();
862 <        assertEquals(5, s.size());
863 <        assertTrue(s.contains("A"));
864 <        assertTrue(s.contains("B"));
865 <        assertTrue(s.contains("C"));
866 <        assertTrue(s.contains("D"));
867 <        assertTrue(s.contains("E"));
861 >        Collection s = map.values();
862 >        assertEquals(5, s.size());
863 >        assertTrue(s.contains("A"));
864 >        assertTrue(s.contains("B"));
865 >        assertTrue(s.contains("C"));
866 >        assertTrue(s.contains("D"));
867 >        assertTrue(s.contains("E"));
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();
875 <        Set s = map.keySet();
875 >        Set s = map.keySet();
876          Object[] ar = s.toArray();
877          assertTrue(s.containsAll(Arrays.asList(ar)));
878 <        assertEquals(5, ar.length);
878 >        assertEquals(5, ar.length);
879          ar[0] = m10;
880          assertFalse(s.containsAll(Arrays.asList(ar)));
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();
888 <        Set s = map.descendingKeySet();
888 >        Set s = map.descendingKeySet();
889          Object[] ar = s.toArray();
890 <        assertEquals(5, ar.length);
890 >        assertEquals(5, ar.length);
891          assertTrue(s.containsAll(Arrays.asList(ar)));
892          ar[0] = m10;
893          assertFalse(s.containsAll(Arrays.asList(ar)));
894      }
895  
896      /**
897 <     *  Values.toArray contains all values
897 >     * Values.toArray contains all values
898       */
899      public void testDescendingValuesToArray() {
900          ConcurrentNavigableMap map = dmap5();
901 <        Collection v = map.values();
901 >        Collection v = map.values();
902          Object[] ar = v.toArray();
903          ArrayList s = new ArrayList(Arrays.asList(ar));
904 <        assertEquals(5, ar.length);
905 <        assertTrue(s.contains("A"));
906 <        assertTrue(s.contains("B"));
907 <        assertTrue(s.contains("C"));
908 <        assertTrue(s.contains("D"));
909 <        assertTrue(s.contains("E"));
904 >        assertEquals(5, ar.length);
905 >        assertTrue(s.contains("A"));
906 >        assertTrue(s.contains("B"));
907 >        assertTrue(s.contains("C"));
908 >        assertTrue(s.contains("D"));
909 >        assertTrue(s.contains("E"));
910      }
911  
930
912      /**
913       * entrySet contains all pairs
914       */
915      public void testDescendingEntrySet() {
916          ConcurrentNavigableMap map = dmap5();
917 <        Set s = map.entrySet();
918 <        assertEquals(5, s.size());
917 >        Set s = map.entrySet();
918 >        assertEquals(5, s.size());
919          Iterator it = s.iterator();
920          while (it.hasNext()) {
921              Map.Entry e = (Map.Entry) it.next();
# Line 948 | Line 929 | public class ConcurrentSkipListSubMapTes
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();
936          ConcurrentNavigableMap map = dmap5();
937 <        empty.putAll(map);
938 <        assertEquals(5, empty.size());
939 <        assertTrue(empty.containsKey(m1));
940 <        assertTrue(empty.containsKey(m2));
941 <        assertTrue(empty.containsKey(m3));
942 <        assertTrue(empty.containsKey(m4));
943 <        assertTrue(empty.containsKey(m5));
937 >        empty.putAll(map);
938 >        assertEquals(5, empty.size());
939 >        assertTrue(empty.containsKey(m1));
940 >        assertTrue(empty.containsKey(m2));
941 >        assertTrue(empty.containsKey(m3));
942 >        assertTrue(empty.containsKey(m4));
943 >        assertTrue(empty.containsKey(m5));
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();
951 <        map.putIfAbsent(six, "Z");
951 >        map.putIfAbsent(six, "Z");
952          assertTrue(map.containsKey(six));
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();
# Line 980 | Line 961 | public class ConcurrentSkipListSubMapTes
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();
968 <        assertNull(map.replace(six, "Z"));
968 >        assertNull(map.replace(six, "Z"));
969          assertFalse(map.containsKey(six));
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();
# Line 997 | Line 978 | public class ConcurrentSkipListSubMapTes
978          assertEquals("Z", map.get(m1));
979      }
980  
1000
981      /**
982       * replace value fails when the given key not mapped to expected value
983       */
984      public void testDescendingReplaceValue() {
985          ConcurrentNavigableMap map = dmap5();
986          assertEquals("A", map.get(m1));
987 <        assertFalse(map.replace(m1, "Z", "Z"));
987 >        assertFalse(map.replace(m1, "Z", "Z"));
988          assertEquals("A", map.get(m1));
989      }
990  
# Line 1014 | Line 994 | public class ConcurrentSkipListSubMapTes
994      public void testDescendingReplaceValue2() {
995          ConcurrentNavigableMap map = dmap5();
996          assertEquals("A", map.get(m1));
997 <        assertTrue(map.replace(m1, "A", "Z"));
997 >        assertTrue(map.replace(m1, "A", "Z"));
998          assertEquals("Z", map.get(m1));
999      }
1000  
1021
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();
1006 <        map.remove(m5);
1007 <        assertEquals(4, map.size());
1008 <        assertFalse(map.containsKey(m5));
1006 >        map.remove(m5);
1007 >        assertEquals(4, map.size());
1008 >        assertFalse(map.containsKey(m5));
1009      }
1010  
1011      /**
# Line 1034 | Line 1013 | public class ConcurrentSkipListSubMapTes
1013       */
1014      public void testDescendingRemove2() {
1015          ConcurrentNavigableMap map = dmap5();
1016 <        assertTrue(map.containsKey(m5));
1016 >        assertTrue(map.containsKey(m5));
1017          assertEquals("E", map.get(m5));
1018 <        map.remove(m5, "E");
1019 <        assertEquals(4, map.size());
1020 <        assertFalse(map.containsKey(m5));
1021 <        map.remove(m4, "A");
1022 <        assertEquals(4, map.size());
1023 <        assertTrue(map.containsKey(m4));
1045 <
1018 >        map.remove(m5, "E");
1019 >        assertEquals(4, map.size());
1020 >        assertFalse(map.containsKey(m5));
1021 >        map.remove(m4, "A");
1022 >        assertEquals(4, map.size());
1023 >        assertTrue(map.containsKey(m4));
1024      }
1025  
1026      /**
# Line 1061 | Line 1039 | public class ConcurrentSkipListSubMapTes
1039  
1040          Map.Entry e4 = map.lowerEntry(zero);
1041          assertNull(e4);
1064
1042      }
1043  
1044      /**
# Line 1080 | Line 1057 | public class ConcurrentSkipListSubMapTes
1057  
1058          Map.Entry e4 = map.higherEntry(m6);
1059          assertNull(e4);
1083
1060      }
1061  
1062      /**
# Line 1099 | Line 1075 | public class ConcurrentSkipListSubMapTes
1075  
1076          Map.Entry e4 = map.floorEntry(zero);
1077          assertNull(e4);
1102
1078      }
1079  
1080      /**
# Line 1118 | Line 1093 | public class ConcurrentSkipListSubMapTes
1093  
1094          Map.Entry e4 = map.ceilingEntry(m6);
1095          assertNull(e4);
1121
1096      }
1097  
1098      /**
# Line 1143 | Line 1117 | public class ConcurrentSkipListSubMapTes
1117          try {
1118              e.setValue("A");
1119              shouldThrow();
1120 <        } catch (Exception ok) {
1147 <        }
1120 >        } catch (UnsupportedOperationException success) {}
1121          e = map.pollFirstEntry();
1122          assertNull(e);
1123      }
# Line 1171 | Line 1144 | public class ConcurrentSkipListSubMapTes
1144          try {
1145              e.setValue("E");
1146              shouldThrow();
1147 <        } catch (Exception ok) {
1175 <        }
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();
1157          ConcurrentNavigableMap empty = dmap0();
1158 <        assertEquals(0, empty.size());
1159 <        assertEquals(5, map.size());
1158 >        assertEquals(0, empty.size());
1159 >        assertEquals(5, map.size());
1160      }
1161  
1162      /**
# Line 1194 | Line 1166 | public class ConcurrentSkipListSubMapTes
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      /**
# Line 1230 | Line 1202 | public class ConcurrentSkipListSubMapTes
1202              ConcurrentNavigableMap c = dmap0();
1203              c.containsValue(null);
1204              shouldThrow();
1205 <        } catch (NullPointerException e){}
1205 >        } catch (NullPointerException success) {}
1206      }
1207  
1236
1208      /**
1209       * put(null,x) throws NPE
1210       */
# Line 1242 | Line 1213 | public class ConcurrentSkipListSubMapTes
1213              ConcurrentNavigableMap c = dmap5();
1214              c.put(null, "whatever");
1215              shouldThrow();
1216 <        } catch (NullPointerException e){}
1216 >        } catch (NullPointerException success) {}
1217      }
1218  
1219      /**
# Line 1253 | Line 1224 | public class ConcurrentSkipListSubMapTes
1224              ConcurrentNavigableMap c = dmap5();
1225              c.putIfAbsent(null, "whatever");
1226              shouldThrow();
1227 <        } catch (NullPointerException e){}
1227 >        } catch (NullPointerException success) {}
1228      }
1229  
1230      /**
# Line 1264 | Line 1235 | public class ConcurrentSkipListSubMapTes
1235              ConcurrentNavigableMap c = dmap5();
1236              c.replace(null, "whatever");
1237              shouldThrow();
1238 <        } catch (NullPointerException e){}
1238 >        } catch (NullPointerException success) {}
1239      }
1240  
1241      /**
# Line 1275 | Line 1246 | public class ConcurrentSkipListSubMapTes
1246              ConcurrentNavigableMap c = dmap5();
1247              c.replace(null, m1, "whatever");
1248              shouldThrow();
1249 <        } catch (NullPointerException e){}
1249 >        } catch (NullPointerException success) {}
1250      }
1251  
1252      /**
# Line 1286 | Line 1257 | public class ConcurrentSkipListSubMapTes
1257              ConcurrentNavigableMap c = dmap5();
1258              c.remove(null);
1259              shouldThrow();
1260 <        } catch (NullPointerException e){}
1260 >        } catch (NullPointerException success) {}
1261      }
1262  
1263      /**
# Line 1297 | Line 1268 | public class ConcurrentSkipListSubMapTes
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() {
1278 <        ConcurrentNavigableMap q = dmap5();
1279 <
1280 <        try {
1281 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1282 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1283 <            out.writeObject(q);
1284 <            out.close();
1285 <
1315 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1316 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1317 <            ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject();
1318 <            assertEquals(q.size(), r.size());
1319 <            assertTrue(q.equals(r));
1320 <            assertTrue(r.equals(q));
1321 <        } catch (Exception e){
1322 <            e.printStackTrace();
1323 <            unexpectedException();
1324 <        }
1277 >    public void testDescendingSerialization() throws Exception {
1278 >        NavigableMap x = dmap5();
1279 >        NavigableMap y = serialClone(x);
1280 >
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  
1327
1328
1288      /**
1289       * subMap returns map with keys in requested range
1290       */
# Line 1355 | Line 1314 | public class ConcurrentSkipListSubMapTes
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      }
# Line 1383 | Line 1342 | public class ConcurrentSkipListSubMapTes
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  
# Line 1455 | Line 1414 | public class ConcurrentSkipListSubMapTes
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());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines