Skip to content

Commit 972d5a2

Browse files
committed
tiny test improvement
1 parent b3139d5 commit 972d5a2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
public class MiscJavaXMLTypesReadWriteTest
1616
extends BaseMapTest
1717
{
18+
private final ObjectMapper MAPPER = newJsonMapper();
19+
1820
/*
1921
/**********************************************************
2022
/* Serializer tests
@@ -40,19 +42,17 @@ public void testXMLGregorianCalendarSerAndDeser() throws Exception
4042
DatatypeFactory dtf = DatatypeFactory.newInstance();
4143
XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar
4244
(1974, 10, 10, 18, 15, 17, 123, 0);
43-
/* Due to [JACKSON-308], 1.6 will use configurable Date serialization;
44-
* and it defaults to using timestamp. So let's try couple of combinations.
45-
*/
46-
ObjectMapper mapper = new ObjectMapper();
45+
4746
long timestamp = cal.toGregorianCalendar().getTimeInMillis();
4847
String numStr = String.valueOf(timestamp);
49-
assertEquals(numStr, mapper.writeValueAsString(cal));
48+
assertEquals(numStr, MAPPER.writeValueAsString(cal));
5049

5150
// [JACKSON-403] Needs to come back ok as well:
52-
XMLGregorianCalendar calOut = mapper.readValue(numStr, XMLGregorianCalendar.class);
51+
XMLGregorianCalendar calOut = MAPPER.readValue(numStr, XMLGregorianCalendar.class);
5352
assertNotNull(calOut);
5453
assertEquals(timestamp, calOut.toGregorianCalendar().getTimeInMillis());
5554

55+
ObjectMapper mapper = new ObjectMapper();
5656
// and then textual variant
5757
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
5858
// this is ALMOST same as default for XMLGregorianCalendar... just need to unify Z/+0000
@@ -97,9 +97,8 @@ public void testQNameDeser() throws Exception
9797
{
9898
QName qn = new QName("http://abc", "tag", "prefix");
9999
String qstr = qn.toString();
100-
ObjectMapper mapper = new ObjectMapper();
101100
assertEquals("Should deserialize to equal QName (exp serialization: '"+qstr+"')",
102-
qn, mapper.readValue(q(qstr), QName.class));
101+
qn, MAPPER.readValue(q(qstr), QName.class));
103102
}
104103

105104
public void testCalendarDeser() throws Exception
@@ -109,7 +108,7 @@ public void testCalendarDeser() throws Exception
109108
(1974, 10, 10, 18, 15, 17, 123, 0);
110109
String exp = cal.toXMLFormat();
111110
assertEquals("Should deserialize to equal XMLGregorianCalendar ('"+exp+"')", cal,
112-
new ObjectMapper().readValue(q(exp), XMLGregorianCalendar.class));
111+
MAPPER.readValue(q(exp), XMLGregorianCalendar.class));
113112
}
114113

115114
public void testDurationDeser() throws Exception
@@ -119,6 +118,6 @@ public void testDurationDeser() throws Exception
119118
Duration dur = dtf.newDurationDayTime(true, 27, 5, 15, 59);
120119
String exp = dur.toString();
121120
assertEquals("Should deserialize to equal Duration ('"+exp+"')", dur,
122-
new ObjectMapper().readValue(q(exp), Duration.class));
121+
MAPPER.readValue(q(exp), Duration.class));
123122
}
124123
}

0 commit comments

Comments
 (0)