io.github.olib963.javatest.matchers.internal.CauseMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javatest-matchers Show documentation
Show all versions of javatest-matchers Show documentation
Matchers to create assertions from common conditions
package io.github.olib963.javatest.matchers.internal;
import io.github.olib963.javatest.matchers.MatchResult;
import io.github.olib963.javatest.matchers.Matcher;
public class CauseMatcher implements Matcher {
private final Matcher causeMatcher;
public CauseMatcher(Matcher causeMatcher) {
this.causeMatcher = causeMatcher;
}
@Override
public MatchResult matches(Throwable value) {
var cause = value.getCause();
return causeMatcher.matches(cause)
.mapMismatch(mismatch -> "cause {" + cause + "} " + mismatch);
}
@Override
public String describeExpected() {
return "have a cause that was expected to " + causeMatcher.describeExpected();
}
}