--- jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2010/10/11 05:40:41 1.21 +++ jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2014/12/31 19:05:42 1.33 @@ -1,13 +1,24 @@ /* * 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.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.concurrent.ConcurrentSkipListMap; + +import junit.framework.Test; +import junit.framework.TestSuite; public class ConcurrentSkipListMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -18,7 +29,7 @@ public class ConcurrentSkipListMapTest e } /** - * 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 ConcurrentSkipListMap map5() { ConcurrentSkipListMap map = new ConcurrentSkipListMap(); @@ -39,11 +50,11 @@ public class ConcurrentSkipListMapTest e public void testClear() { ConcurrentSkipListMap map = map5(); map.clear(); - assertEquals(map.size(), 0); + assertEquals(0, map.size()); } /** - * + * copy constructor creates map equal to source map */ public void testConstructFromSorted() { ConcurrentSkipListMap map = map5(); @@ -119,7 +130,6 @@ public class ConcurrentSkipListMapTest e assertEquals(five, map.lastKey()); } - /** * keySet.toArray returns contains all keys */ @@ -176,7 +186,7 @@ public class ConcurrentSkipListMapTest e last = k; ++count; } - assertEquals(count ,5); + assertEquals(5, count); } /** @@ -195,7 +205,7 @@ public class ConcurrentSkipListMapTest e last = k; ++count; } - assertEquals(count ,5); + assertEquals(5, count); } /** @@ -214,7 +224,7 @@ public class ConcurrentSkipListMapTest e last = k; ++count; } - assertEquals(count, 5); + assertEquals(5, count); } /** @@ -233,7 +243,7 @@ public class ConcurrentSkipListMapTest e last = k; ++count; } - assertEquals(count, 5); + assertEquals(5, count); } /** @@ -382,7 +392,6 @@ public class ConcurrentSkipListMapTest e assertEquals("Z", map.get(one)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -403,7 +412,6 @@ public class ConcurrentSkipListMapTest e assertEquals("Z", map.get(one)); } - /** * remove removes the correct key-value pair from the map */ @@ -505,7 +513,7 @@ public class ConcurrentSkipListMapTest e * lowerEntry, higherEntry, ceilingEntry, and floorEntry return * immutable entries */ - public void testEntryImmutablity() { + public void testEntryImmutability() { ConcurrentSkipListMap map = map5(); Map.Entry e = map.lowerEntry(three); assertEquals(two, e.getKey()); @@ -533,8 +541,6 @@ public class ConcurrentSkipListMapTest e } catch (UnsupportedOperationException success) {} } - - /** * lowerKey returns preceding element */ @@ -678,7 +684,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap 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))); } } @@ -717,7 +723,6 @@ public class ConcurrentSkipListMapTest e } catch (NullPointerException success) {} } - /** * put(null,x) throws NPE */ @@ -799,23 +804,16 @@ public class ConcurrentSkipListMapTest e * A deserialized map equals original */ public void testSerialization() throws Exception { - ConcurrentSkipListMap 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)); - ConcurrentSkipListMap r = (ConcurrentSkipListMap)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 */ @@ -1000,7 +998,7 @@ public class ConcurrentSkipListMapTest e static NavigableMap newMap(Class cl) throws Exception { NavigableMap result = (NavigableMap) cl.newInstance(); - assertEquals(result.size(), 0); + assertEquals(0, result.size()); assertFalse(result.keySet().iterator().hasNext()); return result; } @@ -1161,7 +1159,7 @@ public class ConcurrentSkipListMapTest e */ void check(NavigableMap map, final int min, final int max, final boolean ascending) { - class ReferenceSet { + class ReferenceSet { int lower(int key) { return ascending ? lowerAscending(key) : higherAscending(key); } @@ -1227,7 +1225,7 @@ public class ConcurrentSkipListMapTest e if (bsContainsI) size++; } - assertEquals(map.size(), size); + assertEquals(size, map.size()); // Test contents using contains keySet iterator int size2 = 0;