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

com.annimon.stream.test.OptionalMatcher Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package com.annimon.stream.test;

import com.annimon.stream.Optional;
import static org.hamcrest.CoreMatchers.not;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;

public class OptionalMatcher {

    private OptionalMatcher() { }

    public static Matcher> isPresent() {
        return new IsPresentMatcher();
    }

    public static Matcher> isEmpty() {
        return not(isPresent());
    }

    public static class IsPresentMatcher extends TypeSafeDiagnosingMatcher> {

        @Override
        protected boolean matchesSafely(Optional optional, Description mismatchDescription) {
            mismatchDescription.appendText("Optional was empty");
            return optional.isPresent();
        }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy