您应该尝试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]
}
日期的完整示例在这里,其他的都在那里。