it.ozimov.cirneco.hamcrest.java8.base.IsEmptyOptional Maven / Gradle / Ivy
package it.ozimov.cirneco.hamcrest.java8.base;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import java.util.Optional;
/**
* Is the given {@linkplain Optional} instance empty?
*
* @since version 0.1 for JDK8
*/
public class IsEmptyOptional extends TypeSafeMatcher {
/**
* Creates a matcher that matches when the examined {@linkplain Optional} contains no object.
*/
public static Matcher emptyOptional() {
return new IsEmptyOptional();
}
@Override
protected boolean matchesSafely(final Optional actual) {
return !actual.isPresent();
}
@Override
protected void describeMismatchSafely(final Optional item, final Description mismatchDescription) {
mismatchDescription.appendValue(item).appendText(" is not an empty optional");
}
@Override
public void describeTo(final Description description) {
description.appendText("an optional with no content");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy