Package com.google.common.truth
Class OptionalSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.OptionalSubject
-
public final class OptionalSubject extends Subject
Propositions for Java 8Optional
subjects.- Author:
- Christian Gruber
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject,ActualT>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
hasValue(@Nullable java.lang.Object expected)
Fails if theOptional
<T>
does not have the given value or the subject is null.void
isEmpty()
Fails if theOptional
<T>
is present or the subject is null.void
isPresent()
Fails if theOptional
<T>
is empty or the subject is null.static Subject.Factory<OptionalSubject,java.util.Optional<?>>
optionals()
-
Methods inherited from class com.google.common.truth.Subject
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
-
-
-
-
Method Detail
-
isPresent
public void isPresent()
Fails if theOptional
<T>
is empty or the subject is null.
-
isEmpty
public void isEmpty()
Fails if theOptional
<T>
is present or the subject is null.
-
hasValue
public void hasValue(@Nullable java.lang.Object expected)
Fails if theOptional
<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");
-
optionals
public static Subject.Factory<OptionalSubject,java.util.Optional<?>> optionals()
-
-