Class OptionalAssert<T>

  • Type Parameters:
    T - the type of elements of the tested Optional value
    All Implemented Interfaces:
    org.assertj.core.api.Assert<OptionalAssert<T>,​com.google.common.base.Optional<T>>, org.assertj.core.api.Descriptable<OptionalAssert<T>>, org.assertj.core.api.ExtensionPoints<OptionalAssert<T>,​com.google.common.base.Optional<T>>

    public class OptionalAssert<T>
    extends org.assertj.core.api.AbstractAssert<OptionalAssert<T>,​com.google.common.base.Optional<T>>
    Assertions for guava Optional.

    To create an instance of this class, invoke Assertions.assertThat(Optional)

    Author:
    Kornel Kiełczewski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) org.assertj.core.internal.Failures failures  
      • Fields inherited from class org.assertj.core.api.AbstractAssert

        actual, info, myself, objects, throwUnsupportedExceptionOnEquals
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected OptionalAssert​(com.google.common.base.Optional<T> actual)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class org.assertj.core.api.AbstractAssert

        as, as, asInstanceOf, 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, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
    • Field Detail

      • failures

        org.assertj.core.internal.Failures failures
    • 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​(Object value)
        Verifies that the actual Optional contains the given value.

        Example :

         Optional<String> optional = Optional.of("Test");
        
         assertThat(optional).contains("Test");
        Parameters:
        value - the value to look for in actual Optional.
        Returns:
        this OptionalAssert for assertions chaining.
        Throws:
        AssertionError - if the actual Optional is null.
        AssertionError - if the actual Optional contains nothing or does not have the given value.
      • isAbsent

        public OptionalAssert<T> isAbsent()
        Verifies that the actual Optional contained instance is absent/null (ie. not Optional.isPresent()).

        Example :

         Optional<String> optional = Optional.absent();
        
         assertThat(optional).isAbsent();
        Returns:
        this OptionalAssert for assertions chaining.
        Throws:
        AssertionError - if the actual Optional is null.
        AssertionError - if the actual Optional contains a (non-null) instance.
      • isPresent

        public OptionalAssert<T> isPresent()
        Verifies that the actual Optional 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 actual Optional is null.
        AssertionError - if the actual Optional contains a null instance.
      • extractingValue

        public org.assertj.core.api.AbstractObjectAssert<?,​T> extractingValue()
        Chain assertion on the content of the Optional.

        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 actual Optional is null.
        AssertionError - if the actual Optional contains a null instance.
      • extractingCharSequence

        public org.assertj.core.api.AbstractCharSequenceAssert<?,​? extends CharSequence> extractingCharSequence()
        Chain assertion on the content of the Optional.

        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 actual Optional is null.
        AssertionError - if the actual Optional contains a null instance.