@FluidAPIDesign public final class ThrowableAssertion extends Object
Example:
assertThrows(() -> someFunctionThatThrows())
.isIntanceOf(RuntimeException.class)
.hasNoCause();
| Modifier and Type | Method and Description |
|---|---|
static ThrowableAssertion |
assertThrows(ExceptionOperation operation)
Assert that a function throws an exception.
|
ThrowableAssertion |
containsInMessage(String messageString)
Assert that the exception contains a string in its message.
|
ThrowableAssertion |
hasCauseInstanceOf(Class<? extends Throwable> exceptionClass)
Asserts that the Exception has a cause of a particular type.
|
ThrowableAssertion |
hasMessage(String expectedMessage)
Checks to make sure the exception contains a certain message.
|
ThrowableAssertion |
hasNoCause()
Assert that the exception has no causing exception
|
ThrowableAssertion |
isInstanceOf(Class<? extends Throwable> exceptionClass)
Check that the Exception is of a particular type.
|
public static ThrowableAssertion assertThrows(ExceptionOperation operation) throws ExceptionNotThrownException
operation - The Lambda function that encapsulates code you expect to throw an exception.ExceptionNotThrownException - If no exception is thrown.public ThrowableAssertion isInstanceOf(Class<? extends Throwable> exceptionClass)
exceptionClass - The expected type of the Exception.public ThrowableAssertion hasMessage(String expectedMessage)
expectedMessage - The exact message expectedpublic ThrowableAssertion containsInMessage(String messageString)
messageString - The partial message to expected.public ThrowableAssertion hasNoCause()
public ThrowableAssertion hasCauseInstanceOf(Class<? extends Throwable> exceptionClass)
exceptionClass - The type expected.Copyright © 2015–2018 RedRoma, Inc.. All rights reserved.