Skip to content

Commit dd5c9d9

Browse files
committed
Change a test a bit for 3.0-compatibility
1 parent 501f724 commit dd5c9d9

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/EnumAsIonSymbolSerializationTest.java

+37-28
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,57 @@
1414

1515
package com.fasterxml.jackson.dataformat.ion;
1616

17-
import java.io.IOException;
1817
import org.junit.Assert;
1918
import org.junit.Test;
2019
import com.amazon.ion.IonSystem;
20+
import com.amazon.ion.IonValue;
2121
import com.amazon.ion.system.IonSystemBuilder;
2222
import com.fasterxml.jackson.databind.SerializationFeature;
2323

24-
public class EnumAsIonSymbolSerializationTest {
24+
public class EnumAsIonSymbolSerializationTest
25+
{
26+
private enum SomeEnum {
27+
SOME_VALUE;
28+
29+
@Override
30+
public String toString() {
31+
return name().toLowerCase();
32+
}
33+
}
34+
2535
private static final IonSystem ION_SYSTEM = IonSystemBuilder.standard().build();
2636

2737
@Test
28-
public void testUsingName() throws IOException {
29-
final IonObjectMapper mapper = newMapper();
30-
31-
Assert.assertEquals(
32-
ION_SYSTEM.singleValue("SOME_VALUE"),
33-
mapper.writeValueAsIonValue(SomeEnum.SOME_VALUE));
38+
public void testUsingName() throws Exception
39+
{
40+
final IonValue EXP = ION_SYSTEM.singleValue("SOME_VALUE");
41+
Assert.assertEquals(EXP,
42+
newMapper(false, false).writeValueAsIonValue(SomeEnum.SOME_VALUE));
43+
Assert.assertEquals(EXP,
44+
newMapper(true, false).writeValueAsIonValue(SomeEnum.SOME_VALUE));
3445
}
3546

3647
@Test
37-
public void testUsingToString() throws IOException {
38-
final IonObjectMapper mapper = newMapper();
39-
40-
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
41-
42-
Assert.assertEquals(
43-
ION_SYSTEM.singleValue("some_value"),
44-
mapper.writeValueAsIonValue(SomeEnum.SOME_VALUE));
48+
public void testUsingToString() throws Exception
49+
{
50+
final IonValue EXP = ION_SYSTEM.singleValue("some_value");
51+
Assert.assertEquals(EXP,
52+
newMapper(false, true).writeValueAsIonValue(SomeEnum.SOME_VALUE));
53+
Assert.assertEquals(EXP,
54+
newMapper(true, true).writeValueAsIonValue(SomeEnum.SOME_VALUE));
4555
}
4656

47-
private static IonObjectMapper newMapper() {
48-
final IonObjectMapper mapper = new IonObjectMapper(new IonFactory(null, ION_SYSTEM));
49-
mapper.registerModule(new EnumAsIonSymbolModule());
57+
private static IonObjectMapper newMapper(boolean textual, boolean usingToString) {
58+
final IonFactory f = (textual
59+
? IonFactory.builderForTextualWriters()
60+
: IonFactory.builderForBinaryWriters()
61+
)
62+
.ionSystem(ION_SYSTEM)
63+
.build();
64+
final IonObjectMapper mapper = IonObjectMapper.builder(f)
65+
.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, usingToString)
66+
.addModule(new EnumAsIonSymbolModule())
67+
.build();
5068
return mapper;
5169
}
52-
53-
private enum SomeEnum {
54-
SOME_VALUE;
55-
56-
@Override
57-
public String toString() {
58-
return name().toLowerCase();
59-
}
60-
}
6170
}

0 commit comments

Comments
 (0)