Hamcrest library for date

I look around, but I did not find anything useful. Are there any third-party libraries that work with hamcrest that have extensive date matching?

In particular, I'm looking for line helpers:

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 there before I downloaded mine.

+5
source share
2 answers

I wrote a set of date matches that look like you. Source here https://github.com/eXparity/hamcrest-date . Embedded Connector Example

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

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

<dependency>
    <groupId>org.exparity</groupId>
    <artifactId>hamcrest-date</artifactId>
    <version>2.0.1</version>
</dependency>
+3
source

fest-assert, hamcrest, IMHO ( " " ). , :

@Test
public void is_between_date_assertions_examples() {

    // various usage of isBetween assertion,
    // Note that isBetween(2002-12-17, 2002-12-19) includes start date but end date :
    assertThat(theTwoTowers.getReleaseDate())
            // = 2002-12-18
            .isBetween(theFellowshipOfTheRing.getReleaseDate(), theReturnOfTheKing.getReleaseDate())
            .isBetween(parse("2002-12-17"), parse("2002-12-19")) // [2002-12-17, 2002-12-19[
            .isBetween("2002-12-17", "2002-12-19") // [2002-12-17, 2002-12-19[
            .isNotBetween("2002-12-17", "2002-12-18") // [2002-12-17, 2002-12-18[
            .isBetween("2002-12-17", "2002-12-18", true, true); // [2002-12-17, 2002-12-18]
}

, .

0

All Articles