io.github.olib963.javatest.matchers.internal.MessageMatcher 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 MessageMatcher implements Matcher {
private final Matcher messageMatcher;
public MessageMatcher(Matcher messageMatcher) {
this.messageMatcher = messageMatcher;
}
@Override
public MatchResult matches(Throwable value) {
var message = value.getMessage();
return messageMatcher.matches(message)
.mapMismatch(mismatch -> "message {" + message + "} " + mismatch);
}
@Override
public String describeExpected() {
return "have a message that was expected to " + messageMatcher.describeExpected();
}
}