Class OptionalMatcher


  • public final class OptionalMatcher
    extends Object
    Hamcrest matchers for Optional.
    • Method Detail

      • optionalValue

        public static <T> org.hamcrest.Matcher<Optional<T>> optionalValue​(org.hamcrest.Matcher<? super T> matcher)
        A matcher for an Optional that checks it is present, and that the value matches the provided matcher.

        Usage example:

             assertThat(myOptional, optionalValue(is("expected")));
         
        Type Parameters:
        T - type of the value
        Parameters:
        matcher - matcher to validate the content of the optional
        Returns:
        matcher validating the Optional is present and matches the provided matcher
      • optionalEmpty

        public static <T> org.hamcrest.Matcher<Optional<T>> optionalEmpty()
        A matcher for an Optional that checks it is empty.

        Usage example:

             assertThat(myOptional, optionalEmpty());
         
        Type Parameters:
        T - type of the optional
        Returns:
        matcher validating the Optional is empty
      • optionalPresent

        public static <T> org.hamcrest.Matcher<Optional<T>> optionalPresent()
        A matcher for an Optional that checks it is present.

        Usage example:

             assertThat(myOptional, optionalPresent());
         
        Type Parameters:
        T - type of the value
        Returns:
        matcher validating the Optional is present