Search in sources :

Example 1 with Instant

use of java.time.Instant in project dropwizard by dropwizard.

the class InstantMapperTest method mapColumnByName_TimestampIsNull.

@Test
public void mapColumnByName_TimestampIsNull() throws Exception {
    when(resultSet.getTimestamp("instant")).thenReturn(null);
    Instant actual = new InstantMapper().mapColumn(resultSet, "instant", null);
    assertThat(actual).isNull();
}
Also used : Instant(java.time.Instant) Test(org.junit.Test)

Example 2 with Instant

use of java.time.Instant 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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Test(org.junit.Test)

Example 3 with Instant

use of java.time.Instant in project dropwizard by dropwizard.

the class InstantMapperTest method mapColumnByIndex_TimestampIsNull.

@Test
public void mapColumnByIndex_TimestampIsNull() throws Exception {
    when(resultSet.getTimestamp(1)).thenReturn(null);
    Instant actual = new InstantMapper().mapColumn(resultSet, 1, null);
    assertThat(actual).isNull();
}
Also used : Instant(java.time.Instant) Test(org.junit.Test)

Example 4 with Instant

use of java.time.Instant in project dropwizard by dropwizard.

the class OffsetDateTimeArgumentTest method apply.

@Test
public void apply() throws Exception {
    final Instant now = OffsetDateTime.now().toInstant();
    final OffsetDateTime dateTime = OffsetDateTime.ofInstant(now, ZoneId.systemDefault());
    new OffsetDateTimeArgument(dateTime, Optional.empty()).apply(1, statement, context);
    Mockito.verify(statement).setTimestamp(1, Timestamp.from(now));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant) Test(org.junit.Test)

Example 5 with Instant

use of java.time.Instant in project dropwizard by dropwizard.

the class OffsetDateTimeMapperTest method mapColumnByIndex.

@Test
public void mapColumnByIndex() throws Exception {
    final Instant now = OffsetDateTime.now().toInstant();
    when(resultSet.getTimestamp(1)).thenReturn(Timestamp.from(now));
    OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, 1, null);
    assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant) Test(org.junit.Test)

Aggregations

Instant (java.time.Instant)321 Test (org.testng.annotations.Test)136 Test (org.junit.Test)65 ZonedDateTime (java.time.ZonedDateTime)36 Clock (java.time.Clock)26 OffsetDateTime (java.time.OffsetDateTime)23 LocalDateTime (java.time.LocalDateTime)18 Duration (java.time.Duration)17 LocalDate (java.time.LocalDate)15 IOException (java.io.IOException)11 LocalTime (java.time.LocalTime)11 DateTimeFormatter (java.time.format.DateTimeFormatter)11 Date (java.util.Date)11 Timestamp (java.sql.Timestamp)10 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)8 ZoneRules (java.time.zone.ZoneRules)8 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)8 JsonArray (io.vertx.core.json.JsonArray)7 JsonObject (io.vertx.core.json.JsonObject)7 OffsetTime (java.time.OffsetTime)7