org.hamcrest.core.StringStartsWith Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-hamcrest Show documentation
Show all versions of java-hamcrest Show documentation
Hamcrest matcher library for Java
The newest version!
package org.hamcrest.core;
import org.hamcrest.Matcher;
/**
* Tests if the argument is a string that contains a substring.
*/
public class StringStartsWith extends SubstringMatcher {
public StringStartsWith(boolean ignoringCase, String substring) { super("starting with", ignoringCase, substring); }
@Override
protected boolean evalSubstringOf(String s) { return converted(s).startsWith(converted(substring)); }
/**
*
* Creates a matcher that matches if the examined {@link String} starts with the specified
* {@link String}.
*
* For example:
* assertThat("myStringOfNote", startsWith("my"))
*
* @param prefix
* the substring that the returned matcher will expect at the start of any examined string
*/
public static Matcher startsWith(String prefix) { return new StringStartsWith(false, prefix); }
/**
*
* Creates a matcher that matches if the examined {@link String} starts with the specified
* {@link String}, ignoring case
*
* For example:
* assertThat("myStringOfNote", startsWith("my"))
*
* @param prefix
* the substring that the returned matcher will expect at the start of any examined string
*/
public static Matcher startsWithIgnoringCase(String prefix) { return new StringStartsWith(true, prefix); }
}