From e5ba92a63a57d6c0d72948507a51bcbff0d23569 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Mon, 27 Jan 2025 04:11:26 +0900 Subject: [PATCH] JSTEP-10 Migrate tests to Junit 5 (#155) --- pom.xml | 11 ++++++--- .../jackson/datatype/joda/AnnotationTest.java | 5 ++++ .../jackson/datatype/joda/DateTimeTest.java | 15 ++++++++++++ .../jackson/datatype/joda/JodaMapperTest.java | 13 ++++++----- .../jackson/datatype/joda/JodaTestBase.java | 11 +++------ .../jackson/datatype/joda/MixedListTest.java | 5 ++++ .../jackson/datatype/joda/TestVersions.java | 5 ++++ .../jackson/datatype/joda/TimeZoneTest.java | 23 +++++++++++++------ .../datatype/joda/depr/DateMidnightTest.java | 12 ++++++++++ .../joda/deser/DateTimeDeserTest.java | 16 ++++++++++++- .../joda/deser/DateTimeZoneDeserTest.java | 6 +++++ .../deser/DurationDeserializationTest.java | 13 +++++++++++ .../datatype/joda/deser/InstantDeserTest.java | 9 ++++++++ .../joda/deser/IntervalDeserTest.java | 10 ++++++++ .../datatype/joda/deser/KeyDeserTest.java | 8 +++++++ .../joda/deser/LocalDateDeserTest.java | 8 +++++++ .../joda/deser/LocalDateTimeDeserTest.java | 7 ++++++ .../joda/deser/LocalTimeDeserTest.java | 6 +++++ .../joda/deser/MonthDayDeserTest.java | 10 ++++++++ .../joda/deser/PeriodDeserializationTest.java | 7 ++++++ .../deser/ReadablePeriodDeserializerTest.java | 5 +++- .../joda/deser/YearMonthDeserTest.java | 9 ++++++++ ...teTimeSerializationWithOffsets146Test.java | 5 ++++ .../joda/ser/InstantSerializationTest.java | 7 ++++++ .../joda/ser/IntervalSerializationTest.java | 7 ++++++ .../joda/ser/JodaSerializationTest.java | 19 +++++++++++++++ .../datatype/joda/ser/WriteZoneIdTest.java | 5 ++++ 27 files changed, 231 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index d0f54dc8..9102a5d4 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,15 @@ ${version.joda} - + - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api test diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/AnnotationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/AnnotationTest.java index 1b9ad847..f4983c9f 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/AnnotationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/AnnotationTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.joda; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -9,6 +11,8 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class AnnotationTest extends DateTimeTest { static class AClass{ @@ -25,6 +29,7 @@ public void setCreatedOn(DateTime createdOn) { } } + @Test public void testDateTimeViaAnnotation() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); AClass initialObject = new AClass(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/DateTimeTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/DateTimeTest.java index 301ca467..05258bff 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/DateTimeTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/DateTimeTest.java @@ -5,6 +5,8 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; @@ -13,6 +15,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import static org.junit.jupiter.api.Assertions.*; + public class DateTimeTest extends JodaTestBase { static class DateAsText { @@ -91,6 +95,7 @@ private static interface TypeInfoMixIn { * First: let's ensure that serialization does not fail * with an error (see [JACKSON-157]). */ + @Test public void testSerializationDefaultAsTimestamp() throws IOException { // let's use epoch time (Jan 1, 1970, UTC) @@ -98,6 +103,7 @@ public void testSerializationDefaultAsTimestamp() throws IOException assertEquals("0", MAPPER.writeValueAsString(DATE_JAN_1_1970_UTC)); } + @Test public void testSerializationFeatureNoTimestamp() throws IOException { String json = MAPPER.writer() @@ -106,6 +112,7 @@ public void testSerializationFeatureNoTimestamp() throws IOException assertEquals(quote("1970-01-01T00:00:00.000Z"), json); } + @Test public void testAnnotationAsText() throws IOException { ObjectMapper m = jodaMapper(); @@ -116,12 +123,14 @@ public void testAnnotationAsText() throws IOException } // for [datatype-joda#70] + @Test public void testAsTextNoMilliseconds() throws Exception { DateTime value = MAPPER.readValue(quote("2015-07-27T08:11:07-07:00"), DateTime.class); assertNotNull(value); } + @Test public void testCustomPatternStyle() throws IOException { // or, using annotations @@ -140,6 +149,7 @@ public void testCustomPatternStyle() throws IOException assertEquals(aposToQuotes("{'date':'1/1/70 12:00 AM'}"), json); } + @Test public void testSerializationWithTypeInfo() throws IOException { // let's use epoch time (Jan 1, 1970, UTC) @@ -155,6 +165,7 @@ public void testSerializationWithTypeInfo() throws IOException m.writeValueAsString(dt)); } + @Test public void testIso8601ThroughJoda() throws Exception { ObjectMapper mapper = new ObjectMapper() .registerModule(new JodaModule()) @@ -181,6 +192,7 @@ public void testIso8601ThroughJoda() throws Exception { // assertEquals(expectedBean.jodaDateTime, actualBean.jodaDateTime); } + @Test public void testCustomFormat() throws Exception { String STR = "2015-06-19T19:05Z"; @@ -199,6 +211,7 @@ public void testCustomFormat() throws Exception assertEquals(inputDate.getMillis(), output.date.getMillis()); } + @Test public void testWithTimeZoneOverride() throws Exception { DateTime date = MAPPER.readValue(quote("2014-01-20T08:59:01.000-0500"), @@ -223,6 +236,7 @@ public void testWithTimeZoneOverride() throws Exception } // since 2.8 + @Test public void testConfigOverrides() throws Exception { ObjectMapper mapper = jodaMapper(); @@ -244,6 +258,7 @@ public void testConfigOverrides() throws Exception } // [datatype-joda#113] (NPE) + @Test public void testWithoutLeniency() throws Exception { ObjectMapper mapper = mapperWithModuleBuilder() diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaMapperTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaMapperTest.java index cf0a34f5..9f69cd5e 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaMapperTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaMapperTest.java @@ -1,23 +1,24 @@ package com.fasterxml.jackson.datatype.joda; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.SerializationFeature; -import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.CoreMatchers.is; +import static org.junit.jupiter.api.Assertions.*; public class JodaMapperTest { + @Test public void test_writeDatesAsTimestamps_property() { JodaMapper objectUnderTest = new JodaMapper(); objectUnderTest.setWriteDatesAsTimestamps(true); - assertThat(objectUnderTest.getWriteDatesAsTimestamps(), is(true)); + assertTrue(objectUnderTest.getWriteDatesAsTimestamps()); objectUnderTest.setWriteDatesAsTimestamps(false); - assertThat(objectUnderTest.getWriteDatesAsTimestamps(), is(false)); + assertFalse(objectUnderTest.getWriteDatesAsTimestamps()); } @Test @@ -27,6 +28,6 @@ public void setWriteDatesAsTimestamps_sets_the_WRITE_DATES_AS_TIMESTAMPS_configu objectUnderTest.setWriteDatesAsTimestamps(true); - assertThat(objectUnderTest.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS), is(true)); + assertTrue(objectUnderTest.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); } } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaTestBase.java b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaTestBase.java index 2765dd1d..d83dcedd 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaTestBase.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaTestBase.java @@ -2,8 +2,6 @@ import java.util.Arrays; -import junit.framework.TestCase; - import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; @@ -16,9 +14,9 @@ import org.joda.time.YearMonth; import org.joda.time.MonthDay; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public abstract class JodaTestBase extends TestCase +public abstract class JodaTestBase { protected static class FormattedInstant { @JsonFormat(pattern = "dd/MM/yyyy HH_mm_ss_SSS") @@ -78,10 +76,7 @@ protected static ObjectMapper mapperWithFailFromEmptyString() { /********************************************************** */ - protected void assertEquals(int[] exp, int[] act) { - assertArrayEquals(exp, act); - } - + /* /********************************************************** /* Helper methods diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java index c529c968..17d14fee 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java @@ -5,13 +5,18 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.jupiter.api.Assertions.*; + public class MixedListTest extends JodaTestBase { private final ObjectMapper MAPPER = jodaMapper(); + @Test public void testMixedList() throws Exception { final Map map = new HashMap(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/TestVersions.java b/src/test/java/com/fasterxml/jackson/datatype/joda/TestVersions.java index d82af955..4e952ef8 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/TestVersions.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/TestVersions.java @@ -2,13 +2,18 @@ import java.io.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.Versioned; +import static org.junit.jupiter.api.Assertions.*; + /** * Simple verification that version access works. */ public class TestVersions extends JodaTestBase { + @Test public void testVersions() throws IOException { JodaModule m = new JodaModule(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/TimeZoneTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/TimeZoneTest.java index bf5c9e40..70a99f82 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/TimeZoneTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/TimeZoneTest.java @@ -3,9 +3,13 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.*; +import static org.junit.jupiter.api.Assertions.*; + // for [datatype-joda#44] public class TimeZoneTest extends JodaTestBase { @@ -39,6 +43,7 @@ private static interface TypeInfoMixIn { private final ObjectMapper MAPPER = jodaMapper(); + @Test public void testSimple() throws Exception { // First, no zone id included @@ -73,6 +78,7 @@ public void testSimple() throws Exception * * https://github.com/FasterXML/jackson-datatype-joda/issues/73 */ + @Test public void testWriteDatesWithZoneIdAndConsistentZoneOffset() throws Exception { ObjectWriter w = MAPPER.writer(); @@ -84,6 +90,7 @@ public void testWriteDatesWithZoneIdAndConsistentZoneOffset() throws Exception .writeValueAsString(DATE_JAN_1_1970_UTC_IN_AMERICA_LA)); } + @Test public void testRoundTrip() throws Exception { ObjectWriter w = MAPPER.writer() @@ -99,14 +106,14 @@ public void testRoundTrip() throws Exception ObjectMapper mapper = jodaMapper(); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); result = mapper.readValue(json, DateTime.class); - assertEquals("Actual timepoints differ", input.getMillis(), result.getMillis()); - assertEquals("TimeZones differ", input, result); + assertEquals(input.getMillis(), result.getMillis(), "Actual timepoints differ"); + assertEquals(input, result, "TimeZones differ"); // Then timestamp: will not currently (2.6) write out timezone id json = w.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(input); result = mapper.readValue(json, DateTime.class); - assertEquals("Actual timepoints differ", input.getMillis(), result.getMillis()); + assertEquals(input.getMillis(), result.getMillis(), "Actual timepoints differ"); // .. meaning we can not test this: // assertEquals("TimeZones differ", input, result); @@ -116,6 +123,7 @@ public void testRoundTrip() throws Exception * Test that de/serializing an ambiguous time (e.g. a 'fall back' DST transition) works and preserves the proper * instants in time and time zones. */ + @Test public void testFallBackTransition() throws Exception { DateTime firstOneAmUtc = new DateTime(FALL_BACK_YEAR, FALL_BACK_MONTH, FALL_BACK_DAY, FIRST_FALL_BACK_HOUR, 0, 0, @@ -139,13 +147,14 @@ public void testFallBackTransition() throws Exception DateTime firstRoundTrip = mapper.readValue(firstOneAmStr, DateTime.class); DateTime secondRoundTrip = mapper.readValue(secondOneAmStr, DateTime.class); - assertEquals("Actual timepoints differ", firstOneAm.getMillis(), firstRoundTrip.getMillis()); - assertEquals("TimeZones differ", firstOneAm, firstRoundTrip); + assertEquals(firstOneAm.getMillis(), firstRoundTrip.getMillis(), "Actual timepoints differ"); + assertEquals(firstOneAm, firstRoundTrip, "TimeZones differ"); - assertEquals("Actual timepoints differ", secondOneAm.getMillis(), secondRoundTrip.getMillis()); - assertEquals("TimeZones differ", secondOneAm, secondRoundTrip); + assertEquals(secondOneAm.getMillis(), secondRoundTrip.getMillis(), "Actual timepoints differ"); + assertEquals(secondOneAm, secondRoundTrip, "TimeZones differ"); } + @Test public void testSerializationWithTypeInfo() throws Exception { // but if re-configured to include the time zone diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/depr/DateMidnightTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/depr/DateMidnightTest.java index addc6381..88006e6e 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/depr/DateMidnightTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/depr/DateMidnightTest.java @@ -5,6 +5,9 @@ import org.joda.time.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; @@ -12,6 +15,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + @SuppressWarnings("deprecation") // because DateMidnight deprecated by Joda public class DateMidnightTest extends JodaTestBase { @@ -54,6 +59,7 @@ public FormattedDateAsTimestamp(DateMidnight d) { /********************************************************** */ + @Test public void testDateMidnightDeserWithTimeZone() throws IOException { MAPPER.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); @@ -87,6 +93,7 @@ public void testDateMidnightDeserWithTimeZone() throws IOException assertNull(MAPPER.readValue(quote(""), DateMidnight.class)); } + @Test public void testDateMidnightDeser() throws IOException { // couple of acceptable formats, so: @@ -104,6 +111,7 @@ public void testDateMidnightDeser() throws IOException assertNull(MAPPER.readValue(quote(""), DateMidnight.class)); } + @Test public void testDateMidnightDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -127,6 +135,7 @@ public void testDateMidnightDeserWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testSerializeAsTimestamp() throws Exception { assertEquals(aposToQuotes("{'value':0}"), @@ -134,6 +143,7 @@ public void testSerializeAsTimestamp() throws Exception new DateMidnight(0, DateTimeZone.UTC)))); } + @Test public void testDateMidnightSer() throws IOException { ObjectMapper mapper = jodaMapper() @@ -162,6 +172,7 @@ public void testDateMidnightSer() throws IOException /********************************************************** */ + @Test public void testDeserWithCustomFormat() throws Exception { String STR = "2015-06-19"; @@ -179,6 +190,7 @@ public void testDeserWithCustomFormat() throws Exception assertEquals(inputDate, output.value); } + @Test public void testWithTimeZoneOverride() throws Exception { ObjectMapper mapper = jodaMapper(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeDeserTest.java index 8d755ef6..d4040b4f 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeDeserTest.java @@ -5,9 +5,12 @@ import java.util.GregorianCalendar; import java.util.TimeZone; -import com.fasterxml.jackson.annotation.JsonFormat; import org.joda.time.*; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonFormat; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -15,6 +18,8 @@ import com.fasterxml.jackson.databind.exc.InvalidFormatException; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for verifying limited interoperability for Joda time. * Basic support is added for handling {@link DateTime}; more can be @@ -67,6 +72,7 @@ public DateTime getJodaDateTime() { * Ok, then: should be able to convert from JSON String or Number, * with standard deserializer we provide. */ + @Test public void testDeserFromNumber() throws IOException { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); @@ -83,6 +89,7 @@ public void testDeserFromNumber() throws IOException assertEquals("1972-12-28T12:00:01.000Z", dt.toString()); } + @Test public void testDeserReadableDateTime() throws IOException { ReadableDateTime date = MAPPER.readValue(quote("1972-12-28T12:00:01.000+0000"), @@ -92,6 +99,7 @@ public void testDeserReadableDateTime() throws IOException } // [datatype-joda#8] + @Test public void testDeserReadableDateTimeWithTimeZoneInfo() throws IOException { TimeZone timeZone = TimeZone.getTimeZone("GMT-6"); @@ -110,6 +118,7 @@ public void testDeserReadableDateTimeWithTimeZoneInfo() throws IOException assertNull(MAPPER.readValue(quote(""), ReadableDateTime.class)); } + @Test public void testDeserReadableDateTimeWithTimeZoneFromData() throws IOException { ObjectMapper mapper = jodaMapper(); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); @@ -119,6 +128,7 @@ public void testDeserReadableDateTimeWithTimeZoneFromData() throws IOException { assertEquals(DateTimeZone.forOffsetHours(-5), date.getZone()); } + @Test public void testDeserReadableDateTimeWithContextTZOverride() throws IOException { ObjectMapper mapper = jodaMapper(); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); @@ -129,6 +139,7 @@ public void testDeserReadableDateTimeWithContextTZOverride() throws IOException assertEquals(expected, date.time); } + @Test public void testDeserReadableDateTimeWithoutContextTZOverride() throws IOException { ObjectMapper mapper = jodaMapper(); mapper.enable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); @@ -139,6 +150,7 @@ public void testDeserReadableDateTimeWithoutContextTZOverride() throws IOExcepti assertEquals(expected, date.time); } + @Test public void test_enable_ADJUST_DATES_TO_CONTEXT_TIME_ZONE() throws Exception { ObjectMapper mapper = jodaMapper(); @@ -148,6 +160,7 @@ public void test_enable_ADJUST_DATES_TO_CONTEXT_TIME_ZONE() throws Exception assertEquals(new DateTime(2016, 12, 31, 17, 1, 1, DateTimeZone.UTC), result); } + @Test public void test_disable_ADJUST_DATES_TO_CONTEXT_TIME_ZONE() throws Exception { ObjectMapper mapper = jodaMapper(); @@ -166,6 +179,7 @@ public void test_disable_ADJUST_DATES_TO_CONTEXT_TIME_ZONE() throws Exception */ // @since 2.12 + @Test public void testReadFromEmptyString() throws Exception { // By default, fine to deser from empty or blank diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeZoneDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeZoneDeserTest.java index 42871fe2..83d52597 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeZoneDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeZoneDeserTest.java @@ -4,6 +4,8 @@ import org.joda.time.DateTimeZone; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; @@ -11,6 +13,8 @@ import com.fasterxml.jackson.datatype.joda.JodaTestBase; import com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserTest.DateTimeZoneWrapper; +import static org.junit.jupiter.api.Assertions.*; + public class DateTimeZoneDeserTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -27,6 +31,7 @@ private static interface ObjectConfiguration { */ // [datatype-joda#82] + @Test public void testSimpleDateTimeZone() throws Exception { TimeZone timeZone = TimeZone.getTimeZone("GMT-6"); @@ -56,6 +61,7 @@ public void testSimpleDateTimeZone() throws Exception */ // @since 2.12 + @Test public void testReadFromEmptyString() throws Exception { // By default, fine to deser from empty or blank diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DurationDeserializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DurationDeserializationTest.java index ab30ca7a..94aabe1e 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DurationDeserializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/DurationDeserializationTest.java @@ -5,6 +5,8 @@ import org.joda.time.Duration; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.core.type.TypeReference; @@ -15,6 +17,8 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class DurationDeserializationTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY) @@ -30,24 +34,28 @@ private static interface ObjectConfiguration { private final ObjectMapper MAPPER = jodaMapper(); private final ObjectReader READER = MAPPER.readerFor(Duration.class); + @Test public void testDurationDeserFromInt() throws IOException { Duration d = READER.readValue("1234"); assertEquals(1234, d.getMillis()); } + @Test public void testDurationDeserFromString() throws IOException { Duration d = READER.readValue(quote("PT1.234S")); assertEquals(1234, d.getMillis()); } + @Test public void testDurationRoundtrip() throws IOException { Duration d = new Duration(5513); assertEquals(d, READER.readValue(MAPPER.writeValueAsString(d))); } + @Test public void testDurationFailsDeserializingUnexpectedType() throws IOException { try { @@ -59,6 +67,7 @@ public void testDurationFailsDeserializingUnexpectedType() throws IOException } } + @Test public void testDurationDeserFromIntWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -74,6 +83,7 @@ public void testDurationDeserFromIntWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testDurationKeyDeserialize() throws IOException { final String json = "{" + quote("PT60s") + ":0}"; @@ -91,6 +101,7 @@ public void testDurationKeyDeserialize() throws IOException // [datatype-joda#90]: Possibly support wider set of representations + @Test public void testDurationAltFromString() throws IOException { Duration d = MAPPER.readValue(quote("PT1H"), Duration.class); @@ -100,6 +111,7 @@ public void testDurationAltFromString() throws IOException assertEquals(4 * 60 + 30, d.getStandardMinutes()); } + @Test public void testDurationAltKeyDeserialize() throws IOException { final String json = "{" + quote("PT4H30M") + ":0}"; @@ -116,6 +128,7 @@ public void testDurationAltKeyDeserialize() throws IOException */ // @since 2.12 + @Test public void testReadFromEmptyString() throws Exception { // By default, fine to deser from empty or blank diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/InstantDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/InstantDeserTest.java index 4f2e2ce2..59499bcf 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/InstantDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/InstantDeserTest.java @@ -9,9 +9,13 @@ import org.joda.time.Instant; import org.joda.time.ReadableInstant; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class InstantDeserTest extends JodaTestBase { /* @@ -22,6 +26,7 @@ public class InstantDeserTest extends JodaTestBase private final ObjectMapper MAPPER = jodaMapper(); + @Test public void testDeserReadableInstant() throws IOException { ReadableInstant date = MAPPER.readValue(quote("1972-12-28T12:00:01.000+0000"), ReadableInstant.class); assertNotNull(date); @@ -30,6 +35,7 @@ public void testDeserReadableInstant() throws IOException { assertNull(MAPPER.readValue(quote(""), ReadableInstant.class)); } + @Test public void testDeserInstantWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -40,6 +46,7 @@ public void testDeserInstantWithTypeInfo() throws IOException assertEquals("1972-12-28T12:00:01.000Z", date.toString()); } + @Test public void testDeserInstantFromNumber() throws IOException { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -51,6 +58,7 @@ public void testDeserInstantFromNumber() throws IOException assertEquals(timepoint, instant.getMillis()); } + @Test public void testDeserInstant() throws IOException { Instant date = MAPPER.readValue(quote("1972-12-28T12:00:01.000Z"), Instant.class); @@ -60,6 +68,7 @@ public void testDeserInstant() throws IOException assertNull(MAPPER.readValue(quote(""), Instant.class)); } + @Test public void testDeserInstantCustomFormat() throws IOException { FormattedInstant input = MAPPER.readValue(aposToQuotes( diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserTest.java index 45cc5c86..f2ba4151 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserTest.java @@ -8,10 +8,14 @@ import org.joda.time.Interval; import org.joda.time.chrono.ISOChronology; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class IntervalDeserTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -26,6 +30,7 @@ private static interface ObjectConfiguration { /********************************************************** */ + @Test public void testIntervalDeser() throws IOException { Interval interval = MAPPER.readValue(quote("1396439982-1396440001"), Interval.class); @@ -39,6 +44,7 @@ public void testIntervalDeser() throws IOException assertEquals(ISOChronology.getInstance(DateTimeZone.UTC), interval.getChronology()); } + @Test public void testIntervalDeserWithTimeZone() throws IOException { MAPPER.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); @@ -56,6 +62,7 @@ public void testIntervalDeserWithTimeZone() throws IOException assertEquals(ISOChronology.getInstance(DateTimeZone.forID("America/Los_Angeles")), interval.getChronology()); } + @Test public void testIntervalDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -66,6 +73,7 @@ public void testIntervalDeserWithTypeInfo() throws IOException assertEquals(1396440001, interval.getEndMillis()); } + @Test public void testIntervalDeserFromIso8601WithTimezoneWithContextTimeZone() throws IOException { final ObjectMapper mapper = mapperWithModuleBuilder() @@ -79,6 +87,7 @@ public void testIntervalDeserFromIso8601WithTimezoneWithContextTimeZone() throws assertEquals(expectedInterval, actualInterval); } + @Test public void testIntervalDeserFromIso8601WithTimezoneWithoutContextTimeZone() throws IOException { final ObjectMapper mapper = mapperWithModuleBuilder() @@ -91,6 +100,7 @@ public void testIntervalDeserFromIso8601WithTimezoneWithoutContextTimeZone() thr assertEquals(expectedInterval, actualInterval); } + @Test public void testIntervalDeserFromIso8601WithTimezoneWithDefaultTimeZone() throws IOException { final ObjectMapper mapper = mapperWithModuleBuilder() diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/KeyDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/KeyDeserTest.java index d0ea0d59..4152ee69 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/KeyDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/KeyDeserTest.java @@ -8,10 +8,14 @@ import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class KeyDeserTest extends JodaTestBase { /* @@ -28,6 +32,7 @@ public class KeyDeserTest extends JodaTestBase /********************************************************** */ + @Test public void testDateTimeKeyDeserialize() throws IOException { final String json = "{" + quote("1970-01-01T00:00:00.000Z") + ":0}"; @@ -37,6 +42,7 @@ public void testDateTimeKeyDeserialize() throws IOException { assertTrue(map.containsKey(DateTime.parse("1970-01-01T00:00:00.000Z"))); } + @Test public void testLocalDateKeyDeserialize() throws IOException { final String json = "{" + quote("2014-05-23") + ":0}"; @@ -46,6 +52,7 @@ public void testLocalDateKeyDeserialize() throws IOException { assertTrue(map.containsKey(LocalDate.parse("2014-05-23"))); } + @Test public void testLocalTimeKeyDeserialize() throws IOException { final String json = "{" + quote("00:00:00.000") + ":0}"; @@ -53,6 +60,7 @@ public void testLocalTimeKeyDeserialize() throws IOException { assertNotNull(map); assertTrue(map.containsKey(LocalTime.parse("00:00:00.000"))); } + @Test public void testLocalDateTimeKeyDeserialize() throws IOException { final String json = "{" + quote("2014-05-23T00:00:00.000") + ":0}"; diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserTest.java index 204c32f7..abe6ff8b 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateDeserTest.java @@ -6,10 +6,14 @@ import org.joda.time.LocalDate; import org.joda.time.chrono.ISOChronology; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class LocalDateDeserTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY) @@ -30,6 +34,7 @@ private static interface ObjectConfiguration { /********************************************************** */ + @Test public void testLocalDateDeser() throws IOException { // couple of acceptable formats, so: @@ -47,6 +52,7 @@ public void testLocalDateDeser() throws IOException assertNull(MAPPER.readValue(quote(""), LocalDate.class)); } + @Test public void testLocalDateDeserWithTimeZone() throws IOException { final String trickyInstant = "1238558582001"; @@ -85,6 +91,7 @@ public void testLocalDateDeserWithTimeZone() throws IOException assertEquals(ISOChronology.getInstanceUTC(), date4.getChronology()); } + @Test public void testLocalDateDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -102,6 +109,7 @@ public void testLocalDateDeserWithTypeInfo() throws IOException assertEquals(13, date2.getDayOfMonth()); } + @Test public void testLocalDateDeserWithPartsAsString() throws IOException { // couple of acceptable formats, so: diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateTimeDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateTimeDeserTest.java index d4e2a2c7..cd384ff3 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateTimeDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalDateTimeDeserTest.java @@ -6,10 +6,14 @@ import org.joda.time.LocalDateTime; import org.joda.time.chrono.ISOChronology; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class LocalDateTimeDeserTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -24,6 +28,7 @@ private static interface ObjectConfiguration { /********************************************************** */ + @Test public void testLocalDateTimeDeser() throws IOException { // couple of acceptable formats again: @@ -62,6 +67,7 @@ public void testLocalDateTimeDeser() throws IOException assertEquals(ISOChronology.getInstanceUTC(), date3.getChronology()); } + @Test public void testLocalDateTimeDeserWithTimeZone() throws IOException { MAPPER.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); @@ -94,6 +100,7 @@ public void testLocalDateTimeDeserWithTimeZone() throws IOException assertNull(MAPPER.readValue(quote(""), LocalDateTime.class)); } + @Test public void testLocalDateTimeDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalTimeDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalTimeDeserTest.java index dcd9413f..4e942df7 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalTimeDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/LocalTimeDeserTest.java @@ -4,10 +4,14 @@ import org.joda.time.LocalTime; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class LocalTimeDeserTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY) @@ -22,6 +26,7 @@ private static interface ObjectConfiguration { /********************************************************** */ + @Test public void testLocalTimeDeser() throws IOException { // couple of acceptable formats, so: @@ -41,6 +46,7 @@ public void testLocalTimeDeser() throws IOException assertNull(MAPPER.readValue(quote(""), LocalTime.class)); } + @Test public void testLocalTimeDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MonthDayDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MonthDayDeserTest.java index 56bb9ac2..ecdb871e 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MonthDayDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MonthDayDeserTest.java @@ -5,11 +5,15 @@ import org.joda.time.MonthDay; import org.joda.time.chrono.ISOChronology; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.MismatchedInputException; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class MonthDayDeserTest extends JodaTestBase { /* @@ -20,6 +24,7 @@ public class MonthDayDeserTest extends JodaTestBase private final ObjectMapper MAPPER = jodaMapper(); + @Test public void testDeserMonthDay() throws Exception { String monthDayString = new MonthDay(7, 23).toString(); @@ -27,6 +32,7 @@ public void testDeserMonthDay() throws Exception assertEquals(new MonthDay(7, 23), monthDay); } + @Test public void testDeserMonthDayWithTimeZone() throws Exception { MAPPER.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); @@ -38,12 +44,14 @@ public void testDeserMonthDayWithTimeZone() throws Exception assertEquals(ISOChronology.getInstanceUTC(), monthDay.getChronology()); } + @Test public void testDeserMonthDayFromEmptyString() throws Exception { MonthDay monthDay = MAPPER.readValue(quote(""), MonthDay.class); assertNull(monthDay); } + @Test public void testDeserMonthDayFailsForUnexpectedType() throws Exception { try { @@ -55,6 +63,7 @@ public void testDeserMonthDayFailsForUnexpectedType() throws Exception } } + @Test public void testDeserMonthDayCustomFormat() throws Exception { FormattedMonthDay input = MAPPER.readValue(aposToQuotes( @@ -65,6 +74,7 @@ public void testDeserMonthDayCustomFormat() throws Exception assertEquals(20, monthDay.getDayOfMonth()); } + @Test public void testDeserMonthDayConfigOverride() throws Exception { ObjectMapper mapper = jodaMapper(); diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/PeriodDeserializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/PeriodDeserializationTest.java index 10857c3a..2627ebae 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/PeriodDeserializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/PeriodDeserializationTest.java @@ -5,11 +5,15 @@ import org.joda.time.Period; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class PeriodDeserializationTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -24,6 +28,7 @@ private static interface ObjectConfiguration { /********************************************************** */ + @Test public void testPeriodDeser() throws IOException { Period out = MAPPER.readValue(quote("PT1H2M3.004S"), Period.class); @@ -42,6 +47,7 @@ public void testPeriodDeser() throws IOException assertEquals(0, out.getMillis()); } + @Test public void testPeriodDeserWithTypeInfo() throws IOException { ObjectMapper mapper = jodaMapper(); @@ -69,6 +75,7 @@ public void testPeriodDeserWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testPeriodKeyDeserialize() throws IOException { final String json = "{" + quote("PT1H2M3.004S") + ":0}"; diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/ReadablePeriodDeserializerTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/ReadablePeriodDeserializerTest.java index f3e4daf2..e6e39a84 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/ReadablePeriodDeserializerTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/ReadablePeriodDeserializerTest.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.datatype.joda.deser; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; import org.joda.time.Days; @@ -12,6 +11,10 @@ import org.joda.time.Weeks; import org.joda.time.Years; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class ReadablePeriodDeserializerTest extends JodaTestBase { diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/YearMonthDeserTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/YearMonthDeserTest.java index 58c37ed3..b78eaf4d 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/deser/YearMonthDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/YearMonthDeserTest.java @@ -6,12 +6,16 @@ import org.joda.time.YearMonth; import org.joda.time.chrono.ISOChronology; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.exc.InvalidFormatException; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class YearMonthDeserTest extends JodaTestBase { /* @@ -23,6 +27,7 @@ public class YearMonthDeserTest extends JodaTestBase private final ObjectMapper MAPPER = jodaMapper(); private final ObjectReader READER = MAPPER.readerFor(YearMonth.class); + @Test public void testDeserYearMonth() throws Exception { String yearMonthString = new YearMonth(2013, 8).toString(); @@ -30,6 +35,7 @@ public void testDeserYearMonth() throws Exception assertEquals(new YearMonth(2013, 8), yearMonth); } + @Test public void testDeserYearMonthWithTimeZone() throws Exception { MAPPER.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); @@ -40,6 +46,7 @@ public void testDeserYearMonthWithTimeZone() throws Exception assertEquals(ISOChronology.getInstanceUTC(), yearMonth.getChronology()); } + @Test public void testDeserYearMonthFailsForUnexpectedType() throws IOException { try { @@ -51,6 +58,7 @@ public void testDeserYearMonthFailsForUnexpectedType() throws IOException } } + @Test public void testDeserYearMonthCustomFormat() throws IOException { FormattedYearMonth input = MAPPER.readValue(aposToQuotes( @@ -68,6 +76,7 @@ public void testDeserYearMonthCustomFormat() throws IOException */ // @since 2.12 + @Test public void testReadFromEmptyString() throws Exception { // By default, fine to deser from empty or blank diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java b/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java index 16ea91b1..70d008d3 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java @@ -8,9 +8,14 @@ import org.joda.time.*; // [datatype-joda#146]: disable overwriting of timezone +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class DateTimeSerializationWithOffsets146Test extends JodaTestBase { // [datatype-joda#146] + @Test public void testLocalDateSerDefault() throws Exception { final String inputStr = "2024-12-01T12:00:00+02:00"; 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 796153c6..f59c09fc 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 @@ -5,10 +5,14 @@ import org.joda.time.DateTime; import org.joda.time.Instant; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class InstantSerializationTest extends JodaTestBase { private final ObjectMapper MAPPER = mapperWithModuleBuilder() @@ -16,6 +20,7 @@ public class InstantSerializationTest extends JodaTestBase .enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) .build(); + @Test public void testInstantSer() throws Exception { Instant instant = new Instant(0L); @@ -28,6 +33,7 @@ public void testInstantSer() throws Exception { .writeValueAsString(instant)); } + @Test public void testCustomFormatInstantSer() throws Exception { final String json = MAPPER.writer() @@ -38,6 +44,7 @@ public void testCustomFormatInstantSer() throws Exception } // [datatype-joda#60] + @Test public void testInstantConversion() throws Exception { final ObjectMapper mapper = mapperWithModuleBuilder() 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 b446bb82..24d6cdd9 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 @@ -3,11 +3,15 @@ import org.joda.time.DateTimeZone; import org.joda.time.Interval; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class IntervalSerializationTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -33,6 +37,7 @@ static class FormattedInterval private final ObjectWriter WRITER = MAPPER.writer(); + @Test public void testIntervalSerBasic() throws Exception { Interval interval = new Interval(1396439982, 1396440001); @@ -44,6 +49,7 @@ public void testIntervalSerBasic() throws Exception .writeValueAsString(interval)); } + @Test public void testIntervalSerWithTypeInfo() throws Exception { Interval interval = new Interval(1396439982, 1396440001); @@ -55,6 +61,7 @@ public void testIntervalSerWithTypeInfo() throws Exception mapper.writeValueAsString(interval)); } + @Test public void testWithTimeZoneOverride() throws Exception { Interval int1 = new Interval(1396439982, 1396440001); 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 3334f7bd..ad8badd9 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 @@ -1,5 +1,7 @@ package com.fasterxml.jackson.datatype.joda.ser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; @@ -13,6 +15,8 @@ import java.io.IOException; +import static org.junit.jupiter.api.Assertions.*; + public class JodaSerializationTest extends JodaTestBase { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class") @@ -44,6 +48,7 @@ public T getContents() { /********************************************************** */ + @Test public void testLocalDateSer() throws IOException { LocalDate date = new LocalDate(2001, 5, 25); @@ -65,6 +70,7 @@ public void testLocalDateSer() throws IOException assertEquals("{}", mapper.writeValueAsString(new Container(null))); } + @Test public void testLocalDateSerWithTypeInfo() throws IOException { LocalDate date = new LocalDate(2001, 5, 25); @@ -86,6 +92,7 @@ public void testLocalDateSerWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testLocalTimeSer() throws IOException { LocalTime date = new LocalTime(13,20,54); @@ -101,6 +108,7 @@ public void testLocalTimeSer() throws IOException } + @Test public void testLocalTimeSerWithFormatOverride() throws IOException { LocalTime date = new LocalTime(13,20,54); @@ -120,6 +128,7 @@ public void testLocalTimeSerWithFormatOverride() throws IOException } + @Test public void testLocalTimeSerWithTypeInfo() throws IOException { LocalTime date = new LocalTime(13,20,54); @@ -142,6 +151,7 @@ public void testLocalTimeSerWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testLocalDateTimeSer() throws IOException { LocalDateTime date = new LocalDateTime(2001, 5, 25, @@ -156,6 +166,7 @@ public void testLocalDateTimeSer() throws IOException assertEquals(q("2001-05-25T10:15:30.037"), mapper.writeValueAsString(date)); } + @Test public void testLocalDateTimeSerWithTypeInfo() throws IOException { LocalDateTime date = new LocalDateTime(2001, 5, 25, @@ -178,12 +189,14 @@ public void testLocalDateTimeSerWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testPeriodSer() throws IOException { Period in = new Period(1, 2, 3, 4); assertEquals(q("PT1H2M3.004S"), MAPPER.writeValueAsString(in)); } + @Test public void testPeriodSerWithTypeInfo() throws IOException { Period in = new Period(1, 2, 3, 4); @@ -199,6 +212,7 @@ public void testPeriodSerWithTypeInfo() throws IOException /********************************************************** */ + @Test public void testDurationSer() throws IOException { Duration d = new Duration(3123422); @@ -210,6 +224,7 @@ public void testDurationSer() throws IOException .writeValueAsString(d)); } + @Test public void testDurationSerWithTypeInfo() throws IOException { Duration d = new Duration(3123422); @@ -221,6 +236,7 @@ public void testDurationSerWithTypeInfo() throws IOException assertEquals("[\"org.joda.time.Duration\",3123422]", json); } + @Test public void testMonthDaySer() throws Exception { MonthDay monthDay = new MonthDay(7, 23); @@ -228,6 +244,7 @@ public void testMonthDaySer() throws Exception assertEquals(q("--07-23"), json); } + @Test public void testCustomMonthDaySer() throws Exception { MonthDay monthDay = new MonthDay(7, 23); @@ -235,6 +252,7 @@ public void testCustomMonthDaySer() throws Exception assertEquals(a2q("{'value':'07:23'}"), json); } + @Test public void testYearMonthSer() throws Exception { YearMonth yearMonth = new YearMonth(2013, 8); @@ -242,6 +260,7 @@ public void testYearMonthSer() throws Exception assertEquals(q("2013-08"), json); } + @Test public void testCustomYearMonthSer() throws Exception { YearMonth yearMonth = new YearMonth(2013, 8); 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 89e5c56b..fcaf54f1 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 @@ -3,10 +3,14 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.joda.JodaTestBase; +import static org.junit.jupiter.api.Assertions.*; + public class WriteZoneIdTest extends JodaTestBase { static class DummyClassWithDate { @@ -22,6 +26,7 @@ public DummyClassWithDate(DateTime date) { } } + @Test public void testJacksonAnnotatedPOJOWithDateWithTimezoneToJson() throws Exception { final ObjectMapper mapper = jodaMapper();