T
- the type of elements of the tested Optional valuepublic class OptionalAssert<T> extends org.assertj.core.api.AbstractAssert<OptionalAssert<T>,com.google.common.base.Optional<T>>
Optional
.
To create an instance of this class, invoke Assertions.assertThat(Optional)
Modifier | Constructor and Description |
---|---|
protected |
OptionalAssert(com.google.common.base.Optional<T> actual) |
Modifier and Type | Method and Description |
---|---|
OptionalAssert<T> |
contains(Object value)
Verifies that the actual
Optional contains the given value. |
protected com.google.common.base.Optional<T> |
getActual() |
OptionalAssert<T> |
isAbsent()
Verifies that the actual
Optional contained instance is absent/null (ie. |
OptionalAssert<T> |
isPresent()
Verifies that the actual
Optional contains a (non-null) instance. |
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
protected OptionalAssert(com.google.common.base.Optional<T> actual)
protected com.google.common.base.Optional<T> getActual()
public OptionalAssert<T> contains(Object value)
Optional
contains the given value.Example :
Optional<String> optional = Optional.of("Test"); assertThat(optional).hasValue("Test");
value
- the value to look for in actual Optional
.OptionalAssert
for assertions chaining.AssertionError
- if the actual Optional
is null
.AssertionError
- if the actual Optional
contains nothing or does not have the given value.public OptionalAssert<T> isAbsent()
Optional
contained instance is absent/null (ie. not Optional.isPresent()
).Example :
Optional<String> optional = Optional.absent(); assertThat(optional).isAbsent();
OptionalAssert
for assertions chaining.AssertionError
- if the actual Optional
is null
.AssertionError
- if the actual Optional
contains a (non-null) instance.public OptionalAssert<T> isPresent()
Optional
contains a (non-null) instance.Example :
Optional<String> optional = Optional.of("value"); assertThat(optional).isPresent();
OptionalAssert
for assertions chaining.AssertionError
- if the actual Optional
is null
.AssertionError
- if the actual Optional
contains a null instance.Copyright © 2013 AssertJ. All Rights Reserved.