Class GuavaOptionalSubject


  • public final class GuavaOptionalSubject
    extends Subject
    Propositions for Guava Optional subjects.

    If you are looking for a java.util.Optional subject, see OptionalSubject.

    Author:
    Christian Gruber
    • Method Detail

      • isPresent

        public void isPresent()
        Fails if the Optional<T> is absent or the subject is null.
      • isAbsent

        public void isAbsent()
        Fails if the Optional<T> is present or the subject is null.
      • hasValue

        public void hasValue​(@Nullable java.lang.Object expected)
        Fails if the Optional<T> does not have the given value or the subject is null.

        To make more complex assertions on the optional's value split your assertion in two:

        
         assertThat(myOptional).isPresent();
         assertThat(myOptional.get()).contains("foo");