Skip to content

Commit

Permalink
Fix tests affected by DST change
Browse files Browse the repository at this point in the history
  • Loading branch information
patrox committed Apr 1, 2016
1 parent 49ea3ed commit c02b4bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Expand Up @@ -7,8 +7,9 @@
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.Optional;

public class OffsetDateTimeArgumentTest {
Expand All @@ -18,12 +19,12 @@ public class OffsetDateTimeArgumentTest {

@Test
public void apply() throws Exception {
final ZoneOffset localOffset = ZoneOffset.from(OffsetDateTime.now());
OffsetDateTime dateTime = OffsetDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, localOffset);
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.valueOf("2007-12-03 10:15:30.375"));
Mockito.verify(statement).setTimestamp(1, Timestamp.from(now));
}

@Test
Expand Down
Expand Up @@ -5,8 +5,9 @@

import java.sql.ResultSet;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
Expand All @@ -17,12 +18,13 @@ public class OffsetDateTimeMapperTest {

@Test
public void mapColumnByName() throws Exception {
when(resultSet.getTimestamp("name")).thenReturn(Timestamp.valueOf("2007-12-03 10:15:30.375"));
final Instant now = OffsetDateTime.now().toInstant();

when(resultSet.getTimestamp("name")).thenReturn(Timestamp.from(now));

OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, "name", null);

final ZoneOffset localOffset = ZoneOffset.from(OffsetDateTime.now());
assertThat(actual).isEqualTo(OffsetDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, localOffset));
assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}

@Test
Expand All @@ -36,12 +38,13 @@ public void mapColumnByName_TimestampIsNull() throws Exception {

@Test
public void mapColumnByIndex() throws Exception {
when(resultSet.getTimestamp(1)).thenReturn(Timestamp.valueOf("2007-12-03 10:15:30.375"));
final Instant now = OffsetDateTime.now().toInstant();

when(resultSet.getTimestamp(1)).thenReturn(Timestamp.from(now));

OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, 1, null);

final ZoneOffset localOffset = ZoneOffset.from(OffsetDateTime.now());
assertThat(actual).isEqualTo(OffsetDateTime.of(2007, 12, 3, 10, 15, 30, 375_000_000, localOffset));
assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}

@Test
Expand Down

0 comments on commit c02b4bd

Please sign in to comment.