mirror of https://github.com/grpc/grpc-java.git
core: test JsonUtil.getObject with a map containing a null value (#8881)
Verifies the behavior of JsonUtil.getObject when the map contains a null value for a given key. Note: this may be incorrect behavior. Issue to track the investigation: #8883.
This commit is contained in:
parent
a661515421
commit
c46d2c276a
|
|
@ -19,6 +19,7 @@ package io.grpc.internal;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -130,4 +131,16 @@ public class JsonUtilTest {
|
||||||
assertThat(JsonUtil.getNumberAsInteger(map, "key_nonexistent")).isNull();
|
assertThat(JsonUtil.getNumberAsInteger(map, "key_nonexistent")).isNull();
|
||||||
assertThat(JsonUtil.getNumberAsLong(map, "key_nonexistent")).isNull();
|
assertThat(JsonUtil.getNumberAsLong(map, "key_nonexistent")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getObject_mapExplicitNullValue() {
|
||||||
|
Map<String, ?> mapWithNullValue = Collections.singletonMap("key", null);
|
||||||
|
try {
|
||||||
|
JsonUtil.getObject(mapWithNullValue, "key");
|
||||||
|
fail("ClassCastException expected");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
assertThat(e).hasMessageThat()
|
||||||
|
.isEqualTo("value 'null' for key 'key' in '{key=null}' is not object");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue