|
| 1 | +package tools.jackson.core.unittest.tofix.async; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import tools.jackson.core.*; |
| 6 | +import tools.jackson.core.json.JsonFactory; |
| 7 | +import tools.jackson.core.exc.StreamReadException; |
| 8 | +import tools.jackson.core.unittest.async.AsyncTestBase; |
| 9 | +import tools.jackson.core.unittest.testutil.AsyncReaderWrapper; |
| 10 | +import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.fail; |
| 13 | + |
| 14 | +// Tests for handling token decoding fails for Root values |
| 15 | +class AsyncTokenRootErrorTest extends AsyncTestBase |
| 16 | +{ |
| 17 | + private final JsonFactory JSON_F = newStreamFactory(); |
| 18 | + |
| 19 | + @JacksonTestFailureExpected |
| 20 | + @Test |
| 21 | + void mangledRootInts() throws Exception |
| 22 | + { |
| 23 | + try (AsyncReaderWrapper p = _createParser("123true")) { |
| 24 | + JsonToken t = p.nextToken(); |
| 25 | + fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue()); |
| 26 | + } catch (StreamReadException e) { |
| 27 | + verifyException(e, "expected space"); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + @JacksonTestFailureExpected |
| 32 | + @Test |
| 33 | + void mangledRootFloats() throws Exception |
| 34 | + { |
| 35 | + // Also test with floats |
| 36 | + try (AsyncReaderWrapper p = _createParser("1.5false")) { |
| 37 | + JsonToken t = p.nextToken(); |
| 38 | + fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue()); |
| 39 | + } catch (StreamReadException e) { |
| 40 | + verifyException(e, "expected space"); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private AsyncReaderWrapper _createParser(String doc) throws Exception |
| 45 | + { |
| 46 | + return asyncForBytes(JSON_F, 1, _jsonDoc(doc), 1); |
| 47 | + } |
| 48 | +} |
0 commit comments