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

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

Go to download

JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck.

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 ThrowableCauseMatcher extends
        TypeSafeMatcher {

    private final Matcher matcher;

    public ThrowableCauseMatcher(Matcher matcher) {
        this.matcher = matcher;
    }

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

    @Override
    protected boolean matchesSafely(T item) {
        return matcher.matches(item.getCause());
    }

    @Override
    protected void describeMismatchSafely(T item, Description description) {
        description.appendText("cause ");
        matcher.describeMismatch(item.getCause(), description);
    }

    @Factory
    public static  Matcher hasCause(final Matcher matcher) {
        return new ThrowableCauseMatcher(matcher);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy