io.github.olib963.javatest.matchers.Matcher 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;
import io.github.olib963.javatest.Assertion;
import io.github.olib963.javatest.matchers.internal.MatcherAssertion;
import io.github.olib963.javatest.matchers.internal.PredicateMatcher;
import java.util.function.Function;
import java.util.function.Predicate;
public interface Matcher {
MatchResult matches(A value);
String describeExpected();
static Matcher fromFunctions(Predicate predicate, String expected) {
return PredicateMatcher.of(predicate, expected);
}
static Matcher fromFunctions(Predicate predicate, String expected, Function mismatchDescriptionFunction) {
return PredicateMatcher.of(predicate, expected, mismatchDescriptionFunction);
}
static Assertion that(A value, Matcher matcher) {
return new MatcherAssertion<>(value, matcher);
}
static Matcher isEqualTo(A expected) {
return PredicateMatcher.isEqualTo(expected);
}
static Matcher hasType(Class expectedClass) {
return PredicateMatcher.hasType(expectedClass);
}
static Matcher isTheSameInstanceAs(A instance) {
return PredicateMatcher.isTheSameInstanceAs(instance);
}
}