diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/InstantSerializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/InstantSerializationTest.java index aaa06fa..796153c 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/InstantSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/InstantSerializationTest.java @@ -11,11 +11,10 @@ public class InstantSerializationTest extends JodaTestBase { - private final ObjectMapper MAPPER = jodaMapper(); - { - MAPPER.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - MAPPER.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); - } + private final ObjectMapper MAPPER = mapperWithModuleBuilder() + .enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) + .build(); public void testInstantSer() throws Exception { Instant instant = new Instant(0L); @@ -24,7 +23,7 @@ public void testInstantSer() throws Exception { assertEquals("0", MAPPER.writeValueAsString(instant)); // but if re-configured, as regular ISO-8601 string - assertEquals(quote("1970-01-01T00:00:00.000Z"), MAPPER.writer() + assertEquals(q("1970-01-01T00:00:00.000Z"), MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(instant)); } @@ -34,24 +33,22 @@ public void testCustomFormatInstantSer() throws Exception final String json = MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(new FormattedInstant(new Instant(0L))); - assertEquals(aposToQuotes( + assertEquals(a2q( "{'value':'01/01/1970 00_00_00_000'}"), json); } // [datatype-joda#60] public void testInstantConversion() throws Exception { - final ObjectMapper mapper = jodaMapper(); - - // Configure Date Formatting - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + final ObjectMapper mapper = mapperWithModuleBuilder() + // Configure Date Formatting + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")); // Create an instant and serialize and additionally serialize the instant as DateTime to demonstrate the difference org.joda.time.Instant now = new DateTime(1431498572205L).toInstant(); - - String instantString = mapper.writeValueAsString(now); - assertEquals("\"2015-05-13T06:29:32.205Z\"", instantString); + assertEquals("\"2015-05-13T06:29:32.205Z\"", mapper.writeValueAsString(now)); } } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/IntervalSerializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/IntervalSerializationTest.java index 9c47065..b446bb8 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/IntervalSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/IntervalSerializationTest.java @@ -1,7 +1,5 @@ package com.fasterxml.jackson.datatype.joda.ser; -import java.io.IOException; - import org.joda.time.DateTimeZone; import org.joda.time.Interval; @@ -28,31 +26,32 @@ static class FormattedInterval /********************************************************** */ - private final ObjectMapper MAPPER = jodaMapper(); - { - MAPPER.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - MAPPER.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); - } + private final ObjectMapper MAPPER = mapperWithModuleBuilder() + .enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) + .build(); + private final ObjectWriter WRITER = MAPPER.writer(); - public void testIntervalSerBasic() throws IOException + public void testIntervalSerBasic() throws Exception { Interval interval = new Interval(1396439982, 1396440001); - assertEquals(quote("1396439982-1396440001"), MAPPER.writeValueAsString(interval)); + assertEquals(q("1396439982-1396440001"), MAPPER.writeValueAsString(interval)); // related to #48 - assertEquals(quote("1970-01-17T03:53:59.982Z/1970-01-17T03:54:00.001Z"), + assertEquals(q("1970-01-17T03:53:59.982Z/1970-01-17T03:54:00.001Z"), WRITER.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) .writeValueAsString(interval)); } - public void testIntervalSerWithTypeInfo() throws IOException + public void testIntervalSerWithTypeInfo() throws Exception { Interval interval = new Interval(1396439982, 1396440001); - ObjectMapper mapper = jodaMapper(); - mapper.addMixIn(Interval.class, ObjectConfiguration.class); - assertEquals("[\"org.joda.time.Interval\"," + quote("1396439982-1396440001") + "]", + ObjectMapper mapper = mapperWithModuleBuilder() + .addMixIn(Interval.class, ObjectConfiguration.class) + .build(); + assertEquals("[\"org.joda.time.Interval\"," + q("1396439982-1396440001") + "]", mapper.writeValueAsString(interval)); } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/JodaSerializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/JodaSerializationTest.java index a508a97..3334f7b 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/JodaSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/JodaSerializationTest.java @@ -31,11 +31,10 @@ public T getContents() { } } - private final ObjectMapper MAPPER = jodaMapper(); - { - MAPPER.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - MAPPER.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); - } + private final ObjectMapper MAPPER = mapperWithModuleBuilder() + .enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) + .build(); private final ObjectWriter WRITER = MAPPER.writer(); @@ -74,9 +73,10 @@ public void testLocalDateSerWithTypeInfo() throws IOException // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - ObjectMapper mapper = jodaMapper(); - mapper.addMixIn(LocalDate.class, ObjectConfiguration.class); - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + ObjectMapper mapper = mapperWithModuleBuilder() + .addMixIn(LocalDate.class, ObjectConfiguration.class) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); assertEquals("[\"org.joda.time.LocalDate\",\"2001-05-25\"]", mapper.writeValueAsString(date)); } @@ -94,8 +94,9 @@ public void testLocalTimeSer() throws IOException // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - ObjectMapper mapper = jodaMapper(); - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + ObjectMapper mapper = mapperWithModuleBuilder() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); assertEquals(q("13:20:54.000"), mapper.writeValueAsString(date)); } @@ -127,9 +128,10 @@ public void testLocalTimeSerWithTypeInfo() throws IOException // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - ObjectMapper mapper = jodaMapper(); - mapper.addMixIn(LocalTime.class, ObjectConfiguration.class); - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + ObjectMapper mapper = mapperWithModuleBuilder() + .addMixIn(LocalTime.class, ObjectConfiguration.class) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); assertEquals("[\"org.joda.time.LocalTime\",\"13:20:54.000\"]", mapper.writeValueAsString(date)); } @@ -148,8 +150,9 @@ public void testLocalDateTimeSer() throws IOException assertEquals("[2001,5,25,10,15,30,37]", MAPPER.writeValueAsString(date)); // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - ObjectMapper mapper = jodaMapper(); - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + ObjectMapper mapper = mapperWithModuleBuilder() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); assertEquals(q("2001-05-25T10:15:30.037"), mapper.writeValueAsString(date)); } @@ -161,10 +164,12 @@ public void testLocalDateTimeSerWithTypeInfo() throws IOException assertEquals("[2001,5,25,10,15,30,37]", MAPPER.writeValueAsString(date)); // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - ObjectMapper mapper = jodaMapper(); - mapper.addMixIn(LocalDateTime.class, ObjectConfiguration.class); - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - assertEquals("[\"org.joda.time.LocalDateTime\",\"2001-05-25T10:15:30.037\"]", mapper.writeValueAsString(date)); + ObjectMapper mapper = mapperWithModuleBuilder() + .addMixIn(LocalDateTime.class, ObjectConfiguration.class) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); + assertEquals("[\"org.joda.time.LocalDateTime\",\"2001-05-25T10:15:30.037\"]", + mapper.writeValueAsString(date)); } /* @@ -182,8 +187,9 @@ public void testPeriodSer() throws IOException public void testPeriodSerWithTypeInfo() throws IOException { Period in = new Period(1, 2, 3, 4); - ObjectMapper mapper = jodaMapper(); - mapper.addMixIn(Period.class, ObjectConfiguration.class); + ObjectMapper mapper = mapperWithModuleBuilder() + .addMixIn(Period.class, ObjectConfiguration.class) + .build(); assertEquals("[\"org.joda.time.Period\",\"PT1H2M3.004S\"]", mapper.writeValueAsString(in)); } @@ -207,9 +213,10 @@ public void testDurationSer() throws IOException public void testDurationSerWithTypeInfo() throws IOException { Duration d = new Duration(3123422); - ObjectMapper mapper = jodaMapper(); - mapper.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); - mapper.addMixIn(Duration.class, ObjectConfiguration.class); + ObjectMapper mapper = mapperWithModuleBuilder() + .enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) + .addMixIn(Duration.class, ObjectConfiguration.class) + .build(); String json = mapper.writeValueAsString(d); assertEquals("[\"org.joda.time.Duration\",3123422]", json); } @@ -217,32 +224,28 @@ public void testDurationSerWithTypeInfo() throws IOException public void testMonthDaySer() throws Exception { MonthDay monthDay = new MonthDay(7, 23); - ObjectMapper mapper = jodaMapper(); - String json = mapper.writeValueAsString(monthDay); + String json = MAPPER.writeValueAsString(monthDay); assertEquals(q("--07-23"), json); } public void testCustomMonthDaySer() throws Exception { MonthDay monthDay = new MonthDay(7, 23); - ObjectMapper mapper = jodaMapper(); - String json = mapper.writeValueAsString(new FormattedMonthDay(monthDay)); + String json = MAPPER.writeValueAsString(new FormattedMonthDay(monthDay)); assertEquals(a2q("{'value':'07:23'}"), json); } public void testYearMonthSer() throws Exception { YearMonth yearMonth = new YearMonth(2013, 8); - ObjectMapper mapper = jodaMapper(); - String json = mapper.writeValueAsString(yearMonth); + String json = MAPPER.writeValueAsString(yearMonth); assertEquals(q("2013-08"), json); } public void testCustomYearMonthSer() throws Exception { YearMonth yearMonth = new YearMonth(2013, 8); - ObjectMapper mapper = jodaMapper(); - String json = mapper.writeValueAsString(new FormattedYearMonth(yearMonth)); + String json = MAPPER.writeValueAsString(new FormattedYearMonth(yearMonth)); assertEquals(a2q("{'value':'2013/08'}"), json); } } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/WriteZoneIdTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/WriteZoneIdTest.java index 1b73c2a..89e5c56 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/ser/WriteZoneIdTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/ser/WriteZoneIdTest.java @@ -24,7 +24,7 @@ public DummyClassWithDate(DateTime date) { public void testJacksonAnnotatedPOJOWithDateWithTimezoneToJson() throws Exception { - ObjectMapper mapper = jodaMapper(); + final ObjectMapper mapper = jodaMapper(); String ZONE_ID = "Asia/Krasnoyarsk"; DummyClassWithDate input = new DummyClassWithDate(new DateTime(2015, 11, 23, 22, 06, 39,