Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing Test Case Granularity for testGetLocalDateTimeTypes #2360

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ public void testNullValuesWithGetObject() throws Exception {
}

@Test
public void testGetLocalDateTimeTypes() throws Exception {
public void testGetLocalDateTimeTypesWithDefaultOffsetDateTimeConversion() throws Exception {
// test value needs to be in a time zone other than local
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS); // Linux has more precision than SQL Server
int offsetSeconds = value.getOffset().getTotalSeconds();
Expand All @@ -1885,7 +1885,6 @@ public void testGetLocalDateTimeTypes() throws Exception {
try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {
try (PreparedStatement stmt = conn.prepareStatement("SELECT ?")) {
stmt.setObject(1, value);

ResultSet rs = stmt.executeQuery();
rs.next();

Expand All @@ -1895,13 +1894,23 @@ public void testGetLocalDateTimeTypes() throws Exception {
assertEquals(valueWithOffsetConversion.toLocalDate(), rs.getObject(1, LocalDate.class));
assertEquals(valueWithOffsetConversion.toLocalTime(), rs.getObject(1, LocalTime.class));
}
}
}

@Test
public void testGetLocalDateTimeTypesWithIgnoreOffsetDateTimeConversion() throws Exception {
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS); // Linux has more precision than SQL Server
int offsetSeconds = value.getOffset().getTotalSeconds();
offsetSeconds += offsetSeconds < 0 ? 3600 : -3600;
value = value.withOffsetSameLocal(ZoneOffset.ofTotalSeconds(offsetSeconds));

try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {

// change the behavior to be compatible with java.time conversion methods
conn.setIgnoreOffsetOnDateTimeOffsetConversion(true);

try (PreparedStatement stmt = conn.prepareStatement("SELECT ?")) {
stmt.setObject(1, value);

ResultSet rs = stmt.executeQuery();
rs.next();

Expand Down