Class ThrowableAsserter.Asserted<R>

  • Type Parameters:
    R - The result type.
    Enclosing class:
    ThrowableAsserter<R>

    public static final class ThrowableAsserter.Asserted<R>
    extends Object
    An object that represents a ThrowableAsserter in its asserted state. It can be used to query the assertion results.
    Author:
    Rob Spoor
    Since:
    2.0
    • Method Detail

      • andReturnResult

        public Optional<R> andReturnResult()
        Returns the result of the executed code.
        Returns:
        An Optional describing the result, or Optional.empty() if an error was thrown or the result was null.
      • andReturnError

        public Throwable andReturnError()
        Returns the error that was thrown.
        Returns:
        The error that was thrown.
        Throws:
        IllegalStateException - If no error was thrown.
      • andReturnErrorAs

        public <T extends Throwable> T andReturnErrorAs​(Class<T> errorType)
        Returns the error that was thrown.
        Type Parameters:
        T - The expected type of error.
        Parameters:
        errorType - The expected type of error. This should be a common super type of all configured error types to prevent any ClassCastExceptions.
        Returns:
        The error that was thrown.
        Throws:
        IllegalStateException - If no error was thrown.
        ClassCastException - If the error that was thrown is not an instance of the given error type.
      • andReturnErrorIfThrown

        public Optional<Throwable> andReturnErrorIfThrown()
        Returns the error that was thrown.
        Returns:
        An Optional describing the error that was thrown, or Optional.empty() if no error was thrown.
      • andReturnErrorIfThrownAs

        public <T extends ThrowableOptional<T> andReturnErrorIfThrownAs​(Class<T> errorType)
        Returns the error that was thrown.
        Type Parameters:
        T - The expected type of error.
        Parameters:
        errorType - The expected type of error. This should be a common super type of all configured error types to prevent any ClassCastExceptions.
        Returns:
        An Optional describing the error that was thrown, or Optional.empty() if no error was thrown.
        Throws:
        ClassCastException - If an error was thrown that is not an instance of the given error type.