--- jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java 2009/11/21 10:25:05 1.10 +++ jsr166/src/test/tck/ConcurrentSkipListSubMapTest.java 2011/05/27 19:21:27 1.18 @@ -1,7 +1,7 @@ /* * 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.*; @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListSubMapTest 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(ConcurrentSkipListSubMapTest.class); @@ -64,7 +64,7 @@ public class ConcurrentSkipListSubMapTes } /** - * clear removes all pairs + * clear removes all pairs */ public void testClear() { ConcurrentNavigableMap map = map5(); @@ -72,9 +72,8 @@ public class ConcurrentSkipListSubMapTes assertEquals(map.size(), 0); } - /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testEquals() { ConcurrentNavigableMap map1 = map5(); @@ -87,7 +86,7 @@ public class ConcurrentSkipListSubMapTes } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testContainsKey() { ConcurrentNavigableMap map = map5(); @@ -96,7 +95,7 @@ public class ConcurrentSkipListSubMapTes } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testContainsValue() { ConcurrentNavigableMap map = map5(); @@ -105,8 +104,8 @@ public class ConcurrentSkipListSubMapTes } /** - * 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() { ConcurrentNavigableMap map = map5(); @@ -116,7 +115,7 @@ public class ConcurrentSkipListSubMapTes } /** - * 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() { ConcurrentNavigableMap empty = map0(); @@ -126,7 +125,7 @@ public class ConcurrentSkipListSubMapTes } /** - * firstKey returns first key + * firstKey returns first key */ public void testFirstKey() { ConcurrentNavigableMap map = map5(); @@ -134,16 +133,15 @@ public class ConcurrentSkipListSubMapTes } /** - * lastKey returns last key + * lastKey returns last key */ public void testLastKey() { ConcurrentNavigableMap map = map5(); assertEquals(five, map.lastKey()); } - /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testKeySet() { ConcurrentNavigableMap map = map5(); @@ -157,7 +155,7 @@ public class ConcurrentSkipListSubMapTes } /** - * keySet is ordered + * keySet is ordered */ public void testKeySetOrder() { ConcurrentNavigableMap map = map5(); @@ -187,7 +185,7 @@ public class ConcurrentSkipListSubMapTes } /** - * keySet.toArray returns contains all keys + * keySet.toArray returns contains all keys */ public void testKeySetToArray() { ConcurrentNavigableMap map = map5(); @@ -200,7 +198,7 @@ public class ConcurrentSkipListSubMapTes } /** - * descendingkeySet.toArray returns contains all keys + * descendingkeySet.toArray returns contains all keys */ public void testDescendingKeySetToArray() { ConcurrentNavigableMap map = map5(); @@ -213,7 +211,7 @@ public class ConcurrentSkipListSubMapTes } /** - * Values.toArray contains all values + * Values.toArray contains all values */ public void testValuesToArray() { ConcurrentNavigableMap map = map5(); @@ -228,7 +226,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -249,7 +246,7 @@ public class ConcurrentSkipListSubMapTes } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testPutAll() { ConcurrentNavigableMap empty = map0(); @@ -264,7 +261,7 @@ public class ConcurrentSkipListSubMapTes } /** - * putIfAbsent works when the given key is not present + * putIfAbsent works when the given key is not present */ public void testPutIfAbsent() { ConcurrentNavigableMap map = map5(); @@ -273,7 +270,7 @@ public class ConcurrentSkipListSubMapTes } /** - * 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() { ConcurrentNavigableMap map = map5(); @@ -281,7 +278,7 @@ public class ConcurrentSkipListSubMapTes } /** - * replace fails when the given key is not present + * replace fails when the given key is not present */ public void testReplace() { ConcurrentNavigableMap map = map5(); @@ -290,7 +287,7 @@ public class ConcurrentSkipListSubMapTes } /** - * replace succeeds if the key is already present + * replace succeeds if the key is already present */ public void testReplace2() { ConcurrentNavigableMap map = map5(); @@ -298,7 +295,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(one)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -319,9 +315,8 @@ public class ConcurrentSkipListSubMapTes 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() { ConcurrentNavigableMap map = map5(); @@ -343,7 +338,6 @@ public class ConcurrentSkipListSubMapTes map.remove(four, "A"); assertEquals(4, map.size()); assertTrue(map.containsKey(four)); - } /** @@ -362,7 +356,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -381,7 +374,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.higherEntry(six); assertNull(e4); - } /** @@ -400,7 +392,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -419,7 +410,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.ceilingEntry(six); assertNull(e4); - } /** @@ -444,8 +434,7 @@ public class ConcurrentSkipListSubMapTes try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -472,14 +461,13 @@ public class ConcurrentSkipListSubMapTes 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() { ConcurrentNavigableMap map = map5(); @@ -495,7 +483,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))); } } @@ -509,7 +497,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -520,7 +508,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.containsKey(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -531,10 +519,9 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map0(); c.containsValue(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } - /** * put(null,x) throws NPE */ @@ -543,7 +530,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.put(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -554,7 +541,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.putIfAbsent(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -565,7 +552,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.replace(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -576,7 +563,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.replace(null, one, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -587,7 +574,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.remove(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -598,7 +585,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = map5(); c.remove(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -620,8 +607,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(r.equals(q)); } - - /** * subMap returns map with keys in requested range */ @@ -651,7 +636,7 @@ public class ConcurrentSkipListSubMapTes 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()); } @@ -679,7 +664,7 @@ public class ConcurrentSkipListSubMapTes 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()); } @@ -751,14 +736,14 @@ public class ConcurrentSkipListSubMapTes SortedMap ssm = sm.tailMap(four); 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()); } /** - * clear removes all pairs + * clear removes all pairs */ public void testDescendingClear() { ConcurrentNavigableMap map = dmap5(); @@ -766,9 +751,8 @@ public class ConcurrentSkipListSubMapTes assertEquals(map.size(), 0); } - /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testDescendingEquals() { ConcurrentNavigableMap map1 = dmap5(); @@ -781,7 +765,7 @@ public class ConcurrentSkipListSubMapTes } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testDescendingContainsKey() { ConcurrentNavigableMap map = dmap5(); @@ -790,7 +774,7 @@ public class ConcurrentSkipListSubMapTes } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testDescendingContainsValue() { ConcurrentNavigableMap map = dmap5(); @@ -799,8 +783,8 @@ public class ConcurrentSkipListSubMapTes } /** - * 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 testDescendingGet() { ConcurrentNavigableMap map = dmap5(); @@ -810,7 +794,7 @@ public class ConcurrentSkipListSubMapTes } /** - * isEmpty is true of empty map and false for non-empty + * isEmpty is true of empty map and false for non-empty */ public void testDescendingIsEmpty() { ConcurrentNavigableMap empty = dmap0(); @@ -820,7 +804,7 @@ public class ConcurrentSkipListSubMapTes } /** - * firstKey returns first key + * firstKey returns first key */ public void testDescendingFirstKey() { ConcurrentNavigableMap map = dmap5(); @@ -828,16 +812,15 @@ public class ConcurrentSkipListSubMapTes } /** - * lastKey returns last key + * lastKey returns last key */ public void testDescendingLastKey() { ConcurrentNavigableMap map = dmap5(); assertEquals(m5, map.lastKey()); } - /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testDescendingKeySet() { ConcurrentNavigableMap map = dmap5(); @@ -851,7 +834,7 @@ public class ConcurrentSkipListSubMapTes } /** - * keySet is ordered + * keySet is ordered */ public void testDescendingKeySetOrder() { ConcurrentNavigableMap map = dmap5(); @@ -881,7 +864,7 @@ public class ConcurrentSkipListSubMapTes } /** - * keySet.toArray returns contains all keys + * keySet.toArray returns contains all keys */ public void testDescendingAscendingKeySetToArray() { ConcurrentNavigableMap map = dmap5(); @@ -894,7 +877,7 @@ public class ConcurrentSkipListSubMapTes } /** - * descendingkeySet.toArray returns contains all keys + * descendingkeySet.toArray returns contains all keys */ public void testDescendingDescendingKeySetToArray() { ConcurrentNavigableMap map = dmap5(); @@ -907,7 +890,7 @@ public class ConcurrentSkipListSubMapTes } /** - * Values.toArray contains all values + * Values.toArray contains all values */ public void testDescendingValuesToArray() { ConcurrentNavigableMap map = dmap5(); @@ -922,7 +905,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(s.contains("E")); } - /** * entrySet contains all pairs */ @@ -943,7 +925,7 @@ public class ConcurrentSkipListSubMapTes } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testDescendingPutAll() { ConcurrentNavigableMap empty = dmap0(); @@ -958,7 +940,7 @@ public class ConcurrentSkipListSubMapTes } /** - * putIfAbsent works when the given key is not present + * putIfAbsent works when the given key is not present */ public void testDescendingPutIfAbsent() { ConcurrentNavigableMap map = dmap5(); @@ -967,7 +949,7 @@ public class ConcurrentSkipListSubMapTes } /** - * 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 testDescendingPutIfAbsent2() { ConcurrentNavigableMap map = dmap5(); @@ -975,7 +957,7 @@ public class ConcurrentSkipListSubMapTes } /** - * replace fails when the given key is not present + * replace fails when the given key is not present */ public void testDescendingReplace() { ConcurrentNavigableMap map = dmap5(); @@ -984,7 +966,7 @@ public class ConcurrentSkipListSubMapTes } /** - * replace succeeds if the key is already present + * replace succeeds if the key is already present */ public void testDescendingReplace2() { ConcurrentNavigableMap map = dmap5(); @@ -992,7 +974,6 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(m1)); } - /** * replace value fails when the given key not mapped to expected value */ @@ -1013,9 +994,8 @@ public class ConcurrentSkipListSubMapTes assertEquals("Z", map.get(m1)); } - /** - * remove removes the correct key-value pair from the map + * remove removes the correct key-value pair from the map */ public void testDescendingRemove() { ConcurrentNavigableMap map = dmap5(); @@ -1037,7 +1017,6 @@ public class ConcurrentSkipListSubMapTes map.remove(m4, "A"); assertEquals(4, map.size()); assertTrue(map.containsKey(m4)); - } /** @@ -1056,7 +1035,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -1075,7 +1053,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.higherEntry(m6); assertNull(e4); - } /** @@ -1094,7 +1071,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -1113,7 +1089,6 @@ public class ConcurrentSkipListSubMapTes Map.Entry e4 = map.ceilingEntry(m6); assertNull(e4); - } /** @@ -1138,8 +1113,7 @@ public class ConcurrentSkipListSubMapTes try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -1166,14 +1140,13 @@ public class ConcurrentSkipListSubMapTes 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 testDescendingSize() { ConcurrentNavigableMap map = dmap5(); @@ -1189,32 +1162,32 @@ 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))); } } // Exception testDescendings /** - * get(null) of nm1mpty map throws NPE + * get(null) of empty map throws NPE */ public void testDescendingGet_NullPointerException() { try { ConcurrentNavigableMap c = dmap5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** - * containsKey(null) of nm1mpty map throws NPE + * containsKey(null) of empty map throws NPE */ public void testDescendingContainsKey_NullPointerException() { try { ConcurrentNavigableMap c = dmap5(); c.containsKey(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1225,10 +1198,9 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap0(); c.containsValue(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } - /** * put(null,x) throws NPE */ @@ -1237,7 +1209,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.put(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1248,7 +1220,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.putIfAbsent(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1259,7 +1231,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.replace(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1270,7 +1242,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.replace(null, m1, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1281,7 +1253,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.remove(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1292,7 +1264,7 @@ public class ConcurrentSkipListSubMapTes ConcurrentNavigableMap c = dmap5(); c.remove(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -1314,7 +1286,6 @@ public class ConcurrentSkipListSubMapTes assertTrue(r.equals(q)); } - /** * subMap returns map with keys in requested range */ @@ -1344,7 +1315,7 @@ public class ConcurrentSkipListSubMapTes assertEquals(1, sm.size()); assertEquals(m3, sm.firstKey()); assertEquals(m3, sm.lastKey()); - assertTrue(sm.remove(m3) != null); + assertEquals("C", sm.remove(m3)); assertTrue(sm.isEmpty()); assertEquals(3, map.size()); } @@ -1372,7 +1343,7 @@ public class ConcurrentSkipListSubMapTes assertEquals(4, map.size()); assertEquals(0, sm.size()); assertTrue(sm.isEmpty()); - assertTrue(sm.remove(m3) == null); + assertSame(sm.remove(m3), null); assertEquals(4, map.size()); } @@ -1444,7 +1415,7 @@ public class ConcurrentSkipListSubMapTes SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); - assertTrue(ssm.remove(m4) != null); + assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size());