Class OptionalSubject


  • public final class OptionalSubject
    extends com.google.common.truth.Subject
    Propositions for Java 8 Optional subjects.
    Author:
    Christian Gruber
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.google.common.truth.Subject

        com.google.common.truth.Subject.Factory<SubjectT extends com.google.common.truth.Subject,​ActualT extends Object>
    • Method Detail

      • isPresent

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

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

        public void hasValue​(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");