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:
Sergii Tkachenko 2022-02-04 09:56:26 -08:00 committed by GitHub
parent a661515421
commit c46d2c276a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -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");
}
}
} }