All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.olib963.javatest.matchers.StringMatchers Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
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() + "}");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy