Assertj-core: Add isCloseTo assertions for LocalDate and LocalDateTime

Created on 9 Mar 2017  路  2Comments  路  Source: assertj/assertj-core

Summary

Currently there are no isCloseTo assertions for LocalDate and LocalDateTime like _org.assertj.core.api.AbstractDateAssert.isCloseTo_, but they would obviously be useful.

This could be implemented by giving the delta either in days/milliseconds or by allowing a TimeUnit / Period / Duration parameter.

Example

assertThat( LocalDate.of(1900, 1, 1) ).isCloseTo( LocalDate.of(1900, 1, 2), 1); // delta in days
assertThat( LocalDateTime.of(1900, 1, 1, 0, 0) ).isCloseTo( LocalDateTime.of(1900, 1, 1,0,1), 1000*60); // delta in ms

// or perhaps...

assertThat( LocalDate.of(1900, 1, 1)).isCloseTo( LocalDate.of(1900, 1, 2), 1, TimeUnit.DAYS);
assertThat( LocalDateTime.of(1900, 1, 1, 0, 0)).isCloseTo( LocalDateTime.of(1900, 1, 1,0,1), 1, TimeUnit.MINUTES); 

// or perhaps...

assertThat( LocalDate.of(1900, 1, 1)).isCloseTo( LocalDate.of(1900, 1, 2), Period.ofDays(1) );
assertThat( LocalDateTime.of(1900, 1, 1, 0, 0)).isCloseTo( LocalDateTime.of(1900, 1, 1,0,1), Duration.ofMinutes( 1) );

Java 8 specific ?

  • YES : create Pull Request from the master branch
duplicate

Most helpful comment

It looks like this one is already implemented (#796) and will be part of the next release.

All 2 comments

It looks like this one is already implemented (#796) and will be part of the next release.

Thanks @epeee, you know the project better than me :smile_cat: !
@FlorianSchaetz sorry to have asked you to fill this issue which is already there.

Was this page helpful?
0 / 5 - 0 ratings