use of java.time.ZonedDateTime in project dropwizard by dropwizard.
the class InstantArgumentTest method applyCalendar.
@Test
public void applyCalendar() throws Exception {
final ZoneId systemDefault = ZoneId.systemDefault();
// this test only asserts that a calendar was passed in. Not that the JDBC driver
// will do the right thing and adjust the time.
final ZonedDateTime zonedDateTime = ZonedDateTime.parse("2012-12-21T00:00:00.000Z");
final ZonedDateTime expected = zonedDateTime.withZoneSameInstant(systemDefault);
final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(systemDefault));
new InstantArgument(zonedDateTime.toInstant(), Optional.of(calendar)).apply(1, statement, context);
Mockito.verify(statement).setTimestamp(1, Timestamp.from(expected.toInstant()), calendar);
}
use of java.time.ZonedDateTime in project dropwizard by dropwizard.
the class InstantMapperTest method mapColumnByName.
@Test
public void mapColumnByName() throws Exception {
ZonedDateTime expected = ZonedDateTime.parse("2012-12-21T00:00:00.000Z");
ZonedDateTime stored = expected.withZoneSameInstant(ZoneId.systemDefault());
when(resultSet.getTimestamp("instant")).thenReturn(Timestamp.from(stored.toInstant()));
Instant actual = new InstantMapper().mapColumn(resultSet, "instant", null);
assertThat(actual).isEqualTo(expected.toInstant());
}
use of java.time.ZonedDateTime in project dropwizard by dropwizard.
the class ZonedDateTimeArgumentTest method apply.
@Test
public void apply() throws Exception {
ZonedDateTime dateTime = ZonedDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, ZoneId.systemDefault());
new ZonedDateTimeArgument(dateTime, Optional.empty()).apply(1, statement, context);
Mockito.verify(statement).setTimestamp(1, Timestamp.valueOf("2007-12-03 10:15:30.375"));
}
use of java.time.ZonedDateTime in project dropwizard by dropwizard.
the class ZonedDateTimeMapperTest method mapColumnByIndex.
@Test
public void mapColumnByIndex() throws Exception {
when(resultSet.getTimestamp(1)).thenReturn(Timestamp.valueOf("2007-12-03 10:15:30.375"));
ZonedDateTime actual = new ZonedDateTimeMapper().mapColumn(resultSet, 1, null);
assertThat(actual).isEqualTo(ZonedDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, ZoneId.systemDefault()));
}
use of java.time.ZonedDateTime in project dropwizard by dropwizard.
the class ZonedDateTimeMapperTest method mapColumnByName.
@Test
public void mapColumnByName() throws Exception {
when(resultSet.getTimestamp("name")).thenReturn(Timestamp.valueOf("2007-12-03 10:15:30.375"));
ZonedDateTime actual = new ZonedDateTimeMapper().mapColumn(resultSet, "name", null);
assertThat(actual).isEqualTo(ZonedDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, ZoneId.systemDefault()));
}
Aggregations