There is also the Cirneco extension. It has several Date
specific matchers (e.g. monday()
) and others that apply to dates because of the implementation of Comparable
(see for instance between()
, betweenInclusive()
). The plan is to support also Joda Time in the JDK7 version of the library and the new date-based classes in the JDK8 version (mainly LocalDate
).
You can do assertions like:
final Date date = new Date();
assertThat(date, is(monday())); // JUnit style
given(date).assertIs(monday()); // Cirneco style
You can use the following dependency for a JDK7-compliant project:
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>java7-hamcrest-matchers</artifactId>
<version>0.7.0</version>
</dependency>
or the following if you are using JDK8
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>java8-hamcrest-matchers</artifactId>
<version>0.7.0</version>
</dependency>