--- jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2009/11/21 10:25:05 1.13 +++ jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2010/10/09 19:30:34 1.20 @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListMapTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(ConcurrentSkipListMapTest.class); @@ -34,7 +34,7 @@ public class ConcurrentSkipListMapTest e } /** - * clear removes all pairs + * clear removes all pairs */ public void testClear() { ConcurrentSkipListMap map = map5(); @@ -52,7 +52,7 @@ public class ConcurrentSkipListMapTest e } /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testEquals() { ConcurrentSkipListMap map1 = map5(); @@ -65,7 +65,7 @@ public class ConcurrentSkipListMapTest e } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testContainsKey() { ConcurrentSkipListMap map = map5(); @@ -74,7 +74,7 @@ public class ConcurrentSkipListMapTest e } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testContainsValue() { ConcurrentSkipListMap map = map5(); @@ -83,8 +83,8 @@ public class ConcurrentSkipListMapTest e } /** - * 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() { ConcurrentSkipListMap map = map5(); @@ -94,7 +94,7 @@ public class ConcurrentSkipListMapTest e } /** - * 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() { ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); @@ -104,7 +104,7 @@ public class ConcurrentSkipListMapTest e } /** - * firstKey returns first key + * firstKey returns first key */ public void testFirstKey() { ConcurrentSkipListMap map = map5(); @@ -112,7 +112,7 @@ public class ConcurrentSkipListMapTest e } /** - * lastKey returns last key + * lastKey returns last key */ public void testLastKey() { ConcurrentSkipListMap map = map5(); @@ -121,7 +121,7 @@ public class ConcurrentSkipListMapTest e /** - * keySet.toArray returns contains all keys + * keySet.toArray returns contains all keys */ public void testKeySetToArray() { ConcurrentSkipListMap map = map5(); @@ -134,7 +134,7 @@ public class ConcurrentSkipListMapTest e } /** - * descendingkeySet.toArray returns contains all keys + * descendingkeySet.toArray returns contains all keys */ public void testDescendingKeySetToArray() { ConcurrentSkipListMap map = map5(); @@ -147,7 +147,7 @@ public class ConcurrentSkipListMapTest e } /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testKeySet() { ConcurrentSkipListMap map = map5(); @@ -161,7 +161,7 @@ public class ConcurrentSkipListMapTest e } /** - * keySet is ordered + * keySet is ordered */ public void testKeySetOrder() { ConcurrentSkipListMap map = map5(); @@ -199,7 +199,7 @@ public class ConcurrentSkipListMapTest e } /** - * descendingKeySet is ordered + * descendingKeySet is ordered */ public void testDescendingKeySetOrder() { ConcurrentSkipListMap map = map5(); @@ -218,7 +218,7 @@ public class ConcurrentSkipListMapTest e } /** - * descending iterator of descendingKeySet is ordered + * descending iterator of descendingKeySet is ordered */ public void testDescendingKeySetDescendingIteratorOrder() { ConcurrentSkipListMap map = map5(); @@ -237,7 +237,7 @@ public class ConcurrentSkipListMapTest e } /** - * Values.toArray contains all values + * Values.toArray contains all values */ public void testValuesToArray() { ConcurrentSkipListMap map = map5(); @@ -305,7 +305,7 @@ public class ConcurrentSkipListMapTest e } /** - * entrySet.toArray contains all entries + * entrySet.toArray contains all entries */ public void testEntrySetToArray() { ConcurrentSkipListMap map = map5(); @@ -319,7 +319,7 @@ public class ConcurrentSkipListMapTest e } /** - * descendingEntrySet.toArray contains all entries + * descendingEntrySet.toArray contains all entries */ public void testDescendingEntrySetToArray() { ConcurrentSkipListMap map = map5(); @@ -333,7 +333,7 @@ public class ConcurrentSkipListMapTest e } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testPutAll() { ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); @@ -348,7 +348,7 @@ public class ConcurrentSkipListMapTest e } /** - * putIfAbsent works when the given key is not present + * putIfAbsent works when the given key is not present */ public void testPutIfAbsent() { ConcurrentSkipListMap map = map5(); @@ -357,7 +357,7 @@ public class ConcurrentSkipListMapTest e } /** - * 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() { ConcurrentSkipListMap map = map5(); @@ -365,7 +365,7 @@ public class ConcurrentSkipListMapTest e } /** - * replace fails when the given key is not present + * replace fails when the given key is not present */ public void testReplace() { ConcurrentSkipListMap map = map5(); @@ -374,7 +374,7 @@ public class ConcurrentSkipListMapTest e } /** - * replace succeeds if the key is already present + * replace succeeds if the key is already present */ public void testReplace2() { ConcurrentSkipListMap map = map5(); @@ -405,7 +405,7 @@ public class ConcurrentSkipListMapTest e /** - * remove removes the correct key-value pair from the map + * remove removes the correct key-value pair from the map */ public void testRemove() { ConcurrentSkipListMap map = map5(); @@ -427,7 +427,6 @@ public class ConcurrentSkipListMapTest e map.remove(four, "A"); assertEquals(4, map.size()); assertTrue(map.containsKey(four)); - } /** @@ -446,7 +445,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -465,7 +463,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.higherEntry(six); assertNull(e4); - } /** @@ -484,7 +481,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -503,12 +499,11 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.ceilingEntry(six); assertNull(e4); - } /** * lowerEntry, higherEntry, ceilingEntry, and floorEntry return - * imutable entries + * immutable entries */ public void testEntryImmutablity() { ConcurrentSkipListMap map = map5(); @@ -516,25 +511,25 @@ public class ConcurrentSkipListMapTest e assertEquals(two, e.getKey()); try { e.setValue("X"); - fail(); + shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.higherEntry(zero); assertEquals(one, e.getKey()); try { e.setValue("X"); - fail(); + shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.floorEntry(one); assertEquals(one, e.getKey()); try { e.setValue("X"); - fail(); + shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.ceilingEntry(five); assertEquals(five, e.getKey()); try { e.setValue("X"); - fail(); + shouldThrow(); } catch (UnsupportedOperationException success) {} } @@ -556,7 +551,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.lowerKey(zero); assertNull(e4); - } /** @@ -575,7 +569,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.higherKey(six); assertNull(e4); - } /** @@ -594,7 +587,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.floorKey(zero); assertNull(e4); - } /** @@ -613,7 +605,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.ceilingKey(six); assertNull(e4); - } /** @@ -638,8 +629,7 @@ public class ConcurrentSkipListMapTest e try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -666,14 +656,13 @@ public class ConcurrentSkipListMapTest e try { e.setValue("E"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollLastEntry(); assertNull(e); } /** - * size returns the correct values + * size returns the correct values */ public void testSize() { ConcurrentSkipListMap map = map5(); @@ -703,7 +692,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -714,7 +703,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.containsKey(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -725,7 +714,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = new ConcurrentSkipListMap(); c.containsValue(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } @@ -737,7 +726,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.put(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -748,7 +737,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.putIfAbsent(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -759,7 +748,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -770,7 +759,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, one, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -782,7 +771,7 @@ public class ConcurrentSkipListMapTest e c.put("sadsdf", "asdads"); c.remove(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -794,20 +783,16 @@ public class ConcurrentSkipListMapTest e c.put("sadsdf", "asdads"); c.remove(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** * remove(x, null) returns false */ public void testRemove3() { - try { - ConcurrentSkipListMap c = new ConcurrentSkipListMap(); - c.put("sadsdf", "asdads"); - assertFalse(c.remove("sadsdf", null)); - } catch (NullPointerException e) { - fail(); - } + ConcurrentSkipListMap c = new ConcurrentSkipListMap(); + c.put("sadsdf", "asdads"); + assertFalse(c.remove("sadsdf", null)); } /** @@ -867,7 +852,7 @@ public class ConcurrentSkipListMapTest e assertEquals(1, sm.size()); assertEquals(three, sm.firstKey()); assertEquals(three, sm.lastKey()); - assertTrue(sm.remove(three) != null); + assertEquals("C", sm.remove(three)); assertTrue(sm.isEmpty()); assertEquals(3, map.size()); } @@ -900,7 +885,7 @@ public class ConcurrentSkipListMapTest e assertEquals(4, map.size()); assertEquals(0, sm.size()); assertTrue(sm.isEmpty()); - assertTrue(sm.remove(three) == null); + assertSame(sm.remove(three), null); assertEquals(4, map.size()); } @@ -982,7 +967,7 @@ public class ConcurrentSkipListMapTest e NavigableMap ssm = sm.tailMap(four, true); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); - assertTrue(ssm.remove(four) != null); + assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); @@ -994,7 +979,7 @@ public class ConcurrentSkipListMapTest e /** * Submaps of submaps subdivide correctly */ - public void testRecursiveSubMaps() { + public void testRecursiveSubMaps() throws Exception { int mapSize = 1000; Class cl = ConcurrentSkipListMap.class; NavigableMap map = newMap(cl); @@ -1012,13 +997,9 @@ public class ConcurrentSkipListMapTest e 0, mapSize - 1, true); } - static NavigableMap newMap(Class cl) { - NavigableMap result = null; - try { - result = (NavigableMap) cl.newInstance(); - } catch (Exception e) { - fail(); - } + static NavigableMap newMap(Class cl) throws Exception { + NavigableMap result = + (NavigableMap) cl.newInstance(); assertEquals(result.size(), 0); assertFalse(result.keySet().iterator().hasNext()); return result; @@ -1081,10 +1062,8 @@ public class ConcurrentSkipListMapTest e } else { try { map.put(key, 2 * key); - fail(); - } catch (IllegalArgumentException e) { - // expected - } + shouldThrow(); + } catch (IllegalArgumentException success) {} } } } @@ -1213,7 +1192,7 @@ public class ConcurrentSkipListMapTest e // BitSet should support this! Test would run much faster while (key >= min) { if (bs.get(key)) - return(key); + return key; key--; } return -1; @@ -1279,16 +1258,12 @@ public class ConcurrentSkipListMapTest e assertEq(rs.last(), -1); try { map.firstKey(); - fail(); - } catch (NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} try { map.lastKey(); - fail(); - } catch (NoSuchElementException e) { - // expected - } + shouldThrow(); + } catch (NoSuchElementException success) {} } }