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

Comparing jsr166/src/test/tck/TreeMapTest.java (file contents):
Revision 1.23 by jsr166, Sat Nov 26 05:42:14 2011 UTC vs.
Revision 1.35 by jsr166, Sun Sep 29 20:40:48 2019 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
8 < import java.util.*;
7 > import java.util.Arrays;
8 > import java.util.BitSet;
9 > import java.util.Collection;
10 > import java.util.Iterator;
11 > import java.util.Map;
12 > import java.util.NavigableMap;
13 > import java.util.NavigableSet;
14 > import java.util.NoSuchElementException;
15 > import java.util.Random;
16 > import java.util.Set;
17 > import java.util.TreeMap;
18 >
19 > import junit.framework.Test;
20  
21   public class TreeMapTest 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(TreeMapTest.class);
26 >        class Implementation implements MapImplementation {
27 >            public Class<?> klazz() { return TreeMap.class; }
28 >            public Map emptyMap() { return new TreeMap(); }
29 >            public boolean isConcurrent() { return false; }
30 >            public boolean permitsNullKeys() { return false; }
31 >            public boolean permitsNullValues() { return true; }
32 >            public boolean supportsSetValue() { return true; }
33 >        }
34 >        return newTestSuite(
35 >            TreeMapTest.class,
36 >            MapTest.testSuite(new Implementation()));
37      }
38  
39      /**
40 <     * Create a map from Integers 1-5 to Strings "A"-"E".
40 >     * Returns a new map from Integers 1-5 to Strings "A"-"E".
41       */
42      private static TreeMap map5() {
43          TreeMap map = new TreeMap();
# Line 41 | Line 62 | public class TreeMapTest extends JSR166T
62      }
63  
64      /**
65 <     *
65 >     * copy constructor creates map equal to source map
66       */
67      public void testConstructFromSorted() {
68          TreeMap map = map5();
# Line 563 | Line 584 | public class TreeMapTest extends JSR166T
584       * get(null) of nonempty map throws NPE
585       */
586      public void testGet_NullPointerException() {
587 +        TreeMap c = map5();
588          try {
567            TreeMap c = map5();
589              c.get(null);
590              shouldThrow();
591          } catch (NullPointerException success) {}
# Line 574 | Line 595 | public class TreeMapTest extends JSR166T
595       * containsKey(null) of nonempty map throws NPE
596       */
597      public void testContainsKey_NullPointerException() {
598 +        TreeMap c = map5();
599          try {
578            TreeMap c = map5();
600              c.containsKey(null);
601              shouldThrow();
602          } catch (NullPointerException success) {}
# Line 585 | Line 606 | public class TreeMapTest extends JSR166T
606       * remove(null) throws NPE for nonempty map
607       */
608      public void testRemove1_NullPointerException() {
609 +        TreeMap c = new TreeMap();
610 +        c.put("sadsdf", "asdads");
611          try {
589            TreeMap c = new TreeMap();
590            c.put("sadsdf", "asdads");
612              c.remove(null);
613              shouldThrow();
614          } catch (NullPointerException success) {}
615      }
616  
617      /**
618 <     * A deserialized map equals original
618 >     * A deserialized/reserialized map equals original
619       */
620      public void testSerialization() throws Exception {
621          NavigableMap x = map5();
622          NavigableMap y = serialClone(x);
623  
624 <        assertTrue(x != y);
624 >        assertNotSame(x, y);
625          assertEquals(x.size(), y.size());
626          assertEquals(x.toString(), y.toString());
627          assertEquals(x, y);
# Line 790 | Line 811 | public class TreeMapTest extends JSR166T
811  
812      static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
813          NavigableMap<Integer, Integer> result
814 <            = (NavigableMap<Integer, Integer>) cl.newInstance();
814 >            = (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
815          assertEquals(0, result.size());
816          assertFalse(result.keySet().iterator().hasNext());
817          return result;
# Line 823 | Line 844 | public class TreeMapTest extends JSR166T
844          // Add entries till we're back to original size
845          while (map.size() < size) {
846              int key = min + rnd.nextInt(rangeSize);
847 <            assertTrue(key >= min && key<= max);
847 >            assertTrue(key >= min && key <= max);
848              put(map, key);
849          }
850      }
# Line 848 | Line 869 | public class TreeMapTest extends JSR166T
869          // Add entries till we're back to original size
870          while (map.size() < size) {
871              int key = min - 5 + rnd.nextInt(rangeSize + 10);
872 <            if (key >= min && key<= max) {
872 >            if (key >= min && key <= max) {
873                  put(map, key);
874              } else {
875                  try {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines