357 |
|
|
358 |
|
Map.Entry e4 = map.lowerEntry(zero); |
359 |
|
assertNull(e4); |
360 |
– |
|
360 |
|
} |
361 |
|
|
362 |
|
/** |
375 |
|
|
376 |
|
Map.Entry e4 = map.higherEntry(six); |
377 |
|
assertNull(e4); |
379 |
– |
|
378 |
|
} |
379 |
|
|
380 |
|
/** |
393 |
|
|
394 |
|
Map.Entry e4 = map.floorEntry(zero); |
395 |
|
assertNull(e4); |
398 |
– |
|
396 |
|
} |
397 |
|
|
398 |
|
/** |
411 |
|
|
412 |
|
Map.Entry e4 = map.ceilingEntry(six); |
413 |
|
assertNull(e4); |
417 |
– |
|
414 |
|
} |
415 |
|
|
416 |
|
|
430 |
|
|
431 |
|
Object e4 = q.lowerKey(zero); |
432 |
|
assertNull(e4); |
437 |
– |
|
433 |
|
} |
434 |
|
|
435 |
|
/** |
448 |
|
|
449 |
|
Object e4 = q.higherKey(six); |
450 |
|
assertNull(e4); |
456 |
– |
|
451 |
|
} |
452 |
|
|
453 |
|
/** |
466 |
|
|
467 |
|
Object e4 = q.floorKey(zero); |
468 |
|
assertNull(e4); |
475 |
– |
|
469 |
|
} |
470 |
|
|
471 |
|
/** |
484 |
|
|
485 |
|
Object e4 = q.ceilingKey(six); |
486 |
|
assertNull(e4); |
494 |
– |
|
487 |
|
} |
488 |
|
|
489 |
|
/** |
508 |
|
try { |
509 |
|
e.setValue("A"); |
510 |
|
shouldThrow(); |
511 |
< |
} catch (Exception ok) { |
520 |
< |
} |
511 |
> |
} catch (UnsupportedOperationException success) {} |
512 |
|
e = map.pollFirstEntry(); |
513 |
|
assertNull(e); |
514 |
|
} |
535 |
|
try { |
536 |
|
e.setValue("E"); |
537 |
|
shouldThrow(); |
538 |
< |
} catch (Exception ok) { |
548 |
< |
} |
538 |
> |
} catch (UnsupportedOperationException success) {} |
539 |
|
e = map.pollLastEntry(); |
540 |
|
assertNull(e); |
541 |
|
} |
571 |
|
TreeMap c = map5(); |
572 |
|
c.get(null); |
573 |
|
shouldThrow(); |
574 |
< |
} catch (NullPointerException e) {} |
574 |
> |
} catch (NullPointerException success) {} |
575 |
|
} |
576 |
|
|
577 |
|
/** |
582 |
|
TreeMap c = map5(); |
583 |
|
c.containsKey(null); |
584 |
|
shouldThrow(); |
585 |
< |
} catch (NullPointerException e) {} |
585 |
> |
} catch (NullPointerException success) {} |
586 |
|
} |
587 |
|
|
588 |
|
/** |
594 |
|
c.put("sadsdf", "asdads"); |
595 |
|
c.remove(null); |
596 |
|
shouldThrow(); |
597 |
< |
} catch (NullPointerException e) {} |
597 |
> |
} catch (NullPointerException success) {} |
598 |
|
} |
599 |
|
|
600 |
|
/** |
601 |
|
* A deserialized map equals original |
602 |
|
*/ |
603 |
< |
public void testSerialization() { |
603 |
> |
public void testSerialization() throws Exception { |
604 |
|
TreeMap q = map5(); |
605 |
|
|
606 |
< |
try { |
607 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
608 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
609 |
< |
out.writeObject(q); |
610 |
< |
out.close(); |
611 |
< |
|
612 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
613 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
614 |
< |
TreeMap r = (TreeMap)in.readObject(); |
615 |
< |
assertEquals(q.size(), r.size()); |
616 |
< |
assertTrue(q.equals(r)); |
627 |
< |
assertTrue(r.equals(q)); |
628 |
< |
} catch (Exception e) { |
629 |
< |
e.printStackTrace(); |
630 |
< |
unexpectedException(); |
631 |
< |
} |
606 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
607 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
608 |
> |
out.writeObject(q); |
609 |
> |
out.close(); |
610 |
> |
|
611 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
612 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
613 |
> |
TreeMap r = (TreeMap)in.readObject(); |
614 |
> |
assertEquals(q.size(), r.size()); |
615 |
> |
assertTrue(q.equals(r)); |
616 |
> |
assertTrue(r.equals(q)); |
617 |
|
} |
618 |
|
|
619 |
|
/** |
652 |
|
assertEquals(1, sm.size()); |
653 |
|
assertEquals(three, sm.firstKey()); |
654 |
|
assertEquals(three, sm.lastKey()); |
655 |
< |
assertTrue(sm.remove(three) != null); |
655 |
> |
assertEquals("C", sm.remove(three)); |
656 |
|
assertTrue(sm.isEmpty()); |
657 |
|
assertEquals(3, map.size()); |
658 |
|
} |
685 |
|
assertEquals(4, map.size()); |
686 |
|
assertEquals(0, sm.size()); |
687 |
|
assertTrue(sm.isEmpty()); |
688 |
< |
assertTrue(sm.remove(three) == null); |
688 |
> |
assertSame(sm.remove(three), null); |
689 |
|
assertEquals(4, map.size()); |
690 |
|
} |
691 |
|
|
767 |
|
NavigableMap ssm = sm.tailMap(four, true); |
768 |
|
assertEquals(four, ssm.firstKey()); |
769 |
|
assertEquals(five, ssm.lastKey()); |
770 |
< |
assertTrue(ssm.remove(four) != null); |
770 |
> |
assertEquals("D", ssm.remove(four)); |
771 |
|
assertEquals(1, ssm.size()); |
772 |
|
assertEquals(3, sm.size()); |
773 |
|
assertEquals(4, map.size()); |
779 |
|
/** |
780 |
|
* Submaps of submaps subdivide correctly |
781 |
|
*/ |
782 |
< |
public void testRecursiveSubMaps() { |
782 |
> |
public void testRecursiveSubMaps() throws Exception { |
783 |
|
int mapSize = 1000; |
784 |
|
Class cl = TreeMap.class; |
785 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
797 |
|
0, mapSize - 1, true); |
798 |
|
} |
799 |
|
|
800 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
801 |
< |
NavigableMap<Integer, Integer> result = null; |
802 |
< |
try { |
818 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
819 |
< |
} catch (Exception e) { |
820 |
< |
fail(); |
821 |
< |
} |
800 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
801 |
> |
NavigableMap<Integer, Integer> result |
802 |
> |
= (NavigableMap<Integer, Integer>) cl.newInstance(); |
803 |
|
assertEquals(result.size(), 0); |
804 |
|
assertFalse(result.keySet().iterator().hasNext()); |
805 |
|
return result; |
862 |
|
} else { |
863 |
|
try { |
864 |
|
map.put(key, 2 * key); |
865 |
< |
fail(); |
866 |
< |
} catch (IllegalArgumentException e) { |
886 |
< |
// expected |
887 |
< |
} |
865 |
> |
shouldThrow(); |
866 |
> |
} catch (IllegalArgumentException success) {} |
867 |
|
} |
868 |
|
} |
869 |
|
} |
1058 |
|
assertEq(rs.last(), -1); |
1059 |
|
try { |
1060 |
|
map.firstKey(); |
1061 |
< |
fail(); |
1062 |
< |
} catch (NoSuchElementException e) { |
1084 |
< |
// expected |
1085 |
< |
} |
1061 |
> |
shouldThrow(); |
1062 |
> |
} catch (NoSuchElementException success) {} |
1063 |
|
try { |
1064 |
|
map.lastKey(); |
1065 |
< |
fail(); |
1066 |
< |
} catch (NoSuchElementException e) { |
1090 |
< |
// expected |
1091 |
< |
} |
1065 |
> |
shouldThrow(); |
1066 |
> |
} catch (NoSuchElementException success) {} |
1067 |
|
} |
1068 |
|
} |
1069 |
|
|