final class HasMessage extends TypeSafeMatcher<Throwable>
Throwable a message, which matches something.
Example:
public class MyTest {
private final SomeClass sut = new SomeClass();
@Test
public void throwsFooException() {
final Throwable result = sut.makeError("foobar");
assertThat(result, hasMessage(is("foobar")));
}
}
| Modifier and Type | Field and Description |
|---|---|
private Matcher<? super String> |
messageTextMatcher
String matcher for expected message.
|
| Modifier | Constructor and Description |
|---|---|
private |
HasMessage(Matcher<? super String> messageTextMatcher)
Dedicated constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
describeTo(Description description) |
static Matcher<Throwable> |
hasMessage(Matcher<? super String> messageTextMatcher)
Creates a matcher of
Throwables that matches when its message matched be messageTextMatcher. |
protected boolean |
matchesSafely(Throwable item) |
describeMismatch, describeMismatchSafely, matches_dont_implement_Matcher___instead_extend_BaseMatcher_, toStringprivate HasMessage(Matcher<? super String> messageTextMatcher)
Use hasMessage(org.hamcrest.Matcher) to create new instances.
messageTextMatcher - must not be nullpublic void describeTo(Description description)
protected boolean matchesSafely(Throwable item)
matchesSafely in class TypeSafeMatcher<Throwable>public static Matcher<Throwable> hasMessage(Matcher<? super String> messageTextMatcher)
Throwables that matches when its message matched be messageTextMatcher.
For example:
assertThat(exception, hasMessage(equalTo("Parameter is required.")))
messageTextMatcher - matcher for actual message., not null.nullCopyright © 2014 Sven Strittmatter. All Rights Reserved.