org.hamcrest.text.IsEmptyString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hamcrest Show documentation
Show all versions of hamcrest Show documentation
Core API and libraries of hamcrest matcher framework.
package org.hamcrest.text;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsNull.nullValue;
/**
* Matches empty Strings (and null).
*/
public final class IsEmptyString extends TypeSafeMatcher {
private static final IsEmptyString INSTANCE = new IsEmptyString();
@SuppressWarnings("unchecked")
private static final Matcher NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE);
private IsEmptyString() { }
@Override
public boolean matchesSafely(String item) {
return item.equals("");
}
@Override
public void describeTo(Description description) {
description.appendText("an empty string");
}
/**
* Creates a matcher of {@link String} that matches when the examined string has zero length.
* For example:
* assertThat("", isEmptyString())
*
* @deprecated use is(emptyString()) instead
*/
@Deprecated
public static Matcher isEmptyString() {
return emptyString();
}
/**
* Creates a matcher of {@link String} that matches when the examined string has zero length.
* For example:
* assertThat("", is(emptyString()))
*
*/
public static Matcher emptyString() {
return INSTANCE;
}
/**
* Creates a matcher of {@link String} that matches when the examined string is null
, or
* has zero length.
* For example:
* assertThat(((String)null), isEmptyOrNullString())
*
* @deprecated use is(emptyOrNullString()) instead
*
*/
@Deprecated
public static Matcher isEmptyOrNullString() {
return emptyOrNullString();
}
/**
* Creates a matcher of {@link String} that matches when the examined string is null
, or
* has zero length.
* For example:
* assertThat(((String)null), is(emptyOrNullString()))
*
*/
public static Matcher emptyOrNullString() {
return NULL_OR_EMPTY_INSTANCE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy