--- jsr166/src/test/tck/TreeSubMapTest.java 2010/10/09 19:30:35 1.13 +++ jsr166/src/test/tck/TreeSubMapTest.java 2011/11/26 05:19:17 1.17 @@ -1,13 +1,11 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ import junit.framework.*; import java.util.*; -import java.util.concurrent.*; -import java.io.*; public class TreeSubMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -69,10 +67,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 +138,6 @@ public class TreeSubMapTest extends JSR1 assertEquals(five, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -376,7 +372,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap map = map5(); String s = map.toString(); for (int i = 1; i <= 5; ++i) { - assertTrue(s.indexOf(String.valueOf(i)) >= 0); + assertTrue(s.contains(String.valueOf(i))); } } @@ -430,24 +426,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)); + assertTrue(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 +577,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 +648,6 @@ public class TreeSubMapTest extends JSR1 assertEquals(m5, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -748,7 +734,6 @@ public class TreeSubMapTest extends JSR1 assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -783,7 +768,6 @@ public class TreeSubMapTest extends JSR1 assertTrue(empty.containsKey(m5)); } - /** * remove removes the correct key-value pair from the map */ @@ -937,7 +921,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap map = dmap5(); String s = map.toString(); for (int i = 1; i <= 5; ++i) { - assertTrue(s.indexOf(String.valueOf(i)) >= 0); + assertTrue(s.contains(String.valueOf(i))); } } @@ -969,22 +953,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)); + assertTrue(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 */