Package com.google.common.truth
Class OptionalSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.OptionalSubject
-
-
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 Deprecated 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
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,Optional<?>>
optionals()
Deprecated.Instead ofabout(optionals()).that(...)
, use justthat(...)
.-
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 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
@Deprecated public static Subject.Factory<OptionalSubject,Optional<?>> optionals()
Deprecated.Instead ofabout(optionals()).that(...)
, use justthat(...)
. Similarly, instead ofassertAbout(optionals()).that(...)
, use justassertThat(...)
.Obsolete factory instance. This factory was previously necessary for assertions likeassertWithMessage(...).about(paths()).that(path)....
. Now, you can perform assertions like that without theabout(...)
call.
-
-