--- jsr166/src/test/tck/TreeSubMapTest.java 2009/11/21 02:07:27 1.7 +++ jsr166/src/test/tck/TreeSubMapTest.java 2010/10/09 19:30:35 1.13 @@ -11,7 +11,7 @@ import java.io.*; public class TreeSubMapTest 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(TreeSubMapTest.class); @@ -64,7 +64,7 @@ public class TreeSubMapTest extends JSR1 } /** - * clear removes all pairs + * clear removes all pairs */ public void testClear() { NavigableMap map = map5(); @@ -74,7 +74,7 @@ public class TreeSubMapTest extends JSR1 /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testEquals() { NavigableMap map1 = map5(); @@ -87,7 +87,7 @@ public class TreeSubMapTest extends JSR1 } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testContainsKey() { NavigableMap map = map5(); @@ -96,7 +96,7 @@ public class TreeSubMapTest extends JSR1 } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testContainsValue() { NavigableMap map = map5(); @@ -105,8 +105,8 @@ public class TreeSubMapTest extends JSR1 } /** - * 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() { NavigableMap map = map5(); @@ -116,7 +116,7 @@ public class TreeSubMapTest extends JSR1 } /** - * 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() { NavigableMap empty = map0(); @@ -126,7 +126,7 @@ public class TreeSubMapTest extends JSR1 } /** - * firstKey returns first key + * firstKey returns first key */ public void testFirstKey() { NavigableMap map = map5(); @@ -134,7 +134,7 @@ public class TreeSubMapTest extends JSR1 } /** - * lastKey returns last key + * lastKey returns last key */ public void testLastKey() { NavigableMap map = map5(); @@ -143,7 +143,7 @@ public class TreeSubMapTest extends JSR1 /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testKeySet() { NavigableMap map = map5(); @@ -157,7 +157,7 @@ public class TreeSubMapTest extends JSR1 } /** - * keySet is ordered + * keySet is ordered */ public void testKeySetOrder() { NavigableMap map = map5(); @@ -206,7 +206,7 @@ public class TreeSubMapTest extends JSR1 } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testPutAll() { NavigableMap empty = map0(); @@ -221,7 +221,7 @@ public class TreeSubMapTest extends JSR1 } /** - * remove removes the correct key-value pair from the map + * remove removes the correct key-value pair from the map */ public void testRemove() { NavigableMap map = map5(); @@ -246,7 +246,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -265,7 +264,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.higherEntry(six); assertNull(e4); - } /** @@ -284,7 +282,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -303,7 +300,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.ceilingEntry(six); assertNull(e4); - } /** @@ -328,8 +324,7 @@ public class TreeSubMapTest extends JSR1 try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} assertTrue(map.isEmpty()); Map.Entry f = map.firstEntry(); assertNull(f); @@ -359,14 +354,13 @@ public class TreeSubMapTest extends JSR1 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() { NavigableMap map = map5(); @@ -396,7 +390,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = map5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -407,7 +401,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = map5(); c.containsKey(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -418,7 +412,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = map5(); c.put(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -429,32 +423,27 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = map5(); c.remove(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** * A deserialized map equals original */ - public void testSerialization() { + public void testSerialization() throws Exception { NavigableMap 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)); - NavigableMap r = (NavigableMap)in.readObject(); - assertFalse(r.isEmpty()); - 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)); + NavigableMap r = (NavigableMap)in.readObject(); + assertFalse(r.isEmpty()); + assertEquals(q.size(), r.size()); + assertTrue(q.equals(r)); + assertTrue(r.equals(q)); } @@ -488,7 +477,7 @@ public class TreeSubMapTest extends JSR1 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()); } @@ -516,7 +505,7 @@ public class TreeSubMapTest extends JSR1 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()); } @@ -588,14 +577,14 @@ public class TreeSubMapTest extends JSR1 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() { NavigableMap map = dmap5(); @@ -605,7 +594,7 @@ public class TreeSubMapTest extends JSR1 /** - * Maps with same contents are equal + * Maps with same contents are equal */ public void testDescendingEquals() { NavigableMap map1 = dmap5(); @@ -618,7 +607,7 @@ public class TreeSubMapTest extends JSR1 } /** - * containsKey returns true for contained key + * containsKey returns true for contained key */ public void testDescendingContainsKey() { NavigableMap map = dmap5(); @@ -627,7 +616,7 @@ public class TreeSubMapTest extends JSR1 } /** - * containsValue returns true for held values + * containsValue returns true for held values */ public void testDescendingContainsValue() { NavigableMap map = dmap5(); @@ -636,8 +625,8 @@ public class TreeSubMapTest extends JSR1 } /** - * 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() { NavigableMap map = dmap5(); @@ -647,7 +636,7 @@ public class TreeSubMapTest extends JSR1 } /** - * 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() { NavigableMap empty = dmap0(); @@ -657,7 +646,7 @@ public class TreeSubMapTest extends JSR1 } /** - * firstKey returns first key + * firstKey returns first key */ public void testDescendingFirstKey() { NavigableMap map = dmap5(); @@ -665,7 +654,7 @@ public class TreeSubMapTest extends JSR1 } /** - * lastKey returns last key + * lastKey returns last key */ public void testDescendingLastKey() { NavigableMap map = dmap5(); @@ -674,7 +663,7 @@ public class TreeSubMapTest extends JSR1 /** - * keySet returns a Set containing all the keys + * keySet returns a Set containing all the keys */ public void testDescendingKeySet() { NavigableMap map = dmap5(); @@ -688,7 +677,7 @@ public class TreeSubMapTest extends JSR1 } /** - * keySet is ordered + * keySet is ordered */ public void testDescendingKeySetOrder() { NavigableMap map = dmap5(); @@ -718,7 +707,7 @@ public class TreeSubMapTest extends JSR1 } /** - * keySet.toArray returns contains all keys + * keySet.toArray returns contains all keys */ public void testDescendingAscendingKeySetToArray() { NavigableMap map = dmap5(); @@ -731,7 +720,7 @@ public class TreeSubMapTest extends JSR1 } /** - * descendingkeySet.toArray returns contains all keys + * descendingkeySet.toArray returns contains all keys */ public void testDescendingDescendingKeySetToArray() { NavigableMap map = dmap5(); @@ -744,7 +733,7 @@ public class TreeSubMapTest extends JSR1 } /** - * Values.toArray contains all values + * Values.toArray contains all values */ public void testDescendingValuesToArray() { NavigableMap map = dmap5(); @@ -780,7 +769,7 @@ public class TreeSubMapTest extends JSR1 } /** - * putAll adds all key-value pairs from the given map + * putAll adds all key-value pairs from the given map */ public void testDescendingPutAll() { NavigableMap empty = dmap0(); @@ -796,7 +785,7 @@ public class TreeSubMapTest extends JSR1 /** - * remove removes the correct key-value pair from the map + * remove removes the correct key-value pair from the map */ public void testDescendingRemove() { NavigableMap map = dmap5(); @@ -821,7 +810,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); - } /** @@ -840,7 +828,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.higherEntry(m6); assertNull(e4); - } /** @@ -859,7 +846,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.floorEntry(zero); assertNull(e4); - } /** @@ -878,7 +864,6 @@ public class TreeSubMapTest extends JSR1 Map.Entry e4 = map.ceilingEntry(m6); assertNull(e4); - } /** @@ -903,8 +888,7 @@ public class TreeSubMapTest extends JSR1 try { e.setValue("A"); shouldThrow(); - } catch (Exception ok) { - } + } catch (UnsupportedOperationException success) {} e = map.pollFirstEntry(); assertNull(e); } @@ -931,14 +915,13 @@ public class TreeSubMapTest extends JSR1 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() { NavigableMap map = dmap5(); @@ -968,7 +951,7 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = dmap5(); c.get(null); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** @@ -979,35 +962,29 @@ public class TreeSubMapTest extends JSR1 NavigableMap c = dmap5(); c.put(null, "whatever"); shouldThrow(); - } catch (NullPointerException e) {} + } catch (NullPointerException success) {} } /** * A deserialized map equals original */ - public void testDescendingSerialization() { + public void testDescendingSerialization() throws Exception { NavigableMap q = dmap5(); - 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)); - NavigableMap r = (NavigableMap)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)); + NavigableMap r = (NavigableMap)in.readObject(); + assertEquals(q.size(), r.size()); + assertTrue(q.equals(r)); + assertTrue(r.equals(q)); } - /** * subMap returns map with keys in requested range */ @@ -1037,7 +1014,7 @@ public class TreeSubMapTest extends JSR1 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()); } @@ -1065,7 +1042,7 @@ public class TreeSubMapTest extends JSR1 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()); } @@ -1137,7 +1114,7 @@ public class TreeSubMapTest extends JSR1 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());