--- jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2006/04/20 20:35:00 1.7 +++ jsr166/src/test/tck/ConcurrentSkipListMapTest.java 2010/08/25 00:07:03 1.18 @@ -11,26 +11,26 @@ 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); + return new TestSuite(ConcurrentSkipListMapTest.class); } /** * Create a map from Integers 1-5 to Strings "A"-"E". */ - private static ConcurrentSkipListMap map5() { - ConcurrentSkipListMap map = new ConcurrentSkipListMap(); + private static ConcurrentSkipListMap map5() { + ConcurrentSkipListMap map = new ConcurrentSkipListMap(); assertTrue(map.isEmpty()); - map.put(one, "A"); - map.put(five, "E"); - map.put(three, "C"); - map.put(two, "B"); - map.put(four, "D"); + map.put(one, "A"); + map.put(five, "E"); + map.put(three, "C"); + map.put(two, "B"); + map.put(four, "D"); assertFalse(map.isEmpty()); assertEquals(5, map.size()); - return map; + return map; } /** @@ -38,12 +38,12 @@ public class ConcurrentSkipListMapTest e */ public void testClear() { ConcurrentSkipListMap map = map5(); - map.clear(); - assertEquals(map.size(), 0); + map.clear(); + assertEquals(map.size(), 0); } /** - * + * */ public void testConstructFromSorted() { ConcurrentSkipListMap map = map5(); @@ -59,7 +59,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap map2 = map5(); assertEquals(map1, map2); assertEquals(map2, map1); - map1.clear(); + map1.clear(); assertFalse(map1.equals(map2)); assertFalse(map2.equals(map1)); } @@ -69,7 +69,7 @@ public class ConcurrentSkipListMapTest e */ public void testContainsKey() { ConcurrentSkipListMap map = map5(); - assertTrue(map.containsKey(one)); + assertTrue(map.containsKey(one)); assertFalse(map.containsKey(zero)); } @@ -78,7 +78,7 @@ public class ConcurrentSkipListMapTest e */ public void testContainsValue() { ConcurrentSkipListMap map = map5(); - assertTrue(map.containsValue("A")); + assertTrue(map.containsValue("A")); assertFalse(map.containsValue("Z")); } @@ -88,7 +88,7 @@ public class ConcurrentSkipListMapTest e */ public void testGet() { ConcurrentSkipListMap map = map5(); - assertEquals("A", (String)map.get(one)); + assertEquals("A", (String)map.get(one)); ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); assertNull(empty.get(one)); } @@ -99,7 +99,7 @@ public class ConcurrentSkipListMapTest e public void testIsEmpty() { ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); ConcurrentSkipListMap map = map5(); - assertTrue(empty.isEmpty()); + assertTrue(empty.isEmpty()); assertFalse(map.isEmpty()); } @@ -108,7 +108,7 @@ public class ConcurrentSkipListMapTest e */ public void testFirstKey() { ConcurrentSkipListMap map = map5(); - assertEquals(one, map.firstKey()); + assertEquals(one, map.firstKey()); } /** @@ -116,7 +116,7 @@ public class ConcurrentSkipListMapTest e */ public void testLastKey() { ConcurrentSkipListMap map = map5(); - assertEquals(five, map.lastKey()); + assertEquals(five, map.lastKey()); } @@ -125,10 +125,10 @@ public class ConcurrentSkipListMapTest e */ public void testKeySetToArray() { ConcurrentSkipListMap map = map5(); - Set s = map.keySet(); + Set s = map.keySet(); Object[] ar = s.toArray(); assertTrue(s.containsAll(Arrays.asList(ar))); - assertEquals(5, ar.length); + assertEquals(5, ar.length); ar[0] = m10; assertFalse(s.containsAll(Arrays.asList(ar))); } @@ -138,9 +138,9 @@ public class ConcurrentSkipListMapTest e */ public void testDescendingKeySetToArray() { ConcurrentSkipListMap map = map5(); - Set s = map.descendingKeySet(); + Set s = map.descendingKeySet(); Object[] ar = s.toArray(); - assertEquals(5, ar.length); + assertEquals(5, ar.length); assertTrue(s.containsAll(Arrays.asList(ar))); ar[0] = m10; assertFalse(s.containsAll(Arrays.asList(ar))); @@ -151,13 +151,13 @@ public class ConcurrentSkipListMapTest e */ public void testKeySet() { ConcurrentSkipListMap map = map5(); - Set s = map.keySet(); - assertEquals(5, s.size()); - assertTrue(s.contains(one)); - assertTrue(s.contains(two)); - assertTrue(s.contains(three)); - assertTrue(s.contains(four)); - assertTrue(s.contains(five)); + Set s = map.keySet(); + assertEquals(5, s.size()); + assertTrue(s.contains(one)); + assertTrue(s.contains(two)); + assertTrue(s.contains(three)); + assertTrue(s.contains(four)); + assertTrue(s.contains(five)); } /** @@ -165,15 +165,37 @@ public class ConcurrentSkipListMapTest e */ public void testKeySetOrder() { ConcurrentSkipListMap map = map5(); - Set s = map.keySet(); + Set s = map.keySet(); Iterator i = s.iterator(); Integer last = (Integer)i.next(); assertEquals(last, one); + int count = 1; while (i.hasNext()) { Integer k = (Integer)i.next(); assertTrue(last.compareTo(k) < 0); last = k; + ++count; + } + assertEquals(count ,5); + } + + /** + * descending iterator of key set is inverse ordered + */ + public void testKeySetDescendingIteratorOrder() { + ConcurrentSkipListMap map = map5(); + NavigableSet s = map.navigableKeySet(); + Iterator i = s.descendingIterator(); + Integer last = (Integer)i.next(); + assertEquals(last, five); + int count = 1; + while (i.hasNext()) { + Integer k = (Integer)i.next(); + assertTrue(last.compareTo(k) > 0); + last = k; + ++count; } + assertEquals(count ,5); } /** @@ -181,32 +203,53 @@ public class ConcurrentSkipListMapTest e */ public void testDescendingKeySetOrder() { ConcurrentSkipListMap map = map5(); - Set s = map.descendingKeySet(); + Set s = map.descendingKeySet(); Iterator i = s.iterator(); Integer last = (Integer)i.next(); assertEquals(last, five); + int count = 1; while (i.hasNext()) { Integer k = (Integer)i.next(); assertTrue(last.compareTo(k) > 0); last = k; + ++count; } + assertEquals(count, 5); } + /** + * descending iterator of descendingKeySet is ordered + */ + public void testDescendingKeySetDescendingIteratorOrder() { + ConcurrentSkipListMap map = map5(); + NavigableSet s = map.descendingKeySet(); + Iterator i = s.descendingIterator(); + Integer last = (Integer)i.next(); + assertEquals(last, one); + int count = 1; + while (i.hasNext()) { + Integer k = (Integer)i.next(); + assertTrue(last.compareTo(k) < 0); + last = k; + ++count; + } + assertEquals(count, 5); + } /** * Values.toArray contains all values */ public void testValuesToArray() { ConcurrentSkipListMap map = map5(); - Collection v = map.values(); + Collection v = map.values(); Object[] ar = v.toArray(); ArrayList s = new ArrayList(Arrays.asList(ar)); - assertEquals(5, ar.length); - assertTrue(s.contains("A")); - assertTrue(s.contains("B")); - assertTrue(s.contains("C")); - assertTrue(s.contains("D")); - assertTrue(s.contains("E")); + assertEquals(5, ar.length); + assertTrue(s.contains("A")); + assertTrue(s.contains("B")); + assertTrue(s.contains("C")); + assertTrue(s.contains("D")); + assertTrue(s.contains("E")); } /** @@ -214,13 +257,13 @@ public class ConcurrentSkipListMapTest e */ public void testValues() { ConcurrentSkipListMap map = map5(); - Collection s = map.values(); - assertEquals(5, s.size()); - assertTrue(s.contains("A")); - assertTrue(s.contains("B")); - assertTrue(s.contains("C")); - assertTrue(s.contains("D")); - assertTrue(s.contains("E")); + Collection s = map.values(); + assertEquals(5, s.size()); + assertTrue(s.contains("A")); + assertTrue(s.contains("B")); + assertTrue(s.contains("C")); + assertTrue(s.contains("D")); + assertTrue(s.contains("E")); } /** @@ -228,12 +271,12 @@ public class ConcurrentSkipListMapTest e */ public void testEntrySet() { ConcurrentSkipListMap map = map5(); - Set s = map.entrySet(); - assertEquals(5, s.size()); + Set s = map.entrySet(); + assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); - assertTrue( + assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || @@ -247,12 +290,12 @@ public class ConcurrentSkipListMapTest e */ public void testDescendingEntrySet() { ConcurrentSkipListMap map = map5(); - Set s = map.descendingMap().entrySet(); - assertEquals(5, s.size()); + Set s = map.descendingMap().entrySet(); + assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); - assertTrue( + assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || @@ -266,7 +309,7 @@ public class ConcurrentSkipListMapTest e */ public void testEntrySetToArray() { ConcurrentSkipListMap map = map5(); - Set s = map.entrySet(); + Set s = map.entrySet(); Object[] ar = s.toArray(); assertEquals(5, ar.length); for (int i = 0; i < 5; ++i) { @@ -280,7 +323,7 @@ public class ConcurrentSkipListMapTest e */ public void testDescendingEntrySetToArray() { ConcurrentSkipListMap map = map5(); - Set s = map.descendingMap().entrySet(); + Set s = map.descendingMap().entrySet(); Object[] ar = s.toArray(); assertEquals(5, ar.length); for (int i = 0; i < 5; ++i) { @@ -295,13 +338,13 @@ public class ConcurrentSkipListMapTest e public void testPutAll() { ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); ConcurrentSkipListMap map = map5(); - empty.putAll(map); - assertEquals(5, empty.size()); - assertTrue(empty.containsKey(one)); - assertTrue(empty.containsKey(two)); - assertTrue(empty.containsKey(three)); - assertTrue(empty.containsKey(four)); - assertTrue(empty.containsKey(five)); + empty.putAll(map); + assertEquals(5, empty.size()); + assertTrue(empty.containsKey(one)); + assertTrue(empty.containsKey(two)); + assertTrue(empty.containsKey(three)); + assertTrue(empty.containsKey(four)); + assertTrue(empty.containsKey(five)); } /** @@ -309,7 +352,7 @@ public class ConcurrentSkipListMapTest e */ public void testPutIfAbsent() { ConcurrentSkipListMap map = map5(); - map.putIfAbsent(six, "Z"); + map.putIfAbsent(six, "Z"); assertTrue(map.containsKey(six)); } @@ -326,7 +369,7 @@ public class ConcurrentSkipListMapTest e */ public void testReplace() { ConcurrentSkipListMap map = map5(); - assertNull(map.replace(six, "Z")); + assertNull(map.replace(six, "Z")); assertFalse(map.containsKey(six)); } @@ -346,7 +389,7 @@ public class ConcurrentSkipListMapTest e public void testReplaceValue() { ConcurrentSkipListMap map = map5(); assertEquals("A", map.get(one)); - assertFalse(map.replace(one, "Z", "Z")); + assertFalse(map.replace(one, "Z", "Z")); assertEquals("A", map.get(one)); } @@ -356,7 +399,7 @@ public class ConcurrentSkipListMapTest e public void testReplaceValue2() { ConcurrentSkipListMap map = map5(); assertEquals("A", map.get(one)); - assertTrue(map.replace(one, "A", "Z")); + assertTrue(map.replace(one, "A", "Z")); assertEquals("Z", map.get(one)); } @@ -366,9 +409,9 @@ public class ConcurrentSkipListMapTest e */ public void testRemove() { ConcurrentSkipListMap map = map5(); - map.remove(five); - assertEquals(4, map.size()); - assertFalse(map.containsKey(five)); + map.remove(five); + assertEquals(4, map.size()); + assertFalse(map.containsKey(five)); } /** @@ -376,15 +419,14 @@ public class ConcurrentSkipListMapTest e */ public void testRemove2() { ConcurrentSkipListMap map = map5(); - assertTrue(map.containsKey(five)); + assertTrue(map.containsKey(five)); assertEquals("E", map.get(five)); - map.remove(five, "E"); - assertEquals(4, map.size()); - assertFalse(map.containsKey(five)); - map.remove(four, "A"); - assertEquals(4, map.size()); - assertTrue(map.containsKey(four)); - + map.remove(five, "E"); + assertEquals(4, map.size()); + assertFalse(map.containsKey(five)); + map.remove(four, "A"); + assertEquals(4, map.size()); + assertTrue(map.containsKey(four)); } /** @@ -403,7 +445,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -422,7 +463,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.higherEntry(six); assertNull(e4); - } /** @@ -441,7 +481,6 @@ public class ConcurrentSkipListMapTest e Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -460,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(); @@ -473,26 +511,26 @@ public class ConcurrentSkipListMapTest e assertEquals(two, e.getKey()); try { e.setValue("X"); - fail(); - } catch(UnsupportedOperationException success) {} + shouldThrow(); + } catch (UnsupportedOperationException success) {} e = map.higherEntry(zero); assertEquals(one, e.getKey()); try { e.setValue("X"); - fail(); - } catch(UnsupportedOperationException success) {} + shouldThrow(); + } catch (UnsupportedOperationException success) {} e = map.floorEntry(one); assertEquals(one, e.getKey()); try { e.setValue("X"); - fail(); - } catch(UnsupportedOperationException success) {} + shouldThrow(); + } catch (UnsupportedOperationException success) {} e = map.ceilingEntry(five); assertEquals(five, e.getKey()); try { e.setValue("X"); - fail(); - } catch(UnsupportedOperationException success) {} + shouldThrow(); + } catch (UnsupportedOperationException success) {} } @@ -513,7 +551,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.lowerKey(zero); assertNull(e4); - } /** @@ -532,7 +569,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.higherKey(six); assertNull(e4); - } /** @@ -551,7 +587,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.floorKey(zero); assertNull(e4); - } /** @@ -570,7 +605,6 @@ public class ConcurrentSkipListMapTest e Object e4 = q.ceilingKey(six); assertNull(e4); - } /** @@ -595,8 +629,7 @@ public class ConcurrentSkipListMapTest e try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -623,8 +656,7 @@ public class ConcurrentSkipListMapTest e try { e.setValue("E"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollLastEntry(); assertNull(e); } @@ -635,8 +667,8 @@ public class ConcurrentSkipListMapTest e public void testSize() { ConcurrentSkipListMap map = map5(); ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); - assertEquals(0, empty.size()); - assertEquals(5, map.size()); + assertEquals(0, empty.size()); + assertEquals(5, map.size()); } /** @@ -648,7 +680,7 @@ public class ConcurrentSkipListMapTest e for (int i = 1; i <= 5; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } // Exception tests @@ -660,7 +692,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.get(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -671,7 +703,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.containsKey(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -682,7 +714,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = new ConcurrentSkipListMap(); c.containsValue(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } @@ -694,7 +726,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.put(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -705,7 +737,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.putIfAbsent(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -716,7 +748,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -727,7 +759,7 @@ public class ConcurrentSkipListMapTest e ConcurrentSkipListMap c = map5(); c.replace(null, one, "whatever"); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -739,7 +771,7 @@ public class ConcurrentSkipListMapTest e c.put("sadsdf", "asdads"); c.remove(null); shouldThrow(); - } catch(NullPointerException e){} + } catch (NullPointerException success) {} } /** @@ -751,44 +783,35 @@ 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)); } /** * A deserialized map equals original */ - public void testSerialization() { + public void testSerialization() throws Exception { ConcurrentSkipListMap q = map5(); - try { - 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)); - } catch(Exception e){ - e.printStackTrace(); - unexpectedException(); - } + 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)); } @@ -820,7 +843,7 @@ public class ConcurrentSkipListMapTest e k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); - + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); @@ -829,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()); } @@ -854,7 +877,7 @@ public class ConcurrentSkipListMapTest e k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); - + Iterator j = sm.keySet().iterator(); j.next(); j.remove(); @@ -862,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()); } @@ -944,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()); @@ -956,9 +979,9 @@ public class ConcurrentSkipListMapTest e /** * Submaps of submaps subdivide correctly */ - public void testRecursiveSubMaps() { - int mapSize = 1000; - Class cl = ConcurrentSkipListMap.class; + public void testRecursiveSubMaps() throws Exception { + int mapSize = 1000; + Class cl = ConcurrentSkipListMap.class; NavigableMap map = newMap(cl); bs = new BitSet(mapSize); @@ -974,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; @@ -1003,7 +1022,7 @@ public class ConcurrentSkipListMapTest e } // Remove a bunch of entries with iterator - for(Iterator it = map.keySet().iterator(); it.hasNext(); ) { + for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -1028,7 +1047,7 @@ public class ConcurrentSkipListMapTest e } // Remove a bunch of entries with iterator - for(Iterator it = map.keySet().iterator(); it.hasNext(); ) { + for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); @@ -1043,10 +1062,8 @@ public class ConcurrentSkipListMapTest e } else { try { map.put(key, 2 * key); - fail(); - } catch(IllegalArgumentException e) { - // expected - } + shouldThrow(); + } catch (IllegalArgumentException success) {} } } } @@ -1241,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) {} } } @@ -1264,5 +1277,5 @@ public class ConcurrentSkipListMapTest e static boolean eq(Integer i, int j) { return i == null ? j == -1 : i == j; } - + }