--- jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java 2010/10/09 19:30:34 1.16 +++ jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java 2014/12/31 19:05:42 1.24 @@ -1,13 +1,22 @@ /* * 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.*; +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.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; + +import junit.framework.Test; +import junit.framework.TestSuite; public class ConcurrentSkipListSubMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -18,7 +27,7 @@ public class ConcurrentSkipListSubMapTes } /** - * 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 ConcurrentNavigableMap map5() { ConcurrentSkipListMap map = new ConcurrentSkipListMap(); @@ -36,7 +45,7 @@ public class ConcurrentSkipListSubMapTes } /** - * 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 ConcurrentNavigableMap dmap5() { ConcurrentSkipListMap map = new ConcurrentSkipListMap(); @@ -69,10 +78,9 @@ public class ConcurrentSkipListSubMapTes public void testClear() { ConcurrentNavigableMap map = map5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } - /** * Maps with same contents are equal */ @@ -141,7 +149,6 @@ public class ConcurrentSkipListSubMapTes assertEquals(five, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -228,7 +235,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -298,7 +304,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(one)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -319,7 +324,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(one)); } - /** * remove removes the correct key-value pair from the map */ @@ -488,7 +492,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap 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))); } } @@ -527,7 +531,6 @@ public class ConcurrentSkipListSubMapTes } catch (NullPointerException success) {} } - /** * put(null,x) throws NPE */ @@ -598,23 +601,16 @@ public class ConcurrentSkipListSubMapTes * A deserialized map equals original */ public void testSerialization() throws Exception { - ConcurrentNavigableMap 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)); - ConcurrentNavigableMap r = (ConcurrentNavigableMap)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 */ @@ -756,10 +752,9 @@ public class ConcurrentSkipListSubMapTes public void testDescendingClear() { ConcurrentNavigableMap map = dmap5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } - /** * Maps with same contents are equal */ @@ -828,7 +823,6 @@ public class ConcurrentSkipListSubMapTes assertEquals(m5, map.lastKey()); } - /** * keySet returns a Set containing all the keys */ @@ -915,7 +909,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -985,7 +978,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(m1)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -1006,7 +998,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(m1)); } - /** * remove removes the correct key-value pair from the map */ @@ -1175,7 +1166,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap 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))); } } @@ -1214,7 +1205,6 @@ public class ConcurrentSkipListSubMapTes } catch (NullPointerException success) {} } - /** * put(null,x) throws NPE */ @@ -1285,22 +1275,16 @@ public class ConcurrentSkipListSubMapTes * A deserialized map equals original */ public void testDescendingSerialization() throws Exception { - ConcurrentNavigableMap 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)); - ConcurrentNavigableMap r = (ConcurrentNavigableMap)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 */