|
| 1 | +package com.fasterxml.jackson.dataformat.csv.failing; |
| 2 | + |
| 3 | +import java.math.BigInteger; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
| 6 | +import com.fasterxml.jackson.core.exc.StreamReadException; |
| 7 | +import com.fasterxml.jackson.databind.ObjectReader; |
| 8 | +import com.fasterxml.jackson.dataformat.csv.CsvMapper; |
| 9 | +import com.fasterxml.jackson.dataformat.csv.CsvSchema; |
| 10 | +import com.fasterxml.jackson.dataformat.csv.ModuleTestBase; |
| 11 | + |
| 12 | +public class IntOverflow485Test extends ModuleTestBase |
| 13 | +{ |
| 14 | + // [dataformats-text#485] |
| 15 | + @JsonPropertyOrder({ "testInt", "testLong" }) |
| 16 | + static class Numbers485 { |
| 17 | + public int intValue; |
| 18 | + public long longValue; |
| 19 | + } |
| 20 | + |
| 21 | + private final CsvMapper MAPPER = mapperForCsv(); |
| 22 | + private final ObjectReader READER = MAPPER.readerWithSchemaFor(Numbers485.class); |
| 23 | + |
| 24 | + // [dataformats-text#485] |
| 25 | + |
| 26 | + // First test that regular parsing works |
| 27 | + public void testNoOverflow485() throws Exception |
| 28 | + { |
| 29 | + Numbers485 result = READER.readValue(csv485(13, 42L)); |
| 30 | + assertEquals(13, result.intValue); |
| 31 | + assertEquals(42L, result.longValue); |
| 32 | + } |
| 33 | + |
| 34 | + public void testIntOverflow() throws Exception |
| 35 | + { |
| 36 | + try { |
| 37 | + Numbers485 result = READER.readValue(csv485("111111111111111111111111111111111111111111", "0")); |
| 38 | + fail("Should not pass; got: "+result.intValue); |
| 39 | + } catch (StreamReadException e) { |
| 40 | + verifyException(e, "CHANGE THIS"); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public void testLongOverflow() throws Exception |
| 45 | + { |
| 46 | + try { |
| 47 | + Numbers485 result = READER.readValue(csv485("0", |
| 48 | + "2222222222222222222222222222222222222222")); |
| 49 | + fail("Should not pass; got: "+result.longValue); |
| 50 | + } catch (StreamReadException e) { |
| 51 | + verifyException(e, "CHANGE THIS"); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private static String csv485(Object intValue, Object longValue) { |
| 56 | + return intValue+","+longValue+"\n"; |
| 57 | + } |
| 58 | +} |
0 commit comments