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

Comparing jsr166/src/test/tck/TreeSubMapTest.java (file contents):
Revision 1.15 by jsr166, Fri May 27 19:10:32 2011 UTC vs.
Revision 1.24 by jsr166, Fri Aug 4 03:30:21 2017 UTC

# Line 4 | Line 4
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.TreeMap;
16 >
17 > import junit.framework.Test;
18 > import junit.framework.TestSuite;
19  
20   public class TreeSubMapTest extends JSR166TestCase {
21      public static void main(String[] args) {
22 <        junit.textui.TestRunner.run(suite());
22 >        main(suite(), args);
23      }
24      public static Test suite() {
25          return new TestSuite(TreeSubMapTest.class);
26      }
27  
28      /**
29 <     * Create a map from Integers 1-5 to Strings "A"-"E".
29 >     * Returns a new map from Integers 1-5 to Strings "A"-"E".
30       */
31      private static NavigableMap map5() {
32          TreeMap map = new TreeMap();
# Line 42 | Line 50 | public class TreeSubMapTest extends JSR1
50      }
51  
52      /**
53 <     * Create a map from Integers -5 to -1 to Strings "A"-"E".
53 >     * Returns a new map from Integers -5 to -1 to Strings "A"-"E".
54       */
55      private static NavigableMap dmap5() {
56          TreeMap map = new TreeMap();
# Line 69 | Line 77 | public class TreeSubMapTest extends JSR1
77      public void testClear() {
78          NavigableMap map = map5();
79          map.clear();
80 <        assertEquals(map.size(), 0);
80 >        assertEquals(0, map.size());
81      }
82  
75
83      /**
84       * Maps with same contents are equal
85       */
# Line 141 | Line 148 | public class TreeSubMapTest extends JSR1
148          assertEquals(five, map.lastKey());
149      }
150  
144
151      /**
152       * keySet returns a Set containing all the keys
153       */
# Line 386 | Line 392 | public class TreeSubMapTest extends JSR1
392       * get(null) of nonempty map throws NPE
393       */
394      public void testGet_NullPointerException() {
395 +        NavigableMap c = map5();
396          try {
390            NavigableMap c = map5();
397              c.get(null);
398              shouldThrow();
399          } catch (NullPointerException success) {}
# Line 397 | Line 403 | public class TreeSubMapTest extends JSR1
403       * containsKey(null) of nonempty map throws NPE
404       */
405      public void testContainsKey_NullPointerException() {
406 +        NavigableMap c = map5();
407          try {
401            NavigableMap c = map5();
408              c.containsKey(null);
409              shouldThrow();
410          } catch (NullPointerException success) {}
# Line 408 | Line 414 | public class TreeSubMapTest extends JSR1
414       * put(null,x) throws NPE
415       */
416      public void testPut1_NullPointerException() {
417 +        NavigableMap c = map5();
418          try {
412            NavigableMap c = map5();
419              c.put(null, "whatever");
420              shouldThrow();
421          } catch (NullPointerException success) {}
# Line 419 | Line 425 | public class TreeSubMapTest extends JSR1
425       * remove(null) throws NPE
426       */
427      public void testRemove1_NullPointerException() {
428 +        NavigableMap c = map5();
429          try {
423            NavigableMap c = map5();
430              c.remove(null);
431              shouldThrow();
432          } catch (NullPointerException success) {}
433      }
434  
435      /**
436 <     * A deserialized map equals original
436 >     * A deserialized/reserialized map equals original
437       */
438      public void testSerialization() throws Exception {
439 <        NavigableMap q = map5();
439 >        NavigableMap x = map5();
440 >        NavigableMap y = serialClone(x);
441  
442 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
443 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
444 <        out.writeObject(q);
445 <        out.close();
446 <
440 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
441 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
442 <        NavigableMap r = (NavigableMap)in.readObject();
443 <        assertFalse(r.isEmpty());
444 <        assertEquals(q.size(), r.size());
445 <        assertTrue(q.equals(r));
446 <        assertTrue(r.equals(q));
442 >        assertNotSame(x, y);
443 >        assertEquals(x.size(), y.size());
444 >        assertEquals(x.toString(), y.toString());
445 >        assertEquals(x, y);
446 >        assertEquals(y, x);
447      }
448  
449
450
449      /**
450       * subMap returns map with keys in requested range
451       */
# Line 589 | Line 587 | public class TreeSubMapTest extends JSR1
587      public void testDescendingClear() {
588          NavigableMap map = dmap5();
589          map.clear();
590 <        assertEquals(map.size(), 0);
590 >        assertEquals(0, map.size());
591      }
592  
595
593      /**
594       * Maps with same contents are equal
595       */
# Line 661 | Line 658 | public class TreeSubMapTest extends JSR1
658          assertEquals(m5, map.lastKey());
659      }
660  
664
661      /**
662       * keySet returns a Set containing all the keys
663       */
# Line 748 | Line 744 | public class TreeSubMapTest extends JSR1
744          assertTrue(s.contains("E"));
745      }
746  
751
747      /**
748       * entrySet contains all pairs
749       */
# Line 783 | Line 778 | public class TreeSubMapTest extends JSR1
778          assertTrue(empty.containsKey(m5));
779      }
780  
786
781      /**
782       * remove removes the correct key-value pair from the map
783       */
# Line 947 | Line 941 | public class TreeSubMapTest extends JSR1
941       * get(null) of nonempty map throws NPE
942       */
943      public void testDescendingGet_NullPointerException() {
944 +        NavigableMap c = dmap5();
945          try {
951            NavigableMap c = dmap5();
946              c.get(null);
947              shouldThrow();
948          } catch (NullPointerException success) {}
# Line 958 | Line 952 | public class TreeSubMapTest extends JSR1
952       * put(null,x) throws NPE
953       */
954      public void testDescendingPut1_NullPointerException() {
955 +        NavigableMap c = dmap5();
956          try {
962            NavigableMap c = dmap5();
957              c.put(null, "whatever");
958              shouldThrow();
959          } catch (NullPointerException success) {}
960      }
961  
962      /**
963 <     * A deserialized map equals original
963 >     * A deserialized/reserialized map equals original
964       */
965      public void testDescendingSerialization() throws Exception {
966 <        NavigableMap q = dmap5();
966 >        NavigableMap x = dmap5();
967 >        NavigableMap y = serialClone(x);
968  
969 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
970 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
971 <        out.writeObject(q);
972 <        out.close();
973 <
979 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
980 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
981 <        NavigableMap r = (NavigableMap)in.readObject();
982 <        assertEquals(q.size(), r.size());
983 <        assertTrue(q.equals(r));
984 <        assertTrue(r.equals(q));
969 >        assertNotSame(x, y);
970 >        assertEquals(x.size(), y.size());
971 >        assertEquals(x.toString(), y.toString());
972 >        assertEquals(x, y);
973 >        assertEquals(y, x);
974      }
975  
987
976      /**
977       * subMap returns map with keys in requested range
978       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines