--- jsr166/src/test/tck/ConcurrentHashMapTest.java 2003/11/28 12:38:08 1.6 +++ jsr166/src/test/tck/ConcurrentHashMapTest.java 2004/07/02 10:26:28 1.11 @@ -1,8 +1,9 @@ /* - * Written by members of JCP JSR-166 Expert Group and released to the - * public domain. Use, modify, and redistribute this code in any way - * without acknowledgement. Other contributors include Andrew Wright, - * Jeffrey Hayes, Pat Fischer, Mike Judd. + * 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 + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import junit.framework.*; @@ -80,8 +81,8 @@ public class ConcurrentHashMapTest exten */ public void testContainsValue() { ConcurrentHashMap map = map5(); - assertTrue(map.contains("A")); - assertFalse(map.contains("Z")); + assertTrue(map.containsValue("A")); + assertFalse(map.containsValue("Z")); } /** @@ -100,15 +101,6 @@ public class ConcurrentHashMapTest exten } /** - * Clone creates an equal map - */ - public void testClone() { - ConcurrentHashMap map = map5(); - ConcurrentHashMap m2 = (ConcurrentHashMap)(map.clone()); - assertEquals(map, m2); - } - - /** * get returns the correct element at the given key, * or null if not present */ @@ -210,8 +202,8 @@ public class ConcurrentHashMapTest exten */ public void testPutIfAbsent() { ConcurrentHashMap map = map5(); - map.putIfAbsent(new Integer(6), "Z"); - assertTrue(map.containsKey(new Integer(6))); + map.putIfAbsent(six, "Z"); + assertTrue(map.containsKey(six)); } /** @@ -223,6 +215,46 @@ public class ConcurrentHashMapTest exten } /** + * replace fails when the given key is not present + */ + public void testReplace() { + ConcurrentHashMap map = map5(); + assertNull(map.replace(six, "Z")); + assertFalse(map.containsKey(six)); + } + + /** + * replace succeeds if the key is already present + */ + public void testReplace2() { + ConcurrentHashMap map = map5(); + assertNotNull(map.replace(one, "Z")); + assertEquals("Z", map.get(one)); + } + + + /** + * replace value fails when the given key not mapped to expected value + */ + public void testReplaceValue() { + ConcurrentHashMap map = map5(); + assertEquals("A", map.get(one)); + assertFalse(map.replace(one, "Z", "Z")); + assertEquals("A", map.get(one)); + } + + /** + * replace value succeeds when the given key mapped to expected value + */ + public void testReplaceValue2() { + ConcurrentHashMap map = map5(); + assertEquals("A", map.get(one)); + assertTrue(map.replace(one, "A", "Z")); + assertEquals("Z", map.get(one)); + } + + + /** * remove removes the correct key-value pair from the map */ public void testRemove() { @@ -377,6 +409,28 @@ public class ConcurrentHashMapTest exten } /** + * replace(null, x) throws NPE + */ + public void testReplace_NullPointerException() { + try { + ConcurrentHashMap c = new ConcurrentHashMap(5); + c.replace(null, "whatever"); + shouldThrow(); + } catch(NullPointerException e){} + } + + /** + * replace(null, x, y) throws NPE + */ + public void testReplaceValue_NullPointerException() { + try { + ConcurrentHashMap c = new ConcurrentHashMap(5); + c.replace(null, one, "whatever"); + shouldThrow(); + } catch(NullPointerException e){} + } + + /** * putIfAbsent(x, null) throws NPE */ public void testPutIfAbsent2_NullPointerException() { @@ -386,6 +440,40 @@ public class ConcurrentHashMapTest exten shouldThrow(); } catch(NullPointerException e){} } + + + /** + * replace(x, null) throws NPE + */ + public void testReplace2_NullPointerException() { + try { + ConcurrentHashMap c = new ConcurrentHashMap(5); + c.replace("whatever", null); + shouldThrow(); + } catch(NullPointerException e){} + } + + /** + * replace(x, null, y) throws NPE + */ + public void testReplaceValue2_NullPointerException() { + try { + ConcurrentHashMap c = new ConcurrentHashMap(5); + c.replace("whatever", null, "A"); + shouldThrow(); + } catch(NullPointerException e){} + } + + /** + * replace(x, y, null) throws NPE + */ + public void testReplaceValue3_NullPointerException() { + try { + ConcurrentHashMap c = new ConcurrentHashMap(5); + c.replace("whatever", one, null); + shouldThrow(); + } catch(NullPointerException e){} + } /**