--- jsr166/src/test/tck/TreeMapTest.java 2009/11/21 02:07:27 1.9 +++ jsr166/src/test/tck/TreeMapTest.java 2009/11/21 17:38:06 1.11 @@ -516,8 +516,7 @@ public class TreeMapTest extends JSR166T try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -544,8 +543,7 @@ public class TreeMapTest extends JSR166T try { e.setValue("E"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollLastEntry(); assertNull(e); } @@ -581,7 +579,7 @@ public class TreeMapTest extends JSR166T TreeMap c = map5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -592,7 +590,7 @@ public class TreeMapTest extends JSR166T TreeMap c = map5(); c.containsKey(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -604,31 +602,26 @@ public class TreeMapTest extends JSR166T c.put("sadsdf", "asdads"); c.remove(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** * A deserialized map equals original */ - public void testSerialization() { + public void testSerialization() throws Exception { TreeMap 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)); - TreeMap r = (TreeMap)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)); + TreeMap r = (TreeMap)in.readObject(); + assertEquals(q.size(), r.size()); + assertTrue(q.equals(r)); + assertTrue(r.equals(q)); } /** @@ -794,7 +787,7 @@ public class TreeMapTest extends JSR166T /** * Submaps of submaps subdivide correctly */ - public void testRecursiveSubMaps() { + public void testRecursiveSubMaps() throws Exception { int mapSize = 1000; Class cl = TreeMap.class; NavigableMap map = newMap(cl); @@ -812,13 +805,9 @@ public class TreeMapTest extends JSR166T 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; @@ -881,10 +870,8 @@ public class TreeMapTest extends JSR166T } else { try { map.put(key, 2 * key); - fail(); - } catch (IllegalArgumentException e) { - // expected - } + shouldThrow(); + } catch (IllegalArgumentException success) {} } } } @@ -1079,16 +1066,12 @@ public class TreeMapTest extends JSR166T 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) {} } }