IsBetween extends TypeSafeMatcher<T> { @Override protected void describeMismatchSafely(final T item, final Description mismatchDescription) { mismatchDescription.appendValue(item).appendText(" is not between ").appendValue(from).appendText(" and ") .appendValue(to).appendText(", both excluded"); } IsBetween(final T from, final T to); static Matcher<T> between(final T from, final T to); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { assertHasMismatchDescription("<9> is not between <10> and <12>, both excluded", isBetweenMatcher, 9); assertHasMismatchDescription("<10> is not between <10> and <12>, both excluded", isBetweenMatcher, 10); assertHasMismatchDescription("<12> is not between <10> and <12>, both excluded", isBetweenMatcher, 12); assertHasMismatchDescription("<13> is not between <10> and <12>, both excluded", isBetweenMatcher, 13); }