17 |
|
import java.util.TreeMap; |
18 |
|
|
19 |
|
import junit.framework.Test; |
20 |
– |
import junit.framework.TestSuite; |
20 |
|
|
21 |
|
public class TreeMapTest extends JSR166TestCase { |
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run(suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
public static Test suite() { |
26 |
< |
return new TestSuite(TreeMapTest.class); |
26 |
> |
class Implementation implements MapImplementation { |
27 |
> |
public Class<?> klazz() { return TreeMap.class; } |
28 |
> |
public Map emptyMap() { return new TreeMap(); } |
29 |
> |
public boolean isConcurrent() { return false; } |
30 |
> |
public boolean permitsNullKeys() { return false; } |
31 |
> |
public boolean permitsNullValues() { return true; } |
32 |
> |
public boolean supportsSetValue() { return true; } |
33 |
> |
} |
34 |
> |
return newTestSuite( |
35 |
> |
TreeMapTest.class, |
36 |
> |
MapTest.testSuite(new Implementation())); |
37 |
|
} |
38 |
|
|
39 |
|
/** |
584 |
|
* get(null) of nonempty map throws NPE |
585 |
|
*/ |
586 |
|
public void testGet_NullPointerException() { |
587 |
+ |
TreeMap c = map5(); |
588 |
|
try { |
579 |
– |
TreeMap c = map5(); |
589 |
|
c.get(null); |
590 |
|
shouldThrow(); |
591 |
|
} catch (NullPointerException success) {} |
595 |
|
* containsKey(null) of nonempty map throws NPE |
596 |
|
*/ |
597 |
|
public void testContainsKey_NullPointerException() { |
598 |
+ |
TreeMap c = map5(); |
599 |
|
try { |
590 |
– |
TreeMap c = map5(); |
600 |
|
c.containsKey(null); |
601 |
|
shouldThrow(); |
602 |
|
} catch (NullPointerException success) {} |
606 |
|
* remove(null) throws NPE for nonempty map |
607 |
|
*/ |
608 |
|
public void testRemove1_NullPointerException() { |
609 |
+ |
TreeMap c = new TreeMap(); |
610 |
+ |
c.put("sadsdf", "asdads"); |
611 |
|
try { |
601 |
– |
TreeMap c = new TreeMap(); |
602 |
– |
c.put("sadsdf", "asdads"); |
612 |
|
c.remove(null); |
613 |
|
shouldThrow(); |
614 |
|
} catch (NullPointerException success) {} |
615 |
|
} |
616 |
|
|
617 |
|
/** |
618 |
< |
* A deserialized map equals original |
618 |
> |
* A deserialized/reserialized map equals original |
619 |
|
*/ |
620 |
|
public void testSerialization() throws Exception { |
621 |
|
NavigableMap x = map5(); |
811 |
|
|
812 |
|
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
813 |
|
NavigableMap<Integer, Integer> result |
814 |
< |
= (NavigableMap<Integer, Integer>) cl.newInstance(); |
814 |
> |
= (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance(); |
815 |
|
assertEquals(0, result.size()); |
816 |
|
assertFalse(result.keySet().iterator().hasNext()); |
817 |
|
return result; |
844 |
|
// Add entries till we're back to original size |
845 |
|
while (map.size() < size) { |
846 |
|
int key = min + rnd.nextInt(rangeSize); |
847 |
< |
assertTrue(key >= min && key<= max); |
847 |
> |
assertTrue(key >= min && key <= max); |
848 |
|
put(map, key); |
849 |
|
} |
850 |
|
} |
869 |
|
// Add entries till we're back to original size |
870 |
|
while (map.size() < size) { |
871 |
|
int key = min - 5 + rnd.nextInt(rangeSize + 10); |
872 |
< |
if (key >= min && key<= max) { |
872 |
> |
if (key >= min && key <= max) { |
873 |
|
put(map, key); |
874 |
|
} else { |
875 |
|
try { |