-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix formatting of LocalDateTimeSerializer encoding and add tests (#287)
- Loading branch information
1 parent
7ff0af3
commit 06e9264
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...n-model/src/test/kotlin/org/jellyfin/sdk/model/serializer/LocalDateTimeSerializerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jellyfin.sdk.model.serializer | ||
|
||
import kotlinx.serialization.json.Json | ||
import java.time.LocalDateTime | ||
import java.time.ZoneId | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
public class LocalDateTimeSerializerTests { | ||
@Test | ||
public fun `Encodes dates and times (UTC)`() { | ||
val instance = LocalDateTimeSerializer(ZoneId.of("UTC")) | ||
|
||
assertEquals( | ||
""""2021-06-30T01:33:07Z"""", | ||
Json.encodeToString(instance, LocalDateTime.of(2021, 6, 30, 1, 33, 7)) | ||
) | ||
} | ||
|
||
@Test | ||
public fun `Encodes dates and times (Offset)`() { | ||
val instance = LocalDateTimeSerializer(ZoneId.of("UTC+01:00")) | ||
|
||
assertEquals( | ||
""""2021-06-30T01:33:07+01:00"""", | ||
Json.encodeToString(instance, LocalDateTime.of(2021, 6, 30, 1, 33, 7)) | ||
) | ||
} | ||
|
||
@Test | ||
public fun `Parses minimum value`() { | ||
val instance = LocalDateTimeSerializer(ZoneId.of("UTC")) | ||
|
||
assertEquals(LocalDateTime.MIN, Json.decodeFromString(instance, """"0001-01-01T00:00:00"""")) | ||
} | ||
|
||
@Test | ||
public fun `Parses dates and times (UTC)`() { | ||
val instance = LocalDateTimeSerializer(ZoneId.of("UTC")) | ||
|
||
assertEquals( | ||
LocalDateTime.of(2021, 6, 30, 1, 33, 7), | ||
Json.decodeFromString(instance, """"2021-06-30T01:33:07Z"""") | ||
) | ||
assertEquals( | ||
LocalDateTime.of(2021, 6, 30, 1, 33, 7, 420000000), | ||
Json.decodeFromString(instance, """"2021-06-30T01:33:07.420Z"""") | ||
) | ||
} | ||
|
||
@Test | ||
public fun `Parses dates and times (Offset)`() { | ||
val instance = LocalDateTimeSerializer(ZoneId.of("UTC+01:00")) | ||
|
||
assertEquals( | ||
LocalDateTime.of(2021, 6, 30, 1, 33, 7), | ||
Json.decodeFromString(instance, """"2021-06-30T01:33:07+01:00"""") | ||
) | ||
assertEquals( | ||
LocalDateTime.of(2021, 6, 30, 1, 33, 7, 420000000), | ||
Json.decodeFromString(instance, """"2021-06-30T01:33:07.420+01:00"""") | ||
) | ||
} | ||
} |