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.16 by jsr166, Sat Oct 9 19:30:34 2010 UTC vs.
Revision 1.26 by jsr166, Fri Aug 4 03:30:21 2017 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 >        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();
# Line 36 | Line 45 | public class ConcurrentSkipListSubMapTes
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();
# Line 69 | Line 78 | public class ConcurrentSkipListSubMapTes
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
86       */
# Line 141 | Line 149 | public class ConcurrentSkipListSubMapTes
149          assertEquals(five, map.lastKey());
150      }
151  
144
152      /**
153       * keySet returns a Set containing all the keys
154       */
# Line 228 | Line 235 | public class ConcurrentSkipListSubMapTes
235          assertTrue(s.contains("E"));
236      }
237  
231
238      /**
239       * entrySet contains all pairs
240       */
# 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       */
# Line 319 | Line 324 | public class ConcurrentSkipListSubMapTes
324          assertEquals("Z", map.get(one));
325      }
326  
322
327      /**
328       * remove removes the correct key-value pair from the map
329       */
# Line 488 | 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 527 | Line 531 | public class ConcurrentSkipListSubMapTes
531          } catch (NullPointerException success) {}
532      }
533  
530
534      /**
535       * put(null,x) throws NPE
536       */
# Line 595 | Line 598 | public class ConcurrentSkipListSubMapTes
598      }
599  
600      /**
601 <     * A deserialized map equals original
601 >     * A deserialized/reserialized 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 <
608 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
609 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
610 <        ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject();
611 <        assertEquals(q.size(), r.size());
612 <        assertTrue(q.equals(r));
613 <        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  
616
617
614      /**
615       * subMap returns map with keys in requested range
616       */
# Line 756 | Line 752 | public class ConcurrentSkipListSubMapTes
752      public void testDescendingClear() {
753          ConcurrentNavigableMap map = dmap5();
754          map.clear();
755 <        assertEquals(map.size(), 0);
755 >        assertEquals(0, map.size());
756      }
757  
762
758      /**
759       * Maps with same contents are equal
760       */
# Line 828 | Line 823 | public class ConcurrentSkipListSubMapTes
823          assertEquals(m5, map.lastKey());
824      }
825  
831
826      /**
827       * keySet returns a Set containing all the keys
828       */
# Line 915 | Line 909 | public class ConcurrentSkipListSubMapTes
909          assertTrue(s.contains("E"));
910      }
911  
918
912      /**
913       * entrySet contains all pairs
914       */
# Line 985 | Line 978 | public class ConcurrentSkipListSubMapTes
978          assertEquals("Z", map.get(m1));
979      }
980  
988
981      /**
982       * replace value fails when the given key not mapped to expected value
983       */
# Line 1006 | Line 998 | public class ConcurrentSkipListSubMapTes
998          assertEquals("Z", map.get(m1));
999      }
1000  
1009
1001      /**
1002       * remove removes the correct key-value pair from the map
1003       */
# Line 1175 | 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  
# Line 1214 | Line 1205 | public class ConcurrentSkipListSubMapTes
1205          } catch (NullPointerException success) {}
1206      }
1207  
1217
1208      /**
1209       * put(null,x) throws NPE
1210       */
# Line 1282 | Line 1272 | public class ConcurrentSkipListSubMapTes
1272      }
1273  
1274      /**
1275 <     * A deserialized map equals original
1275 >     * A deserialized/reserialized 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 <
1295 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1296 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1297 <        ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject();
1298 <        assertEquals(q.size(), r.size());
1299 <        assertTrue(q.equals(r));
1300 <        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  
1303
1288      /**
1289       * subMap returns map with keys in requested range
1290       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines