use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseZonedDateTime.
@ParameterizedTest
@MethodSource("timeZonePairs")
void toDatabaseZonedDateTime(String dbTimeZone, String jvmTimeZone) {
ZoneId dbZone = ZoneId.of(dbTimeZone);
ZoneId jvmZone = ZoneId.of(jvmTimeZone);
ZonedDateTime input = RandomValues.randomZonedDateTime(jvmZone);
try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
ZonedDateTime dbTime = input.withZoneSameInstant(dbZone);
Timestamp expected = Timestamp.valueOf(dbTime.toLocalDateTime());
when(db.databaseTimeZone()).thenReturn(dbZone);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.ZONED_DATE_TIME.toDatabase(db, input);
assertThat(result, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class LocalDateConverterTest method convertToDatabaseColumn.
@ParameterizedTest
@MethodSource("parameters")
void convertToDatabaseColumn(String timeZone, LocalDate input, Date expected) {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDateConverter sut = new LocalDateConverter();
Date actual = sut.convertToDatabaseColumn(input);
assertThat(actual, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class ZonedDateTimeConverterTest method convertToDatabaseColumn.
@ParameterizedTest
@MethodSource("parameters")
void convertToDatabaseColumn(String timeZone, LocalDate local) {
ZonedDateTime input = zonedDateTime(timeZone, local);
Timestamp expected = timestamp(timeZone, local);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
ZonedDateTimeConverter sut = new ZonedDateTimeConverter(ZoneId.of(timeZone));
Timestamp actual = sut.convertToDatabaseColumn(input);
assertThat(actual, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class ZonedDateTimeConverterTest method convertToDatabaseColumnPreGregorianShouldThrow.
@ParameterizedTest
@MethodSource("timezones")
void convertToDatabaseColumnPreGregorianShouldThrow(String timeZone) {
ZonedDateTime input = ZonedDateTime.of(LocalDateUtil.START_OF_GREGORIAN_CALENDAR, LocalTime.MIN, ZoneId.of(timeZone)).minusNanos(1);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
ZonedDateTimeConverter sut = new ZonedDateTimeConverter(ZoneId.of(timeZone));
calling(() -> sut.convertToDatabaseColumn(input)).shouldThrow(IllegalArgumentException.class);
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DatabaseIntegrationTest method canRoundTripLocalTimes.
@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalTimes(String timeZone) {
Database database = testDatabase(dataSource, dialect);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalTime expected = randomLocalTime();
TestRow input = TestRow.of(expected);
database.insert(input);
LocalTime result = database.from(TestRow.class).select(TestRow::localTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
assertThat(result, is(expected));
}
}
Aggregations