--- jsr166/src/test/tck/ConcurrentHashMapTest.java 2010/08/25 00:07:03 1.21 +++ jsr166/src/test/tck/ConcurrentHashMapTest.java 2011/05/31 16:16:23 1.25 @@ -1,16 +1,14 @@ /* * 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/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ import junit.framework.*; import java.util.*; -import java.util.concurrent.*; -import java.util.Enumeration; -import java.io.*; +import java.util.concurrent.ConcurrentHashMap; public class ConcurrentHashMapTest extends JSR166TestCase { public static void main(String[] args) { @@ -37,7 +35,7 @@ public class ConcurrentHashMapTest exten } /** - * clear removes all pairs + * clear removes all pairs */ public void testClear() { ConcurrentHashMap map = map5(); @@ -46,7 +44,7 @@ public class ConcurrentHashMapTest exten } /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testEquals() { ConcurrentHashMap map1 = map5(); @@ -59,7 +57,7 @@ public class ConcurrentHashMapTest exten } /** - * contains returns true for contained value + * contains returns true for contained value */ public void testContains() { ConcurrentHashMap map = map5(); @@ -68,7 +66,7 @@ public class ConcurrentHashMapTest exten } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testContainsKey() { ConcurrentHashMap map = map5(); @@ -77,7 +75,7 @@ public class ConcurrentHashMapTest exten } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testContainsValue() { ConcurrentHashMap map = map5(); @@ -86,8 +84,8 @@ public class ConcurrentHashMapTest exten } /** - * enumeration returns an enumeration containing the correct - * elements + * enumeration returns an enumeration containing the correct + * elements */ public void testEnumeration() { ConcurrentHashMap map = map5(); @@ -101,8 +99,8 @@ public class ConcurrentHashMapTest exten } /** - * get returns the correct element at the given key, - * or null if not present + * get returns the correct element at the given key, + * or null if not present */ public void testGet() { ConcurrentHashMap map = map5(); @@ -112,7 +110,7 @@ public class ConcurrentHashMapTest exten } /** - * isEmpty is true of empty map and false for non-empty + * isEmpty is true of empty map and false for non-empty */ public void testIsEmpty() { ConcurrentHashMap empty = new ConcurrentHashMap(); @@ -122,7 +120,7 @@ public class ConcurrentHashMapTest exten } /** - * keys returns an enumeration containing all the keys from the map + * keys returns an enumeration containing all the keys from the map */ public void testKeys() { ConcurrentHashMap map = map5(); @@ -136,7 +134,7 @@ public class ConcurrentHashMapTest exten } /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testKeySet() { ConcurrentHashMap map = map5(); @@ -150,7 +148,7 @@ public class ConcurrentHashMapTest exten } /** - * keySet.toArray returns contains all keys + * keySet.toArray returns contains all keys */ public void testKeySetToArray() { ConcurrentHashMap map = map5(); @@ -163,7 +161,7 @@ public class ConcurrentHashMapTest exten } /** - * Values.toArray contains all values + * Values.toArray contains all values */ public void testValuesToArray() { ConcurrentHashMap map = map5(); @@ -179,7 +177,7 @@ public class ConcurrentHashMapTest exten } /** - * entrySet.toArray contains all entries + * entrySet.toArray contains all entries */ public void testEntrySetToArray() { ConcurrentHashMap map = map5(); @@ -226,7 +224,7 @@ public class ConcurrentHashMapTest exten } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testPutAll() { ConcurrentHashMap empty = new ConcurrentHashMap(); @@ -241,7 +239,7 @@ public class ConcurrentHashMapTest exten } /** - * putIfAbsent works when the given key is not present + * putIfAbsent works when the given key is not present */ public void testPutIfAbsent() { ConcurrentHashMap map = map5(); @@ -250,7 +248,7 @@ public class ConcurrentHashMapTest exten } /** - * putIfAbsent does not add the pair if the key is already present + * putIfAbsent does not add the pair if the key is already present */ public void testPutIfAbsent2() { ConcurrentHashMap map = map5(); @@ -258,7 +256,7 @@ public class ConcurrentHashMapTest exten } /** - * replace fails when the given key is not present + * replace fails when the given key is not present */ public void testReplace() { ConcurrentHashMap map = map5(); @@ -267,7 +265,7 @@ public class ConcurrentHashMapTest exten } /** - * replace succeeds if the key is already present + * replace succeeds if the key is already present */ public void testReplace2() { ConcurrentHashMap map = map5(); @@ -275,7 +273,6 @@ public class ConcurrentHashMapTest exten assertEquals("Z", map.get(one)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -296,9 +293,8 @@ public class ConcurrentHashMapTest exten assertEquals("Z", map.get(one)); } - /** - * remove removes the correct key-value pair from the map + * remove removes the correct key-value pair from the map */ public void testRemove() { ConcurrentHashMap map = map5(); @@ -321,7 +317,7 @@ public class ConcurrentHashMapTest exten } /** - * size returns the correct values + * size returns the correct values */ public void testSize() { ConcurrentHashMap map = map5(); @@ -337,7 +333,7 @@ public class ConcurrentHashMapTest exten ConcurrentHashMap 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))); } } @@ -483,7 +479,6 @@ public class ConcurrentHashMapTest exten } catch (NullPointerException success) {} } - /** * replace(x, null) throws NPE */ @@ -517,7 +512,6 @@ public class ConcurrentHashMapTest exten } catch (NullPointerException success) {} } - /** * remove(null) throws NPE */ @@ -555,22 +549,15 @@ public class ConcurrentHashMapTest exten * A deserialized map equals original */ public void testSerialization() throws Exception { - ConcurrentHashMap q = map5(); + Map x = map5(); + Map 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)); - ConcurrentHashMap r = (ConcurrentHashMap)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, y); + assertEquals(y, x); } - /** * SetValue of an EntrySet entry sets value in the map. */