Skip to content

Commit dc9b594

Browse files
committed
DATAJDBC-303 - Made test stable against rounding errors.
1 parent b7da4f4 commit dc9b594

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ public void executeCustomQueryWithReturnTypeIsDate() {
210210
@Test // DATAJDBC-175
211211
public void executeCustomQueryWithReturnTypeIsLocalDateTimeList() {
212212

213-
LocalDateTime now = LocalDateTime.now();
213+
LocalDateTime preciseNow = LocalDateTime.now();
214+
LocalDateTime truncatedNow = truncateSubmillis(preciseNow);
215+
214216
repository.nowWithLocalDateTimeList() //
215-
.forEach(d -> assertThat(d).isAfterOrEqualTo(now));
217+
.forEach(d -> assertThat(d).isAfterOrEqualTo(truncatedNow));
216218

217219
}
218220

@@ -259,6 +261,12 @@ public void executeCustomQueryWithImmutableResultType() {
259261
assertThat(repository.immutableTuple()).isEqualTo(new DummyEntityRepository.ImmutableTuple("one", "two", 3));
260262
}
261263

264+
private static LocalDateTime truncateSubmillis(LocalDateTime now) {
265+
266+
int NANOS_IN_MILLIS = 1_000_000;
267+
return now.withNano((now.getNano() / NANOS_IN_MILLIS) * 1_000_000);
268+
}
269+
262270
private DummyEntity dummyEntity(String name) {
263271

264272
DummyEntity entity = new DummyEntity();

0 commit comments

Comments
 (0)