Class OptionalMatcher


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

      • value

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

        Usage example:

             assertThat(myOptional, value(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
      • empty

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

        Usage example:

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

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

        Usage example:

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