Package com.google.common.truth
Class GuavaOptionalSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.GuavaOptionalSubject
-
public final class GuavaOptionalSubject extends Subject
Propositions for GuavaOptional
subjects.If you are looking for a
java.util.Optional
subject, seeOptionalSubject
.- 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 Instance Methods Concrete Methods Modifier and Type Method Description void
hasValue(@Nullable Object expected)
Fails if theOptional
<T>
does not have the given value or the subject is null.void
isAbsent()
Fails if theOptional
<T>
is present or the subject is null.void
isPresent()
Fails if theOptional
<T>
is absent or the subject is null.-
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 absent or the subject is null.
-
isAbsent
public void isAbsent()
Fails if theOptional
<T>
is present or the subject is null.
-
hasValue
public void hasValue(@Nullable 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");
-
-