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

org.hamcrest.text.IsEmptyString Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version

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