你應該嘗試fest-assert,它不符合hamcrest,但恕我直言,它是優於它(「更流利」)。 例如用日期:
@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]
}
完整的例子與日期是here,其他都there。
也許你應該看看尤達時間增加了,與此庫它應該很容易實現這些匹配器 – 2012-08-13 22:57:29
是[Joda時間](http://joda-time.sourceforge.net/)的絕地叉? – 2012-08-14 20:48:26