我一直在四处寻找,但没有发现任何有用的东西。是否有任何第 3 方库可与具有广泛日期匹配的 hamcrest 一起使用?
具体来说,我正在按照以下方式寻找匹配器:
assertThat(myDate, is(withinMinutes(sourceDate, 10)));
assertThat(myDate, is(afterDate(sourceDate)));
assertThat(myDate, is(betweenDates(startDate, endDate)));
我想在自己滚动之前看看外面是否有任何东西。
最佳答案
我写了一组日期匹配器,看起来像您想要的。来源在这里https://github.com/eXparity/hamcrest-date .如何使用内部匹配器的示例
assertThat(dateUnderTest, DateMatchers.within(2, TimeUnit.SECONDS, new Date()));
你可以用 maven 添加它到你的 pom.xml
<dependency>
<groupId>org.exparity</groupId>
<artifactId>hamcrest-date</artifactId>
<version>2.0.1</version>
</dependency>
关于java - 日期的 Hamcrest 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11941810/