Skip to content

Commit 76648d0

Browse files
authored
Add failing test for #485 (#487)
1 parent c94cb96 commit 76648d0

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/NullWriting116Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class NullWriting116Test extends ModuleTestBase
1010
{
11-
private final CsvMapper csv = new CsvMapper();
11+
private final CsvMapper csv = mapperForCsv();
1212

1313
// [dataformat#116]
1414
public void testWithObjectArray() throws Exception

0 commit comments

Comments
 (0)