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-library Show documentation
Show all versions of hamcrest-library Show documentation
A library of Hamcrest matchers - deprecated, please use "hamcrest" instead
package org.hamcrest.text;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsNull.nullValue;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
/**
* Matches empty Strings (and null).
*/
public final class IsEmptyString extends BaseMatcher {
private static final IsEmptyString INSTANCE = new IsEmptyString();
@SuppressWarnings("unchecked")
private static final Matcher NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE);
@Override
public boolean matches(Object item) {
return item != null && item instanceof String && ((String) 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())
*
*/
@Factory
public static Matcher isEmptyString() {
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), isEmptyString())
*
*/
@Factory
public static Matcher isEmptyOrNullString() {
return NULL_OR_EMPTY_INSTANCE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy