Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hamcrest library for date

I have been looking around but I have not found anything useful. Are there any 3rd party libraries that work with hamcrest that have extensive date matching?

Specifically I am looking for matchers along the lines of:

assertThat(myDate, is(withinMinutes(sourceDate, 10)));
assertThat(myDate, is(afterDate(sourceDate)));
assertThat(myDate, is(betweenDates(startDate, endDate)));

I wanted to see if there was anything out there before I rolled my own.

like image 697
Dan Avatar asked Oct 23 '22 13:10

Dan


1 Answers

I've written a set of date matchers which look like what you're after. The source is here https://github.com/eXparity/hamcrest-date. An example of how to use the within matcher

assertThat(dateUnderTest, DateMatchers.within(2, TimeUnit.SECONDS, new Date()));

You can add it with maven adding this to your pom.xml

<dependency>
    <groupId>org.exparity</groupId>
    <artifactId>hamcrest-date</artifactId>
    <version>2.0.1</version>
</dependency>
like image 151
stewbis Avatar answered Oct 27 '22 10:10

stewbis