use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.
the class DataTypeTest method getZonedDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void getZonedDateTime(String timeZone) throws SQLException {
ZonedDateTime expected = ZonedDateTime.of(randomLocalDateTime(), ZoneId.of("UTC"));
Timestamp returnVal = Timestamp.from(expected.toInstant());
when(rs.getTimestamp(eq("someColumn"), any())).thenReturn(returnVal);
when(db.databaseTimeZone()).thenReturn(ZoneId.of(timeZone));
when(db.dialect()).thenReturn(new AnsiDialect());
Optional<ZonedDateTime> result = DataType.ZONED_DATE_TIME.get(rs, "someColumn", db);
assertThat(result, is(Optional.of(expected)));
}
use of org.junit.jupiter.params.ParameterizedTest 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 org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.
the class TypeUtilTest method primitiveComponentType.
@ParameterizedTest
@MethodSource("parametersForPrimitiveComponentType")
void primitiveComponentType(Class<?> array, Class<?> expected) {
Type result = TypeUtil.primitiveComponentType(array);
assertThat(result, equalTo(expected));
}
use of org.junit.jupiter.params.ParameterizedTest 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 org.junit.jupiter.params.ParameterizedTest 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));
}
}
Aggregations