我需要在某个测试用例的日期之前/之后进行测试。如果可能的话,我想使用Hamcrest matchers。
Hamcrest (Java)是否有用于处理日期的匹配器?如果是这样,我将在哪个包/类中找到特定的日期匹配器函数?
发布于 2011-12-24 05:23:55
OrderingComparison::greaterThan匹配器可以在任何可以与其自身相媲美的类型上工作(它在org.hamcrest.number包中,但实际上不是特定于数字的)。Date就是这样一种类型。
发布于 2013-08-09 01:06:33
有一个由https://github.com/eXparity/hamcrest-date的库提供的hamcrest日期匹配器库,该库也可用于maven、ivy等,网址为
<dependency>
<groupId>org.exparity</groupId>
<artifactId>hamcrest-date</artifactId>
<version>1.1.0</version>
</dependency>它支持日期的各种匹配器,因此允许构造
Date myBirthday = new Date();
MatcherAssert.assertThat(myBirthday, DateMatchers.after(Moments.today()));或
Date myBirthday = new Date();
MatcherAssert.assertThat(myBirthday, DateMatchers.isToday());发布于 2013-02-01 18:42:34
你可以看看新的Date Matcher,它将被添加到hamcrest中(我不知道什么时候想的):
Date matchers discussion/code changes on github
在快速查看之后,似乎会有一个新的包org.hamcrest.date,其中包含:
https://stackoverflow.com/questions/8620181
复制相似问题