All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.internal.matchers.ThrowableMessageMatcher Maven / Gradle / Ivy

Go to download

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.

There is a newer version: 4.13.2
Show newest version
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 fMatcher;

    public ThrowableMessageMatcher(Matcher matcher) {
        fMatcher = matcher;
    }

    public void describeTo(Description description) {
        description.appendText("exception with message ");
        description.appendDescriptionOf(fMatcher);
    }

    @Override
    protected boolean matchesSafely(T item) {
        return fMatcher.matches(item.getMessage());
    }

    @Override
    protected void describeMismatchSafely(T item, Description description) {
        description.appendText("message ");
        fMatcher.describeMismatch(item.getMessage(), description);
    }

    @Factory
    public static  Matcher hasMessage(final Matcher matcher) {
        return new ThrowableMessageMatcher(matcher);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy