Browse Source

DATAJDBC-303 - Made test stable against rounding errors.

pull/106/head
Jens Schauder 7 years ago
parent
commit
dc9b594dd0
  1. 12
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java

12
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java

@ -210,9 +210,11 @@ public class QueryAnnotationHsqlIntegrationTests { @@ -210,9 +210,11 @@ public class QueryAnnotationHsqlIntegrationTests {
@Test // DATAJDBC-175
public void executeCustomQueryWithReturnTypeIsLocalDateTimeList() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime preciseNow = LocalDateTime.now();
LocalDateTime truncatedNow = truncateSubmillis(preciseNow);
repository.nowWithLocalDateTimeList() //
.forEach(d -> assertThat(d).isAfterOrEqualTo(now));
.forEach(d -> assertThat(d).isAfterOrEqualTo(truncatedNow));
}
@ -259,6 +261,12 @@ public class QueryAnnotationHsqlIntegrationTests { @@ -259,6 +261,12 @@ public class QueryAnnotationHsqlIntegrationTests {
assertThat(repository.immutableTuple()).isEqualTo(new DummyEntityRepository.ImmutableTuple("one", "two", 3));
}
private static LocalDateTime truncateSubmillis(LocalDateTime now) {
int NANOS_IN_MILLIS = 1_000_000;
return now.withNano((now.getNano() / NANOS_IN_MILLIS) * 1_000_000);
}
private DummyEntity dummyEntity(String name) {
DummyEntity entity = new DummyEntity();

Loading…
Cancel
Save