use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseLocalDate.
@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDate(String timeZone) {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDate input = RandomValues.randomLocalDate();
Date expected = Date.valueOf(input);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.LOCAL_DATE.toDatabase(db, input);
assertThat(result, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseLocalDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDateTime(String jvmTimeZone) {
try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
LocalDateTime input = RandomValues.randomLocalDateTime();
Timestamp expected = Timestamp.valueOf(input);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.LOCAL_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 convertToEntityAttribute.
@ParameterizedTest
@MethodSource("parameters")
void convertToEntityAttribute(String timeZone, LocalDate expected, Date input) {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDateConverter sut = new LocalDateConverter();
LocalDate actual = sut.convertToEntityAttribute(input);
assertThat(actual, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class ZonedDateTimeConverterTest method convertToEntityAttribute.
@ParameterizedTest
@MethodSource("parameters")
void convertToEntityAttribute(String timeZone, LocalDate local) {
Timestamp input = timestamp(timeZone, local);
ZonedDateTime expected = zonedDateTime(timeZone, local);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
ZonedDateTimeConverter sut = new ZonedDateTimeConverter(ZoneId.of(timeZone));
ZonedDateTime actual = sut.convertToEntityAttribute(input);
assertThat(actual, is(expected));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class ZonedDateTimeConverterTest method convertToEntityAttributePreGregorianShouldThrow.
@ParameterizedTest
@MethodSource("timezones")
void convertToEntityAttributePreGregorianShouldThrow(String timeZone) {
ZonedDateTime dateTime = ZonedDateTime.of(LocalDateUtil.START_OF_GREGORIAN_CALENDAR, LocalTime.MIN, ZoneId.of(timeZone)).minusNanos(1);
Timestamp input = Timestamp.from(dateTime.toInstant());
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
ZonedDateTimeConverter sut = new ZonedDateTimeConverter(ZoneId.of(timeZone));
calling(() -> sut.convertToEntityAttribute(input)).shouldThrow(IllegalArgumentException.class);
}
}
Aggregations