io.github.olib963.javatest.matchers.MatchResult 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 java.util.Optional;
import java.util.function.Function;
public final class MatchResult {
public final boolean matches;
public final Optional mismatch;
private MatchResult(boolean matches, Optional mismatch) {
this.matches = matches;
this.mismatch = mismatch;
}
public static MatchResult of(boolean matches) {
return of(matches, Optional.empty());
}
public static MatchResult of(boolean matches, Optional mismatch) {
return new MatchResult(matches, mismatch);
}
public static MatchResult match() {
return new MatchResult(true, Optional.empty());
}
public static MatchResult mismatch(){
return new MatchResult(false, Optional.empty());
}
public static MatchResult mismatch(String mismatch){
return new MatchResult(false, Optional.of(mismatch));
}
public MatchResult mapMismatch(Function mismatchFunction) {
return new MatchResult(matches, mismatch.map(mismatchFunction));
}
}