io.github.olib963.javatest.matchers.StringMatchers 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.matchers.internal.PredicateMatcher;
public class StringMatchers {
private StringMatchers() {}
public static Matcher startsWith(final String prefix) {
return PredicateMatcher.of(s -> s.startsWith(prefix), "start with {" + prefix + "}");
}
public static Matcher endsWith(final String suffix) {
return PredicateMatcher.of(s -> s.endsWith(suffix), "end with {" + suffix + "}");
}
public static Matcher containsString(final String subString) {
return PredicateMatcher.of(s -> s.contains(subString), "contain {" + subString + "}");
}
public static Matcher isEmptyString() {
return PredicateMatcher.of(String::isEmpty, "be the empty string");
}
public static Matcher isBlankString() {
return PredicateMatcher.of(String::isBlank, "be a blank string");
}
public static Matcher isEqualToIgnoringCase(String expected) {
return PredicateMatcher.of(s -> s.equalsIgnoreCase(expected), "be equal to (ignoring case) {" + expected + "}");
}
public static Matcher hasLength(int length) {
return PredicateMatcher.of(s -> s.length() == length, "have length {" + length + "}", s -> "had length {" + s.length() + "}");
}
}