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

de.otto.edison.testsupport.matcher.OptionalMatchers Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
package de.otto.edison.testsupport.matcher;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

import java.util.Optional;

public class OptionalMatchers {

    public static Matcher> isPresent() {
        return new BaseMatcher>() {

            @Override
            public boolean matches(Object item) {
                return Optional.class.isAssignableFrom(item.getClass())
                        && ((Optional)item).isPresent();
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("Optional should be present");
            }
        };
    }

    public static Matcher> isAbsent() {
        return new BaseMatcher>() {

            @Override
            public boolean matches(Object item) {
                return Optional.class.isAssignableFrom(item.getClass())
                        && !((Optional)item).isPresent();
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("Optional should be absent");
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy