Class OptionalAssert<T>

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

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

        public AbstractCharSequenceAssert<?,​? extends java.lang.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:
        java.lang.AssertionError - if the actual Optional is null.
        java.lang.AssertionError - if the actual Optional contains a null instance.