/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.<T>describedAs(description, matcher, values); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
@Override public void describeTo(@Nonnull final Description description) { matcher.describeTo(description); description.appendText(" ("); super.describeTo(description); description.appendText(")"); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.<T>describedAs(description, matcher, values); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.<T>describedAs(description, matcher, values); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenized description */ public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) { return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
/** * Creates a matcher for arrays that matches when the <code>length</code> of the array * is zero. * <p/> * For example: * <pre>assertThat(new String[0], emptyArray())</pre> * */ @Factory public static <E> Matcher<E[]> emptyArray() { Matcher<E[]> isEmpty = arrayWithSize(0); return describedAs("an empty array", isEmpty); } }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
/** * Creates a matcher for arrays that matches when the <code>length</code> of the array * is zero. * For example: * <pre>assertThat(new String[0], emptyArray())</pre> * */ public static <E> Matcher<E[]> emptyArray() { return describedAs("an empty array", IsArrayWithSize.<E>arrayWithSize(0)); } }
/** * Wraps an existing matcher and overrides the description when it fails. */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
@Test public void delegatesMismatchDescriptionToAnotherMatcher() { Matcher<Integer> matcher = describedAs("irrelevant", equalTo(2)); assertMismatchDescription("was <1>", matcher, 1); } }
/** * Wraps an existing matcher and overrides the description when it fails. */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
@Test public void celegatesMatchingToAnotherMatcher() { Matcher<String> matcher = describedAs("irrelevant", equalTo("hi")); assertMatches(matcher, "hi"); assertDoesNotMatch("matched", matcher, "oi"); }
/** * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * <p/> * For example: * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre> * * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description */ @Factory public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) { return new DescribedAs<T>(description, matcher, values); } }
@Test public void overridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { Matcher<?> matcher = describedAs("my description", anything()); assertDescription("my description", matcher); }