Skip to content

Commit ea6e8ea

Browse files
authored
Add test wrt #490, passing against 2.16 (#491)
1 parent 368ba69 commit ea6e8ea

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.fasterxml.jackson.dataformat.ion;
2+
3+
import java.util.*;
4+
import org.junit.Test;
5+
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
8+
import static org.junit.Assert.*;
9+
10+
// for [dataformats-binary#490]
11+
public class DatabindNumberRoundtrip490Test
12+
{
13+
private final IonObjectMapper BINARY_MAPPER = IonObjectMapper.builderForBinaryWriters()
14+
.build();
15+
private final IonObjectMapper TEXT_MAPPER = IonObjectMapper.builderForTextualWriters()
16+
.build();
17+
18+
@Test
19+
public void testBinaryFloats() throws Exception {
20+
_floatRoundtrip(BINARY_MAPPER);
21+
}
22+
23+
@Test
24+
public void testBinaryIntegers() throws Exception {
25+
_integerRoundtrip490(BINARY_MAPPER);
26+
}
27+
28+
@Test
29+
public void testTextualFloats() throws Exception {
30+
_floatRoundtrip(TEXT_MAPPER);
31+
}
32+
33+
@Test
34+
public void testTextualIntegers() throws Exception {
35+
_integerRoundtrip490(TEXT_MAPPER);
36+
}
37+
38+
private void _floatRoundtrip(ObjectMapper mapper) throws Exception
39+
{
40+
final double d = 42.25d;
41+
final float f = 42.75f;
42+
43+
_roundtrip490(mapper, d, d);
44+
45+
// Ion oddity: "float"s get upgraded to "double"s, so...
46+
_roundtrip490(mapper, f, (double) f);
47+
}
48+
49+
private void _integerRoundtrip490(ObjectMapper mapper) throws Exception
50+
{
51+
_roundtrip490(mapper, Integer.MAX_VALUE, Integer.MAX_VALUE);
52+
_roundtrip490(mapper, Long.MAX_VALUE, Long.MAX_VALUE);
53+
}
54+
55+
private void _roundtrip490(ObjectMapper mapper,
56+
Object input, Object result)
57+
throws Exception
58+
{
59+
byte[] serialized = mapper.writeValueAsBytes(Collections.singletonMap("k", input));
60+
61+
Map<?,?> deserialized = mapper.readValue(serialized, Map.class);
62+
assertEquals(result, deserialized.get("k"));
63+
}
64+
}

0 commit comments

Comments
 (0)