Class ThrowableAsserter.Asserted<R>
- java.lang.Object
-
- com.github.robtimus.junit.support.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 aThrowableAsserter
in its asserted state. It can be used to query the assertion results.- Author:
- Rob Spoor
- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Throwable
andReturnError()
Returns the error that was thrown.<T extends Throwable>
TandReturnErrorAs(Class<T> errorType)
Returns the error that was thrown.Optional<Throwable>
andReturnErrorIfThrown()
Returns the error that was thrown.<T extends Throwable>
Optional<T>andReturnErrorIfThrownAs(Class<T> errorType)
Returns the error that was thrown.Optional<R>
andReturnResult()
Returns the result of the executed code.
-
-
-
Method Detail
-
andReturnResult
public Optional<R> andReturnResult()
Returns the result of the executed code.- Returns:
- An
Optional
describing the result, orOptional.empty()
if an error was thrown or the result wasnull
.
-
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 anyClassCastException
s.- 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, orOptional.empty()
if no error was thrown.
-
andReturnErrorIfThrownAs
public <T extends Throwable> Optional<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 anyClassCastException
s.- Returns:
- An
Optional
describing the error that was thrown, orOptional.empty()
if no error was thrown. - Throws:
ClassCastException
- If an error was thrown that is not an instance of the given error type.
-
-