516 |
|
try { |
517 |
|
e.setValue("A"); |
518 |
|
shouldThrow(); |
519 |
< |
} catch (Exception ok) { |
520 |
< |
} |
519 |
> |
} catch (UnsupportedOperationException success) {} |
520 |
|
e = map.pollFirstEntry(); |
521 |
|
assertNull(e); |
522 |
|
} |
543 |
|
try { |
544 |
|
e.setValue("E"); |
545 |
|
shouldThrow(); |
546 |
< |
} catch (Exception ok) { |
548 |
< |
} |
546 |
> |
} catch (UnsupportedOperationException success) {} |
547 |
|
e = map.pollLastEntry(); |
548 |
|
assertNull(e); |
549 |
|
} |
579 |
|
TreeMap c = map5(); |
580 |
|
c.get(null); |
581 |
|
shouldThrow(); |
582 |
< |
} catch (NullPointerException e) {} |
582 |
> |
} catch (NullPointerException success) {} |
583 |
|
} |
584 |
|
|
585 |
|
/** |
590 |
|
TreeMap c = map5(); |
591 |
|
c.containsKey(null); |
592 |
|
shouldThrow(); |
593 |
< |
} catch (NullPointerException e) {} |
593 |
> |
} catch (NullPointerException success) {} |
594 |
|
} |
595 |
|
|
596 |
|
/** |
602 |
|
c.put("sadsdf", "asdads"); |
603 |
|
c.remove(null); |
604 |
|
shouldThrow(); |
605 |
< |
} catch (NullPointerException e) {} |
605 |
> |
} catch (NullPointerException success) {} |
606 |
|
} |
607 |
|
|
608 |
|
/** |
609 |
|
* A deserialized map equals original |
610 |
|
*/ |
611 |
< |
public void testSerialization() { |
611 |
> |
public void testSerialization() throws Exception { |
612 |
|
TreeMap q = map5(); |
613 |
|
|
614 |
< |
try { |
615 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
616 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
617 |
< |
out.writeObject(q); |
618 |
< |
out.close(); |
619 |
< |
|
620 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
621 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
622 |
< |
TreeMap r = (TreeMap)in.readObject(); |
623 |
< |
assertEquals(q.size(), r.size()); |
624 |
< |
assertTrue(q.equals(r)); |
627 |
< |
assertTrue(r.equals(q)); |
628 |
< |
} catch (Exception e) { |
629 |
< |
e.printStackTrace(); |
630 |
< |
unexpectedException(); |
631 |
< |
} |
614 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
615 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
616 |
> |
out.writeObject(q); |
617 |
> |
out.close(); |
618 |
> |
|
619 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
620 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
621 |
> |
TreeMap r = (TreeMap)in.readObject(); |
622 |
> |
assertEquals(q.size(), r.size()); |
623 |
> |
assertTrue(q.equals(r)); |
624 |
> |
assertTrue(r.equals(q)); |
625 |
|
} |
626 |
|
|
627 |
|
/** |
660 |
|
assertEquals(1, sm.size()); |
661 |
|
assertEquals(three, sm.firstKey()); |
662 |
|
assertEquals(three, sm.lastKey()); |
663 |
< |
assertTrue(sm.remove(three) != null); |
663 |
> |
assertEquals("C", sm.remove(three)); |
664 |
|
assertTrue(sm.isEmpty()); |
665 |
|
assertEquals(3, map.size()); |
666 |
|
} |
693 |
|
assertEquals(4, map.size()); |
694 |
|
assertEquals(0, sm.size()); |
695 |
|
assertTrue(sm.isEmpty()); |
696 |
< |
assertTrue(sm.remove(three) == null); |
696 |
> |
assertSame(sm.remove(three), null); |
697 |
|
assertEquals(4, map.size()); |
698 |
|
} |
699 |
|
|
775 |
|
NavigableMap ssm = sm.tailMap(four, true); |
776 |
|
assertEquals(four, ssm.firstKey()); |
777 |
|
assertEquals(five, ssm.lastKey()); |
778 |
< |
assertTrue(ssm.remove(four) != null); |
778 |
> |
assertEquals("D", ssm.remove(four)); |
779 |
|
assertEquals(1, ssm.size()); |
780 |
|
assertEquals(3, sm.size()); |
781 |
|
assertEquals(4, map.size()); |
787 |
|
/** |
788 |
|
* Submaps of submaps subdivide correctly |
789 |
|
*/ |
790 |
< |
public void testRecursiveSubMaps() { |
790 |
> |
public void testRecursiveSubMaps() throws Exception { |
791 |
|
int mapSize = 1000; |
792 |
|
Class cl = TreeMap.class; |
793 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
805 |
|
0, mapSize - 1, true); |
806 |
|
} |
807 |
|
|
808 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
809 |
< |
NavigableMap<Integer, Integer> result = null; |
810 |
< |
try { |
818 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
819 |
< |
} catch (Exception e) { |
820 |
< |
fail(); |
821 |
< |
} |
808 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
809 |
> |
NavigableMap<Integer, Integer> result |
810 |
> |
= (NavigableMap<Integer, Integer>) cl.newInstance(); |
811 |
|
assertEquals(result.size(), 0); |
812 |
|
assertFalse(result.keySet().iterator().hasNext()); |
813 |
|
return result; |
870 |
|
} else { |
871 |
|
try { |
872 |
|
map.put(key, 2 * key); |
873 |
< |
fail(); |
874 |
< |
} catch (IllegalArgumentException e) { |
886 |
< |
// expected |
887 |
< |
} |
873 |
> |
shouldThrow(); |
874 |
> |
} catch (IllegalArgumentException success) {} |
875 |
|
} |
876 |
|
} |
877 |
|
} |
1066 |
|
assertEq(rs.last(), -1); |
1067 |
|
try { |
1068 |
|
map.firstKey(); |
1069 |
< |
fail(); |
1070 |
< |
} catch (NoSuchElementException e) { |
1084 |
< |
// expected |
1085 |
< |
} |
1069 |
> |
shouldThrow(); |
1070 |
> |
} catch (NoSuchElementException success) {} |
1071 |
|
try { |
1072 |
|
map.lastKey(); |
1073 |
< |
fail(); |
1074 |
< |
} catch (NoSuchElementException e) { |
1090 |
< |
// expected |
1091 |
< |
} |
1073 |
> |
shouldThrow(); |
1074 |
> |
} catch (NoSuchElementException success) {} |
1075 |
|
} |
1076 |
|
} |
1077 |
|
|