Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to verify TemporalAccessor serialization. #638

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.micronaut.cache.serialize

import io.micronaut.core.convert.DefaultMutableConversionService
import spock.lang.Issue
import spock.lang.PendingFeature
import spock.lang.Specification

import java.nio.charset.Charset
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.OffsetTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime

class DefaultStringKeySerializerSpec extends Specification {

@PendingFeature(reason = "Depends on https://github.com/micronaut-projects/micronaut-core/pull/8963")
@Issue("https://github.com/micronaut-projects/micronaut-cache/issues/404")
wetted marked this conversation as resolved.
Show resolved Hide resolved
void "test TemporalAccessor serialization"() {

given:
final serializer = new DefaultStringKeySerializer("cacheName", Charset.defaultCharset(), new DefaultMutableConversionService())

expect:
new String(serializer.serialize(sourceObject).get(), Charset.defaultCharset()) == "cacheName:$result"

where:
sourceObject | result
LocalDate.of(2022, 8, 12) | "2022-08-12"
LocalDateTime.of(2022, 8, 12, 12, 19) | "2022-08-12T12:19:00"
OffsetTime.of(12, 19, 0, 0, ZoneOffset.ofHours(5)) | "12:19:00+05:00"
OffsetDateTime.of(2022, 8, 12, 12, 19, 0, 0, ZoneOffset.ofHours(5)) | "2022-08-12T12:19:00+05:00"
ZonedDateTime.of(2022, 8, 12, 12, 19, 0, 0, ZoneOffset.ofHours(5)) | "2022-08-12T12:19:00+05:00"
ZonedDateTime.of(2022, 8, 12, 12, 19, 0, 0, ZoneId.of("Europe/Berlin")) | "2022-08-12T12:19:00+02:00[Europe/Berlin]"
LocalDateTime.of(2022, 8, 12, 12, 19).toInstant(ZoneOffset.UTC) | "2022-08-12T12:19:00Z"
}
}