ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/TreeSubMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/TreeSubMapTest.java (file contents):
Revision 1.7 by jsr166, Sat Nov 21 02:07:27 2009 UTC vs.
Revision 1.14 by jsr166, Tue Mar 15 19:47:07 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import junit.framework.*;
# Line 11 | Line 11 | import java.io.*;
11  
12   public class TreeSubMapTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17          return new TestSuite(TreeSubMapTest.class);
# Line 64 | Line 64 | public class TreeSubMapTest extends JSR1
64      }
65  
66      /**
67 <     *  clear removes all pairs
67 >     * clear removes all pairs
68       */
69      public void testClear() {
70          NavigableMap map = map5();
# Line 74 | Line 74 | public class TreeSubMapTest extends JSR1
74  
75  
76      /**
77 <     *  Maps with same contents are equal
77 >     * Maps with same contents are equal
78       */
79      public void testEquals() {
80          NavigableMap map1 = map5();
# Line 87 | Line 87 | public class TreeSubMapTest extends JSR1
87      }
88  
89      /**
90 <     *  containsKey returns true for contained key
90 >     * containsKey returns true for contained key
91       */
92      public void testContainsKey() {
93          NavigableMap map = map5();
# Line 96 | Line 96 | public class TreeSubMapTest extends JSR1
96      }
97  
98      /**
99 <     *  containsValue returns true for held values
99 >     * containsValue returns true for held values
100       */
101      public void testContainsValue() {
102          NavigableMap map = map5();
# Line 105 | Line 105 | public class TreeSubMapTest extends JSR1
105      }
106  
107      /**
108 <     *  get returns the correct element at the given key,
109 <     *  or null if not present
108 >     * get returns the correct element at the given key,
109 >     * or null if not present
110       */
111      public void testGet() {
112          NavigableMap map = map5();
# Line 116 | Line 116 | public class TreeSubMapTest extends JSR1
116      }
117  
118      /**
119 <     *  isEmpty is true of empty map and false for non-empty
119 >     * isEmpty is true of empty map and false for non-empty
120       */
121      public void testIsEmpty() {
122          NavigableMap empty = map0();
# Line 126 | Line 126 | public class TreeSubMapTest extends JSR1
126      }
127  
128      /**
129 <     *   firstKey returns first key
129 >     * firstKey returns first key
130       */
131      public void testFirstKey() {
132          NavigableMap map = map5();
# Line 134 | Line 134 | public class TreeSubMapTest extends JSR1
134      }
135  
136      /**
137 <     *   lastKey returns last key
137 >     * lastKey returns last key
138       */
139      public void testLastKey() {
140          NavigableMap map = map5();
# Line 143 | Line 143 | public class TreeSubMapTest extends JSR1
143  
144  
145      /**
146 <     *   keySet returns a Set containing all the keys
146 >     * keySet returns a Set containing all the keys
147       */
148      public void testKeySet() {
149          NavigableMap map = map5();
# Line 157 | Line 157 | public class TreeSubMapTest extends JSR1
157      }
158  
159      /**
160 <     *   keySet is ordered
160 >     * keySet is ordered
161       */
162      public void testKeySetOrder() {
163          NavigableMap map = map5();
# Line 206 | Line 206 | public class TreeSubMapTest extends JSR1
206      }
207  
208      /**
209 <     *   putAll  adds all key-value pairs from the given map
209 >     * putAll adds all key-value pairs from the given map
210       */
211      public void testPutAll() {
212          NavigableMap empty = map0();
# Line 221 | Line 221 | public class TreeSubMapTest extends JSR1
221      }
222  
223      /**
224 <     *   remove removes the correct key-value pair from the map
224 >     * remove removes the correct key-value pair from the map
225       */
226      public void testRemove() {
227          NavigableMap map = map5();
# Line 246 | Line 246 | public class TreeSubMapTest extends JSR1
246  
247          Map.Entry e4 = map.lowerEntry(zero);
248          assertNull(e4);
249
249      }
250  
251      /**
# Line 265 | Line 264 | public class TreeSubMapTest extends JSR1
264  
265          Map.Entry e4 = map.higherEntry(six);
266          assertNull(e4);
268
267      }
268  
269      /**
# Line 284 | Line 282 | public class TreeSubMapTest extends JSR1
282  
283          Map.Entry e4 = map.floorEntry(zero);
284          assertNull(e4);
287
285      }
286  
287      /**
# Line 303 | Line 300 | public class TreeSubMapTest extends JSR1
300  
301          Map.Entry e4 = map.ceilingEntry(six);
302          assertNull(e4);
306
303      }
304  
305      /**
# Line 328 | Line 324 | public class TreeSubMapTest extends JSR1
324          try {
325              e.setValue("A");
326              shouldThrow();
327 <        } catch (Exception ok) {
332 <        }
327 >        } catch (UnsupportedOperationException success) {}
328          assertTrue(map.isEmpty());
329          Map.Entry f = map.firstEntry();
330          assertNull(f);
# Line 359 | Line 354 | public class TreeSubMapTest extends JSR1
354          try {
355              e.setValue("E");
356              shouldThrow();
357 <        } catch (Exception ok) {
363 <        }
357 >        } catch (UnsupportedOperationException success) {}
358          e = map.pollLastEntry();
359          assertNull(e);
360      }
361  
362      /**
363 <     *   size returns the correct values
363 >     * size returns the correct values
364       */
365      public void testSize() {
366          NavigableMap map = map5();
# Line 396 | Line 390 | public class TreeSubMapTest extends JSR1
390              NavigableMap c = map5();
391              c.get(null);
392              shouldThrow();
393 <        } catch (NullPointerException e) {}
393 >        } catch (NullPointerException success) {}
394      }
395  
396      /**
# Line 407 | Line 401 | public class TreeSubMapTest extends JSR1
401              NavigableMap c = map5();
402              c.containsKey(null);
403              shouldThrow();
404 <        } catch (NullPointerException e) {}
404 >        } catch (NullPointerException success) {}
405      }
406  
407      /**
# Line 418 | Line 412 | public class TreeSubMapTest extends JSR1
412              NavigableMap c = map5();
413              c.put(null, "whatever");
414              shouldThrow();
415 <        } catch (NullPointerException e) {}
415 >        } catch (NullPointerException success) {}
416      }
417  
418      /**
# Line 429 | Line 423 | public class TreeSubMapTest extends JSR1
423              NavigableMap c = map5();
424              c.remove(null);
425              shouldThrow();
426 <        } catch (NullPointerException e) {}
426 >        } catch (NullPointerException success) {}
427      }
428  
429      /**
430       * A deserialized map equals original
431       */
432 <    public void testSerialization() {
432 >    public void testSerialization() throws Exception {
433          NavigableMap q = map5();
434  
435 <        try {
436 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
437 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
438 <            out.writeObject(q);
439 <            out.close();
440 <
441 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
442 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
443 <            NavigableMap r = (NavigableMap)in.readObject();
444 <            assertFalse(r.isEmpty());
445 <            assertEquals(q.size(), r.size());
446 <            assertTrue(q.equals(r));
453 <            assertTrue(r.equals(q));
454 <        } catch (Exception e) {
455 <            e.printStackTrace();
456 <            unexpectedException();
457 <        }
435 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
436 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
437 >        out.writeObject(q);
438 >        out.close();
439 >
440 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
441 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
442 >        NavigableMap r = (NavigableMap)in.readObject();
443 >        assertFalse(r.isEmpty());
444 >        assertEquals(q.size(), r.size());
445 >        assertTrue(q.equals(r));
446 >        assertTrue(r.equals(q));
447      }
448  
449  
# Line 488 | Line 477 | public class TreeSubMapTest extends JSR1
477          assertEquals(1, sm.size());
478          assertEquals(three, sm.firstKey());
479          assertEquals(three, sm.lastKey());
480 <        assertTrue(sm.remove(three) != null);
480 >        assertEquals("C", sm.remove(three));
481          assertTrue(sm.isEmpty());
482          assertEquals(3, map.size());
483      }
# Line 516 | Line 505 | public class TreeSubMapTest extends JSR1
505          assertEquals(4, map.size());
506          assertEquals(0, sm.size());
507          assertTrue(sm.isEmpty());
508 <        assertTrue(sm.remove(three) == null);
508 >        assertSame(sm.remove(three), null);
509          assertEquals(4, map.size());
510      }
511  
# Line 588 | Line 577 | public class TreeSubMapTest extends JSR1
577          SortedMap ssm = sm.tailMap(four);
578          assertEquals(four, ssm.firstKey());
579          assertEquals(five, ssm.lastKey());
580 <        assertTrue(ssm.remove(four) != null);
580 >        assertEquals("D", ssm.remove(four));
581          assertEquals(1, ssm.size());
582          assertEquals(3, sm.size());
583          assertEquals(4, map.size());
584      }
585  
586      /**
587 <     *  clear removes all pairs
587 >     * clear removes all pairs
588       */
589      public void testDescendingClear() {
590          NavigableMap map = dmap5();
# Line 605 | Line 594 | public class TreeSubMapTest extends JSR1
594  
595  
596      /**
597 <     *  Maps with same contents are equal
597 >     * Maps with same contents are equal
598       */
599      public void testDescendingEquals() {
600          NavigableMap map1 = dmap5();
# Line 618 | Line 607 | public class TreeSubMapTest extends JSR1
607      }
608  
609      /**
610 <     *  containsKey returns true for contained key
610 >     * containsKey returns true for contained key
611       */
612      public void testDescendingContainsKey() {
613          NavigableMap map = dmap5();
# Line 627 | Line 616 | public class TreeSubMapTest extends JSR1
616      }
617  
618      /**
619 <     *  containsValue returns true for held values
619 >     * containsValue returns true for held values
620       */
621      public void testDescendingContainsValue() {
622          NavigableMap map = dmap5();
# Line 636 | Line 625 | public class TreeSubMapTest extends JSR1
625      }
626  
627      /**
628 <     *  get returns the correct element at the given key,
629 <     *  or null if not present
628 >     * get returns the correct element at the given key,
629 >     * or null if not present
630       */
631      public void testDescendingGet() {
632          NavigableMap map = dmap5();
# Line 647 | Line 636 | public class TreeSubMapTest extends JSR1
636      }
637  
638      /**
639 <     *  isEmpty is true of empty map and false for non-empty
639 >     * isEmpty is true of empty map and false for non-empty
640       */
641      public void testDescendingIsEmpty() {
642          NavigableMap empty = dmap0();
# Line 657 | Line 646 | public class TreeSubMapTest extends JSR1
646      }
647  
648      /**
649 <     *   firstKey returns first key
649 >     * firstKey returns first key
650       */
651      public void testDescendingFirstKey() {
652          NavigableMap map = dmap5();
# Line 665 | Line 654 | public class TreeSubMapTest extends JSR1
654      }
655  
656      /**
657 <     *   lastKey returns last key
657 >     * lastKey returns last key
658       */
659      public void testDescendingLastKey() {
660          NavigableMap map = dmap5();
# Line 674 | Line 663 | public class TreeSubMapTest extends JSR1
663  
664  
665      /**
666 <     *   keySet returns a Set containing all the keys
666 >     * keySet returns a Set containing all the keys
667       */
668      public void testDescendingKeySet() {
669          NavigableMap map = dmap5();
# Line 688 | Line 677 | public class TreeSubMapTest extends JSR1
677      }
678  
679      /**
680 <     *   keySet is ordered
680 >     * keySet is ordered
681       */
682      public void testDescendingKeySetOrder() {
683          NavigableMap map = dmap5();
# Line 718 | Line 707 | public class TreeSubMapTest extends JSR1
707      }
708  
709      /**
710 <     *  keySet.toArray returns contains all keys
710 >     * keySet.toArray returns contains all keys
711       */
712      public void testDescendingAscendingKeySetToArray() {
713          NavigableMap map = dmap5();
# Line 731 | Line 720 | public class TreeSubMapTest extends JSR1
720      }
721  
722      /**
723 <     *  descendingkeySet.toArray returns contains all keys
723 >     * descendingkeySet.toArray returns contains all keys
724       */
725      public void testDescendingDescendingKeySetToArray() {
726          NavigableMap map = dmap5();
# Line 744 | Line 733 | public class TreeSubMapTest extends JSR1
733      }
734  
735      /**
736 <     *  Values.toArray contains all values
736 >     * Values.toArray contains all values
737       */
738      public void testDescendingValuesToArray() {
739          NavigableMap map = dmap5();
# Line 780 | Line 769 | public class TreeSubMapTest extends JSR1
769      }
770  
771      /**
772 <     *   putAll  adds all key-value pairs from the given map
772 >     * putAll adds all key-value pairs from the given map
773       */
774      public void testDescendingPutAll() {
775          NavigableMap empty = dmap0();
# Line 796 | Line 785 | public class TreeSubMapTest extends JSR1
785  
786  
787      /**
788 <     *   remove removes the correct key-value pair from the map
788 >     * remove removes the correct key-value pair from the map
789       */
790      public void testDescendingRemove() {
791          NavigableMap map = dmap5();
# Line 821 | Line 810 | public class TreeSubMapTest extends JSR1
810  
811          Map.Entry e4 = map.lowerEntry(zero);
812          assertNull(e4);
824
813      }
814  
815      /**
# Line 840 | Line 828 | public class TreeSubMapTest extends JSR1
828  
829          Map.Entry e4 = map.higherEntry(m6);
830          assertNull(e4);
843
831      }
832  
833      /**
# Line 859 | Line 846 | public class TreeSubMapTest extends JSR1
846  
847          Map.Entry e4 = map.floorEntry(zero);
848          assertNull(e4);
862
849      }
850  
851      /**
# Line 878 | Line 864 | public class TreeSubMapTest extends JSR1
864  
865          Map.Entry e4 = map.ceilingEntry(m6);
866          assertNull(e4);
881
867      }
868  
869      /**
# Line 903 | Line 888 | public class TreeSubMapTest extends JSR1
888          try {
889              e.setValue("A");
890              shouldThrow();
891 <        } catch (Exception ok) {
907 <        }
891 >        } catch (UnsupportedOperationException success) {}
892          e = map.pollFirstEntry();
893          assertNull(e);
894      }
# Line 931 | Line 915 | public class TreeSubMapTest extends JSR1
915          try {
916              e.setValue("E");
917              shouldThrow();
918 <        } catch (Exception ok) {
935 <        }
918 >        } catch (UnsupportedOperationException success) {}
919          e = map.pollLastEntry();
920          assertNull(e);
921      }
922  
923      /**
924 <     *   size returns the correct values
924 >     * size returns the correct values
925       */
926      public void testDescendingSize() {
927          NavigableMap map = dmap5();
# Line 968 | Line 951 | public class TreeSubMapTest extends JSR1
951              NavigableMap c = dmap5();
952              c.get(null);
953              shouldThrow();
954 <        } catch (NullPointerException e) {}
954 >        } catch (NullPointerException success) {}
955      }
956  
957      /**
# Line 979 | Line 962 | public class TreeSubMapTest extends JSR1
962              NavigableMap c = dmap5();
963              c.put(null, "whatever");
964              shouldThrow();
965 <        } catch (NullPointerException e) {}
965 >        } catch (NullPointerException success) {}
966      }
967  
968      /**
969       * A deserialized map equals original
970       */
971 <    public void testDescendingSerialization() {
971 >    public void testDescendingSerialization() throws Exception {
972          NavigableMap q = dmap5();
973  
974 <        try {
975 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
976 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
977 <            out.writeObject(q);
978 <            out.close();
979 <
980 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
981 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
982 <            NavigableMap r = (NavigableMap)in.readObject();
983 <            assertEquals(q.size(), r.size());
984 <            assertTrue(q.equals(r));
1002 <            assertTrue(r.equals(q));
1003 <        } catch (Exception e) {
1004 <            e.printStackTrace();
1005 <            unexpectedException();
1006 <        }
974 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
975 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
976 >        out.writeObject(q);
977 >        out.close();
978 >
979 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
980 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
981 >        NavigableMap r = (NavigableMap)in.readObject();
982 >        assertEquals(q.size(), r.size());
983 >        assertTrue(q.equals(r));
984 >        assertTrue(r.equals(q));
985      }
986  
987  
1010
988      /**
989       * subMap returns map with keys in requested range
990       */
# Line 1037 | Line 1014 | public class TreeSubMapTest extends JSR1
1014          assertEquals(1, sm.size());
1015          assertEquals(m3, sm.firstKey());
1016          assertEquals(m3, sm.lastKey());
1017 <        assertTrue(sm.remove(m3) != null);
1017 >        assertEquals("C", sm.remove(m3));
1018          assertTrue(sm.isEmpty());
1019          assertEquals(3, map.size());
1020      }
# Line 1065 | Line 1042 | public class TreeSubMapTest extends JSR1
1042          assertEquals(4, map.size());
1043          assertEquals(0, sm.size());
1044          assertTrue(sm.isEmpty());
1045 <        assertTrue(sm.remove(m3) == null);
1045 >        assertSame(sm.remove(m3), null);
1046          assertEquals(4, map.size());
1047      }
1048  
# Line 1137 | Line 1114 | public class TreeSubMapTest extends JSR1
1114          SortedMap ssm = sm.tailMap(m4);
1115          assertEquals(m4, ssm.firstKey());
1116          assertEquals(m5, ssm.lastKey());
1117 <        assertTrue(ssm.remove(m4) != null);
1117 >        assertEquals("D", ssm.remove(m4));
1118          assertEquals(1, ssm.size());
1119          assertEquals(3, sm.size());
1120          assertEquals(4, map.size());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines