|
10 | 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
11 | 11 |
|
12 | 12 | // For [dataformats-binary#245]: no pretty-printing for textual format |
13 | | -public class PrettyPrintWriteTest |
| 13 | +public class IonPrettyPrintWriteTest |
14 | 14 | { |
15 | 15 | @JsonPropertyOrder({ "x", "y" }) |
16 | 16 | static class Point { |
17 | 17 | public int x = 1; |
18 | 18 | public int y = 2; |
19 | 19 | } |
20 | 20 |
|
| 21 | + private final IonObjectMapper TEXTUAL_MAPPER = IonObjectMapper.builder(IonFactory.forTextualWriters()).build(); |
| 22 | + |
21 | 23 | @Test |
22 | | - public void testBasicPrettyPrintTextual() throws Exception |
| 24 | + public void prettyPrintTextual() throws Exception |
23 | 25 | { |
24 | 26 | final String EXP = "{\n x:1,\n y:2\n}"; |
25 | 27 |
|
26 | | - IonObjectMapper mapper = IonObjectMapper.builder(IonFactory.forTextualWriters()).build(); |
27 | | - String ion = mapper.writerWithDefaultPrettyPrinter() |
| 28 | + String ion = TEXTUAL_MAPPER.writerWithDefaultPrettyPrinter() |
28 | 29 | .writeValueAsString(new Point()); |
29 | 30 | assertEquals(EXP, ion.trim()); |
30 | 31 |
|
31 | | - ion = mapper.writer() |
| 32 | + ion = TEXTUAL_MAPPER.writer() |
32 | 33 | .with(SerializationFeature.INDENT_OUTPUT) |
33 | 34 | .writeValueAsString(new Point()); |
34 | 35 | assertEquals(EXP, ion.trim()); |
35 | 36 |
|
| 37 | + IonObjectMapper mapper = TEXTUAL_MAPPER.rebuild() |
| 38 | + .enable(SerializationFeature.INDENT_OUTPUT) |
| 39 | + .build(); |
| 40 | + ion = mapper.writeValueAsString(new Point()); |
| 41 | + assertEquals(EXP, ion.trim()); |
| 42 | + |
36 | 43 | // But also no indentation if not requested |
37 | 44 | ion = mapper.writer() |
| 45 | + .without(SerializationFeature.INDENT_OUTPUT) |
38 | 46 | .writeValueAsString(new Point()); |
39 | 47 | assertEquals("{x:1,y:2}", ion.trim()); |
40 | 48 | } |
41 | 49 |
|
42 | 50 | // and with binary format, should simply be no-op |
43 | 51 | @Test |
44 | | - public void testIgnorePrettyPrintForBinary() throws Exception |
| 52 | + public void prettyPrintIgnoredForBinary() throws Exception |
45 | 53 | { |
46 | 54 | IonObjectMapper mapper = IonObjectMapper.builder(IonFactory.forBinaryWriters()).build(); |
47 | 55 | byte[] encoded = mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(new Point()); |
|
0 commit comments