Tests for LinkedTreeMap with incompatible keys.
This commit is contained in:
parent
a6ab854302
commit
01bd0d92e2
|
@ -164,7 +164,6 @@ public final class LinkedTreeMap<K, V> extends AbstractMap<K, V> implements Seri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jwilson): don't throw ClassCastExceptions on unknown types
|
|
||||||
@SuppressWarnings("unchecked") // this method throws ClassCastExceptions!
|
@SuppressWarnings("unchecked") // this method throws ClassCastExceptions!
|
||||||
Node<K, V> findByObject(Object key) {
|
Node<K, V> findByObject(Object key) {
|
||||||
return key != null ? find((K) key, false) : null;
|
return key != null ? find((K) key, false) : null;
|
||||||
|
|
|
@ -45,7 +45,30 @@ public final class LinkedTreeMapTest extends TestCase {
|
||||||
assertIterationOrder(map.keySet(), "a", "c");
|
assertIterationOrder(map.keySet(), "a", "c");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test contains with non-string key
|
public void testPutNullKeyFails() {
|
||||||
|
LinkedTreeMap<String, String> map = new LinkedTreeMap<String, String>();
|
||||||
|
try {
|
||||||
|
map.put(null, "android");
|
||||||
|
fail();
|
||||||
|
} catch (NullPointerException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testContainsNullKeyFails() {
|
||||||
|
LinkedTreeMap<String, String> map = new LinkedTreeMap<String, String>();
|
||||||
|
map.put("a", "android");
|
||||||
|
assertFalse(map.containsKey(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testContainsNonComparableKeyThrows() {
|
||||||
|
LinkedTreeMap<String, String> map = new LinkedTreeMap<String, String>();
|
||||||
|
map.put("a", "android");
|
||||||
|
try {
|
||||||
|
map.containsKey(new Object());
|
||||||
|
fail();
|
||||||
|
} catch (ClassCastException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
|
private <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
|
||||||
ArrayList<T> actualList = new ArrayList<T>();
|
ArrayList<T> actualList = new ArrayList<T>();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user