1package org.hamcrest.core; 2 3import org.hamcrest.Matcher; 4import org.junit.Test; 5 6import static org.hamcrest.AbstractMatcherTest.*; 7import static org.hamcrest.core.DescribedAs.describedAs; 8import static org.hamcrest.core.IsAnything.anything; 9import static org.hamcrest.core.IsEqual.equalTo; 10 11public final class DescribedAsTest { 12 13 @Test public void 14 copesWithNullsAndUnknownTypes() { 15 Matcher<Object> matcher = describedAs("irrelevant", anything()); 16 17 assertNullSafe(matcher); 18 assertUnknownTypeSafe(matcher); 19 } 20 21 @Test public void 22 overridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { 23 Matcher<?> matcher = describedAs("my description", anything()); 24 25 assertDescription("my description", matcher); 26 } 27 28 @Test public void 29 appendsValuesToDescription() { 30 Matcher<?> matcher = describedAs("value 1 = %0, value 2 = %1", anything(), 33, 97); 31 32 assertDescription("value 1 = <33>, value 2 = <97>", matcher); 33 } 34 35 @Test public void 36 celegatesMatchingToAnotherMatcher() { 37 Matcher<String> matcher = describedAs("irrelevant", equalTo("hi")); 38 39 assertMatches(matcher, "hi"); 40 assertDoesNotMatch("matched", matcher, "oi"); 41 } 42 43 @Test public void 44 delegatesMismatchDescriptionToAnotherMatcher() { 45 Matcher<Integer> matcher = describedAs("irrelevant", equalTo(2)); 46 47 assertMismatchDescription("was <1>", matcher, 1); 48 } 49} 50