--- jsr166/src/test/tck/TreeSubMapTest.java 2011/05/27 19:10:32 1.15 +++ jsr166/src/test/tck/TreeSubMapTest.java 2014/12/31 19:05:43 1.21 @@ -4,10 +4,18 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; -import java.util.*; -import java.util.concurrent.*; -import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.NavigableMap; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import junit.framework.Test; +import junit.framework.TestSuite; public class TreeSubMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -18,7 +26,7 @@ public class TreeSubMapTest extends JSR1 } /** - * Create a map from Integers 1-5 to Strings "A"-"E". + * Returns a new map from Integers 1-5 to Strings "A"-"E". */ private static NavigableMap map5() { TreeMap map = new TreeMap(); @@ -42,7 +50,7 @@ public class TreeSubMapTest extends JSR1 } /** - * Create a map from Integers -5 to -1 to Strings "A"-"E". + * Returns a new map from Integers -5 to -1 to Strings "A"-"E". */ private static NavigableMap dmap5() { TreeMap map = new TreeMap(); @@ -69,10 +77,9 @@ public class TreeSubMapTest extends JSR1 public void testClear() { NavigableMap map = map5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } - /** * Maps with same contents are equal */ @@ -141,7 +148,6 @@ public class TreeSubMapTest extends JSR1 assertEquals(five, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -430,24 +436,16 @@ public class TreeSubMapTest extends JSR1 * A deserialized map equals original */ public void testSerialization() throws Exception { - NavigableMap q = map5(); + NavigableMap x = map5(); + NavigableMap y = serialClone(x); - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(q); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - NavigableMap r = (NavigableMap)in.readObject(); - assertFalse(r.isEmpty()); - assertEquals(q.size(), r.size()); - assertTrue(q.equals(r)); - assertTrue(r.equals(q)); + assertNotSame(x, y); + assertEquals(x.size(), y.size()); + assertEquals(x.toString(), y.toString()); + assertEquals(x, y); + assertEquals(y, x); } - - /** * subMap returns map with keys in requested range */ @@ -589,10 +587,9 @@ public class TreeSubMapTest extends JSR1 public void testDescendingClear() { NavigableMap map = dmap5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } - /** * Maps with same contents are equal */ @@ -661,7 +658,6 @@ public class TreeSubMapTest extends JSR1 assertEquals(m5, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -748,7 +744,6 @@ public class TreeSubMapTest extends JSR1 assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -783,7 +778,6 @@ public class TreeSubMapTest extends JSR1 assertTrue(empty.containsKey(m5)); } - /** * remove removes the correct key-value pair from the map */ @@ -969,22 +963,16 @@ public class TreeSubMapTest extends JSR1 * A deserialized map equals original */ public void testDescendingSerialization() throws Exception { - NavigableMap q = dmap5(); + NavigableMap x = dmap5(); + NavigableMap y = serialClone(x); - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(q); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - NavigableMap r = (NavigableMap)in.readObject(); - assertEquals(q.size(), r.size()); - assertTrue(q.equals(r)); - assertTrue(r.equals(q)); + assertNotSame(x, y); + assertEquals(x.size(), y.size()); + assertEquals(x.toString(), y.toString()); + assertEquals(x, y); + assertEquals(y, x); } - /** * subMap returns map with keys in requested range */