org.junit.internal.matchers.ThrowableMessageMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-curves4 Show documentation
Show all versions of virtdata-lib-curves4 Show documentation
Statistical sampling library for use in virtualdataset libraries, based on apache commons math 4
package org.junit.internal.matchers;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
public class ThrowableMessageMatcher extends
TypeSafeMatcher {
private final Matcher matcher;
public ThrowableMessageMatcher(Matcher matcher) {
this.matcher = matcher;
}
public void describeTo(Description description) {
description.appendText("exception with message ");
description.appendDescriptionOf(matcher);
}
@Override
protected boolean matchesSafely(T item) {
return matcher.matches(item.getMessage());
}
@Override
protected void describeMismatchSafely(T item, Description description) {
description.appendText("message ");
matcher.describeMismatch(item.getMessage(), description);
}
@Factory
public static Matcher hasMessage(final Matcher matcher) {
return new ThrowableMessageMatcher(matcher);
}
}