DATAJDBC-303 - Made test stable against rounding errors.

This commit is contained in:
Jens Schauder
2018-12-17 13:45:50 +01:00
parent b7da4f412f
commit dc9b594dd0

View File

@@ -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 {
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();