@@ -3,12 +3,14 @@ package com.withorb.api.core
33import com.fasterxml.jackson.annotation.JsonProperty
44import com.fasterxml.jackson.databind.exc.MismatchedInputException
55import com.fasterxml.jackson.module.kotlin.readValue
6+ import java.time.LocalDate
7+ import java.time.LocalTime
68import java.time.OffsetDateTime
9+ import java.time.ZoneOffset
710import kotlin.reflect.KClass
811import org.assertj.core.api.Assertions.assertThat
912import org.assertj.core.api.Assertions.catchThrowable
1013import org.junit.jupiter.api.Test
11- import org.junit.jupiter.api.assertDoesNotThrow
1214import org.junit.jupiter.params.ParameterizedTest
1315import org.junit.jupiter.params.provider.EnumSource
1416import org.junitpioneer.jupiter.cartesian.CartesianTest
@@ -72,11 +74,34 @@ internal class ObjectMappersTest {
7274 }
7375 }
7476
75- enum class LenientOffsetDateTimeTestCase (val string : String ) {
76- DATE (" 1998-04-21" ),
77- DATE_TIME (" 1998-04-21T04:00:00" ),
78- ZONED_DATE_TIME_1 (" 1998-04-21T04:00:00+03:00" ),
79- ZONED_DATE_TIME_2 (" 1998-04-21T04:00:00Z" ),
77+ enum class LenientOffsetDateTimeTestCase (
78+ val string : String ,
79+ val expectedOffsetDateTime : OffsetDateTime ,
80+ ) {
81+ DATE (
82+ " 1998-04-21" ,
83+ expectedOffsetDateTime =
84+ OffsetDateTime .of(LocalDate .of(1998 , 4 , 21 ), LocalTime .of(0 , 0 ), ZoneOffset .UTC ),
85+ ),
86+ DATE_TIME (
87+ " 1998-04-21T04:00:00" ,
88+ expectedOffsetDateTime =
89+ OffsetDateTime .of(LocalDate .of(1998 , 4 , 21 ), LocalTime .of(4 , 0 ), ZoneOffset .UTC ),
90+ ),
91+ ZONED_DATE_TIME_1 (
92+ " 1998-04-21T04:00:00+03:00" ,
93+ expectedOffsetDateTime =
94+ OffsetDateTime .of(
95+ LocalDate .of(1998 , 4 , 21 ),
96+ LocalTime .of(4 , 0 ),
97+ ZoneOffset .ofHours(3 ),
98+ ),
99+ ),
100+ ZONED_DATE_TIME_2 (
101+ " 1998-04-21T04:00:00Z" ,
102+ expectedOffsetDateTime =
103+ OffsetDateTime .of(LocalDate .of(1998 , 4 , 21 ), LocalTime .of(4 , 0 ), ZoneOffset .UTC ),
104+ ),
80105 }
81106
82107 @ParameterizedTest
@@ -85,6 +110,8 @@ internal class ObjectMappersTest {
85110 val jsonMapper = jsonMapper()
86111 val json = jsonMapper.writeValueAsString(testCase.string)
87112
88- assertDoesNotThrow { jsonMapper().readValue<OffsetDateTime >(json) }
113+ val offsetDateTime = jsonMapper().readValue<OffsetDateTime >(json)
114+
115+ assertThat(offsetDateTime).isEqualTo(testCase.expectedOffsetDateTime)
89116 }
90117}
0 commit comments