--- jsr166/src/test/tck/TreeMapTest.java 2013/01/02 07:41:07 1.26 +++ jsr166/src/test/tck/TreeMapTest.java 2017/08/23 05:33:00 1.34 @@ -4,15 +4,38 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; -import java.util.*; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.NoSuchElementException; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; + +import junit.framework.Test; public class TreeMapTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { - return new TestSuite(TreeMapTest.class); + class Implementation implements MapImplementation { + public Class klazz() { return TreeMap.class; } + public Map emptyMap() { return new TreeMap(); } + public Object makeKey(int i) { return i; } + public Object makeValue(int i) { return i; } + public boolean isConcurrent() { return false; } + public boolean permitsNullKeys() { return false; } + public boolean permitsNullValues() { return true; } + public boolean supportsSetValue() { return true; } + } + return newTestSuite( + TreeMapTest.class, + MapTest.testSuite(new Implementation())); } /** @@ -563,8 +586,8 @@ public class TreeMapTest extends JSR166T * get(null) of nonempty map throws NPE */ public void testGet_NullPointerException() { + TreeMap c = map5(); try { - TreeMap c = map5(); c.get(null); shouldThrow(); } catch (NullPointerException success) {} @@ -574,8 +597,8 @@ public class TreeMapTest extends JSR166T * containsKey(null) of nonempty map throws NPE */ public void testContainsKey_NullPointerException() { + TreeMap c = map5(); try { - TreeMap c = map5(); c.containsKey(null); shouldThrow(); } catch (NullPointerException success) {} @@ -585,22 +608,22 @@ public class TreeMapTest extends JSR166T * remove(null) throws NPE for nonempty map */ public void testRemove1_NullPointerException() { + TreeMap c = new TreeMap(); + c.put("sadsdf", "asdads"); try { - TreeMap c = new TreeMap(); - c.put("sadsdf", "asdads"); c.remove(null); shouldThrow(); } catch (NullPointerException success) {} } /** - * A deserialized map equals original + * A deserialized/reserialized map equals original */ public void testSerialization() throws Exception { NavigableMap x = map5(); NavigableMap y = serialClone(x); - assertTrue(x != y); + assertNotSame(x, y); assertEquals(x.size(), y.size()); assertEquals(x.toString(), y.toString()); assertEquals(x, y); @@ -790,7 +813,7 @@ public class TreeMapTest extends JSR166T static NavigableMap newMap(Class cl) throws Exception { NavigableMap result - = (NavigableMap) cl.newInstance(); + = (NavigableMap) cl.getConstructor().newInstance(); assertEquals(0, result.size()); assertFalse(result.keySet().iterator().hasNext()); return result; @@ -823,7 +846,7 @@ public class TreeMapTest extends JSR166T // Add entries till we're back to original size while (map.size() < size) { int key = min + rnd.nextInt(rangeSize); - assertTrue(key >= min && key<= max); + assertTrue(key >= min && key <= max); put(map, key); } } @@ -848,7 +871,7 @@ public class TreeMapTest extends JSR166T // Add entries till we're back to original size while (map.size() < size) { int key = min - 5 + rnd.nextInt(rangeSize + 10); - if (key >= min && key<= max) { + if (key >= min && key <= max) { put(map, key); } else { try {