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. |
org.assertj.core.api.AbstractCharSequenceAssert<?,? extends CharSequence> |
extractingCharSequence()
Chain assertion on the content of the
Optional. |
org.assertj.core.api.AbstractObjectAssert<?,T> |
extractingValue()
Chain assertion on the content of the
Optional. |
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, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnErrorprotected 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).contains("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.public org.assertj.core.api.AbstractObjectAssert<?,T> extractingValue()
Optional.
Example :
Optional<Number> optional = Optional.of(12L);
assertThat(optional).extractingValue().isInstanceOf(Long.class);AbstractObjectAssert for assertions chaining on the content of the Optional.AssertionError - if the actual Optional is null.AssertionError - if the actual Optional contains a null instance.public org.assertj.core.api.AbstractCharSequenceAssert<?,? extends CharSequence> extractingCharSequence()
Optional.
Example :
Optional<String> optional = Optional.of("Bill");
assertThat(optional).extractingCharSequence().startsWith("Bi");AbstractCharSequenceAssert for assertions chaining on the content of the Optional.AssertionError - if the actual Optional is null.AssertionError - if the actual Optional contains a null instance.Copyright © 2018 AssertJ. All rights reserved.