Package org.assertj.guava.api
Class OptionalAssert<T>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<OptionalAssert<T>,com.google.common.base.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>,com.google.common.base.Optional<T>>,Descriptable<OptionalAssert<T>>,ExtensionPoints<OptionalAssert<T>,com.google.common.base.Optional<T>>
public class OptionalAssert<T> extends AbstractAssert<OptionalAssert<T>,com.google.common.base.Optional<T>>
Assertions for guavaOptional.To create an instance of this class, invoke
Assertions.assertThat(Optional)
-
-
Field Summary
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedOptionalAssert(com.google.common.base.Optional<T> actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionalAssert<T>contains(java.lang.Object value)Verifies that the actualOptionalcontains the given value.AbstractCharSequenceAssert<?,? extends java.lang.CharSequence>extractingCharSequence()Chain assertion on the content of theOptional.AbstractObjectAssert<?,T>extractingValue()Chain assertion on the content of theOptional.protected com.google.common.base.Optional<T>getActual()OptionalAssert<T>isAbsent()Verifies that the actualOptionalcontained instance is absent/null (ie.OptionalAssert<T>isPresent()Verifies that the actualOptionalcontains a (non-null) instance.-
Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, 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, usingEquals, usingEquals, 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 Detail
-
OptionalAssert
protected OptionalAssert(com.google.common.base.Optional<T> actual)
-
-
Method Detail
-
getActual
protected com.google.common.base.Optional<T> getActual()
-
contains
public OptionalAssert<T> contains(java.lang.Object value)
Verifies that the actualOptionalcontains 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
OptionalAssertfor assertions chaining. - Throws:
java.lang.AssertionError- if the actualOptionalisnull.java.lang.AssertionError- if the actualOptionalcontains nothing or does not have the given value.
-
isAbsent
public OptionalAssert<T> isAbsent()
Verifies that the actualOptionalcontained instance is absent/null (ie. notOptional.isPresent()).
Example :
Optional<String> optional = Optional.absent(); assertThat(optional).isAbsent();- Returns:
- this
OptionalAssertfor assertions chaining. - Throws:
java.lang.AssertionError- if the actualOptionalisnull.java.lang.AssertionError- if the actualOptionalcontains a (non-null) instance.
-
isPresent
public OptionalAssert<T> isPresent()
Verifies that the actualOptionalcontains a (non-null) instance.
Example :
Optional<String> optional = Optional.of("value"); assertThat(optional).isPresent();- Returns:
- this
OptionalAssertfor assertions chaining. - Throws:
java.lang.AssertionError- if the actualOptionalisnull.java.lang.AssertionError- if the actualOptionalcontains a null instance.
-
extractingValue
public AbstractObjectAssert<?,T> extractingValue()
Chain assertion on the content of theOptional.Example :
Optional<Number> optional = Optional.of(12L); assertThat(optional).extractingValue().isInstanceOf(Long.class);- Returns:
- a new
AbstractObjectAssertfor assertions chaining on the content of the Optional. - Throws:
java.lang.AssertionError- if the actualOptionalisnull.java.lang.AssertionError- if the actualOptionalcontains a null instance.
-
extractingCharSequence
public AbstractCharSequenceAssert<?,? extends java.lang.CharSequence> extractingCharSequence()
Chain assertion on the content of theOptional.Example :
Optional<String> optional = Optional.of("Bill"); assertThat(optional).extractingCharSequence().startsWith("Bi");- Returns:
- a new
AbstractCharSequenceAssertfor assertions chaining on the content of the Optional. - Throws:
java.lang.AssertionError- if the actualOptionalisnull.java.lang.AssertionError- if the actualOptionalcontains a null instance.
-
-