|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.json;
|
19 | 19 |
|
| 20 | +import static java.nio.charset.StandardCharsets.UTF_8; |
20 | 21 | import static org.assertj.core.api.Assertions.assertThat;
|
21 | 22 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
22 | 23 | import static org.openqa.selenium.json.Json.MAP_TYPE;
|
|
35 | 36 | import org.junit.experimental.categories.Category;
|
36 | 37 | import org.openqa.selenium.testing.UnitTests;
|
37 | 38 |
|
| 39 | +import java.io.ByteArrayInputStream; |
| 40 | +import java.io.IOException; |
| 41 | +import java.io.InputStream; |
| 42 | +import java.io.InputStreamReader; |
| 43 | +import java.io.Reader; |
38 | 44 | import java.io.StringReader;
|
| 45 | +import java.nio.charset.StandardCharsets; |
39 | 46 | import java.util.Map;
|
40 | 47 | import java.util.Random;
|
41 | 48 | import java.util.stream.Collectors;
|
@@ -258,6 +265,30 @@ public void shouldBeAbleToReadNonWellFormedDataLongerThanReadBuffer() {
|
258 | 265 | raw, raw.substring(raw.length() - 128)));
|
259 | 266 | }
|
260 | 267 |
|
| 268 | + @Test |
| 269 | + public void nullInputsShouldCoerceAsNullValues() throws IOException { |
| 270 | + try (InputStream is = new ByteArrayInputStream(new byte[0]); |
| 271 | + Reader reader = new InputStreamReader(is, UTF_8); |
| 272 | + JsonInput input = new Json().newInput(reader)) { |
| 273 | + |
| 274 | + Object value = input.read(MAP_TYPE); |
| 275 | + |
| 276 | + assertThat(value).isNull(); |
| 277 | + } |
| 278 | + } |
| 279 | + |
| 280 | + @Test |
| 281 | + public void emptyStringsWithNoJsonValuesComeBackAsNull() throws IOException { |
| 282 | + try (InputStream is = new ByteArrayInputStream(" ".getBytes(UTF_8)); |
| 283 | + Reader reader = new InputStreamReader(is, UTF_8); |
| 284 | + JsonInput input = new Json().newInput(reader)) { |
| 285 | + |
| 286 | + Object value = input.read(String.class); |
| 287 | + |
| 288 | + assertThat(value).isNull(); |
| 289 | + } |
| 290 | + } |
| 291 | + |
261 | 292 | private JsonInput newInput(String raw) {
|
262 | 293 | StringReader reader = new StringReader(raw);
|
263 | 294 | return new JsonInput(reader, new JsonTypeCoercer(), BY_NAME);
|
|
0 commit comments