Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 26, 2025
2 parents 736f69b + e5ba92a commit c3d435e
Show file tree
Hide file tree
Showing 27 changed files with 307 additions and 108 deletions.
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ Joda (https://www.joda.org/joda-time/) data types.

<!-- And obviously also depends on Joda lib -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${version.joda}</version>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${version.joda}</version>
</dependency>

<!-- 20-Apr-2024, tatu: JUnit4 no longer from jackson-base, so: -->
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
requires org.joda.time;

// Additional test lib/framework dependencies
requires junit; // JUnit 4
requires org.junit.jupiter.api; // JUnit 5

// Further, need to open up test packages for JUnit et al
opens tools.jackson.datatype.joda;
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/tools/jackson/datatype/joda/AnnotationTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package tools.jackson.datatype.joda;

import org.junit.jupiter.api.Test;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.annotation.JsonDeserialize;
import tools.jackson.databind.annotation.JsonSerialize;
import tools.jackson.datatype.joda.deser.DateTimeDeserializer;
import tools.jackson.datatype.joda.ser.DateTimeSerializer;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AnnotationTest extends DateTimeTest
{
Expand All @@ -25,6 +29,7 @@ public void setCreatedOn(DateTime createdOn) {
}
}

@Test
public void testDateTimeViaAnnotation() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
AClass initialObject = new AClass();
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/tools/jackson/datatype/joda/DateTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +17,8 @@
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;

import static org.junit.jupiter.api.Assertions.*;

public class DateTimeTest extends JodaTestBase
{
static class DateAsText {
Expand Down Expand Up @@ -93,13 +97,15 @@ 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)
// by default, dates use timestamp, so:
assertEquals("0", MAPPER.writeValueAsString(DATE_JAN_1_1970_UTC));
}

@Test
public void testSerializationFeatureNoTimestamp() throws IOException
{
String json = MAPPER.writer()
Expand All @@ -108,6 +114,7 @@ public void testSerializationFeatureNoTimestamp() throws IOException
assertEquals(quote("1970-01-01T00:00:00.000Z"), json);
}

@Test
public void testAnnotationAsText() throws IOException
{
ObjectMapper m = mapperWithModuleBuilder()
Expand All @@ -119,12 +126,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
Expand All @@ -143,6 +152,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)
Expand All @@ -159,6 +169,7 @@ public void testSerializationWithTypeInfo() throws IOException
m.writeValueAsString(dt));
}

@Test
public void testIso8601ThroughJoda() throws Exception {
ObjectMapper mapper = mapperWithModuleBuilder()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
Expand All @@ -185,6 +196,7 @@ public void testIso8601ThroughJoda() throws Exception {
// assertEquals(expectedBean.jodaDateTime, actualBean.jodaDateTime);
}

@Test
public void testCustomFormat() throws Exception
{
String STR = "2015-06-19T19:05Z";
Expand All @@ -203,6 +215,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"),
Expand All @@ -227,6 +240,7 @@ public void testWithTimeZoneOverride() throws Exception
}

// since 2.8
@Test
public void testConfigOverrides() throws Exception
{
ObjectMapper mapper = mapperWithModuleBuilder()
Expand All @@ -249,6 +263,7 @@ public void testConfigOverrides() throws Exception
}

// [datatype-joda#113] (NPE)
@Test
public void testWithoutLeniency() throws Exception
{
ObjectMapper mapper = mapperWithModuleBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import tools.jackson.databind.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JDKSerializabilityTest extends JodaTestBase
{
@Test
public void testMapperWithModule() throws Exception {
final DateTime input = new DateTime(0L, DateTimeZone.UTC);
ObjectMapper mapper = mapperWithModule();
Expand Down
17 changes: 6 additions & 11 deletions src/test/java/tools/jackson/datatype/joda/JodaTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.Arrays;
import java.util.TimeZone;

import junit.framework.TestCase;
import org.joda.time.Instant;
import org.joda.time.YearMonth;
import org.joda.time.MonthDay;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
Expand All @@ -13,13 +15,9 @@
import tools.jackson.databind.cfg.CoercionInputShape;
import tools.jackson.databind.json.JsonMapper;

import org.joda.time.Instant;
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")
Expand Down Expand Up @@ -98,10 +96,7 @@ protected static JsonMapper mapperWithFailFromEmptyString() {
/**********************************************************************
*/

protected void assertEquals(int[] exp, int[] act) {
assertArrayEquals(exp, act);
}


/*
/**********************************************************************
/* Helper methods
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/tools/jackson/datatype/joda/MixedListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import java.util.*;

import org.junit.jupiter.api.Test;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.*;

public class MixedListTest extends JodaTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

@Test
public void testMixedList() throws Exception
{
final Map<String, Object> map = new HashMap<String, Object>();
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/tools/jackson/datatype/joda/TestVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import tools.jackson.core.Versioned;

import static org.junit.jupiter.api.Assertions.*;

/**
* Simple verification that version access works.
*/
public class TestVersions extends JodaTestBase
{
public void testVersions() throws IOException
@Test
public void testVersions() throws Exception
{
JodaModule m = new JodaModule();
assertVersion(m);
Expand Down
23 changes: 16 additions & 7 deletions src/test/java/tools/jackson/datatype/joda/TimeZoneTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tools.jackson.datatype.joda;

import org.junit.jupiter.api.Test;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

Expand All @@ -9,6 +11,8 @@

import tools.jackson.databind.*;

import static org.junit.jupiter.api.Assertions.*;

// for [datatype-joda#44]
public class TimeZoneTest extends JodaTestBase
{
Expand Down Expand Up @@ -44,6 +48,7 @@ private static interface TypeInfoMixIn {
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.build();

@Test
public void testSimple() throws Exception
{
// First, no zone id included
Expand Down Expand Up @@ -78,6 +83,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();
Expand All @@ -89,6 +95,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()
Expand All @@ -105,14 +112,14 @@ public void testRoundTrip() throws Exception
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.build();
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);
Expand All @@ -122,6 +129,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,
Expand All @@ -146,13 +154,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
Expand Down
Loading

0 comments on commit c3d435e

Please sign in to comment.