Package org.assertj.guava.api
Class OptionalAssert<T>
java.lang.Object
org.assertj.core.api.AbstractAssert<OptionalAssert<T>,Optional<T>>
org.assertj.guava.api.OptionalAssert<T>
- Type Parameters:
T
- the type of elements of the tested Optional value
- All Implemented Interfaces:
Assert<OptionalAssert<T>,
,Optional<T>> Descriptable<OptionalAssert<T>>
,ExtensionPoints<OptionalAssert<T>,
Optional<T>>
Assertions for guava
Optional
.
To create an instance of this class, invoke Assertions.assertThat(Optional)
- Author:
- Kornel Kiełczewski
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionVerifies that the actualOptional
contains the given value.AbstractCharSequenceAssert
<?, ? extends CharSequence> Chain assertion on the content of theOptional
.Chain assertion on the content of theOptional
.isAbsent()
Verifies that the actualOptional
contained instance is absent/null (ie.Verifies that the actualOptional
contains a (non-null) instance.Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
OptionalAssert
-
-
Method Details
-
getActual
-
contains
Verifies that the actualOptional
contains the given value.
Example :
Optional<String> optional = Optional.of("Test"); assertThat(optional).contains("Test");
- Parameters:
value
- the value to look for in actualOptional
.- Returns:
- this
OptionalAssert
for assertions chaining. - Throws:
AssertionError
- if the actualOptional
isnull
.AssertionError
- if the actualOptional
contains nothing or does not have the given value.
-
isAbsent
Verifies that the actualOptional
contained instance is absent/null (ie. notOptional.isPresent()
).
Example :
Optional<String> optional = Optional.absent(); assertThat(optional).isAbsent();
- Returns:
- this
OptionalAssert
for assertions chaining. - Throws:
AssertionError
- if the actualOptional
isnull
.AssertionError
- if the actualOptional
contains a (non-null) instance.
-
isPresent
Verifies that the actualOptional
contains a (non-null) instance.
Example :
Optional<String> optional = Optional.of("value"); assertThat(optional).isPresent();
- Returns:
- this
OptionalAssert
for assertions chaining. - Throws:
AssertionError
- if the actualOptional
isnull
.AssertionError
- if the actualOptional
contains a null instance.
-
extractingValue
Chain assertion on the content of theOptional
.Example :
Optional<Number> optional = Optional.of(12L); assertThat(optional).extractingValue().isInstanceOf(Long.class);
- Returns:
- a new
AbstractObjectAssert
for assertions chaining on the content of the Optional. - Throws:
AssertionError
- if the actualOptional
isnull
.AssertionError
- if the actualOptional
contains a null instance.
-
extractingCharSequence
Chain assertion on the content of theOptional
.Example :
Optional<String> optional = Optional.of("Bill"); assertThat(optional).extractingCharSequence().startsWith("Bi");
- Returns:
- a new
AbstractCharSequenceAssert
for assertions chaining on the content of the Optional. - Throws:
AssertionError
- if the actualOptional
isnull
.AssertionError
- if the actualOptional
contains a null instance.
-