Package org.assertj.core.api
Class ThrowableTypeAssert<T extends Throwable>
java.lang.Object
org.assertj.core.api.ThrowableTypeAssert<T>
- Type Parameters:
T
- type of throwable to be thrown.
- All Implemented Interfaces:
Descriptable<ThrowableTypeAssert<T>>
- Direct Known Subclasses:
SoftThrowableTypeAssert
public class ThrowableTypeAssert<T extends Throwable>
extends Object
implements Descriptable<ThrowableTypeAssert<T>>
Assertion class checking
Throwable
type.
The class itself does not do much, it delegates the work to ThrowableAssertAlternative
after calling isThrownBy(ThrowingCallable)
.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected ThrowableAssertAlternative
<T> buildThrowableTypeAssert
(T throwable) protected void
checkThrowableType
(Throwable throwable) describedAs
(Description description) Sets the description of the assertion that is going to be called after.isThrownBy
(ThrowableAssert.ThrowingCallable throwingCallable) Assert that an exception of type T is thrown by thethrowingCallable
and allow to chain assertions on the thrown exception.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Field Details
-
expectedThrowableType
-
description
-
-
Constructor Details
-
ThrowableTypeAssert
Default constructor.- Parameters:
throwableType
- class representing the target (expected) exception.
-
-
Method Details
-
isThrownBy
Assert that an exception of type T is thrown by thethrowingCallable
and allow to chain assertions on the thrown exception.Example:
assertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); }) .withMessage("boom!");
- Parameters:
throwingCallable
- code throwing the exception of expected type- Returns:
- return a
ThrowableAssertAlternative
.
-
checkThrowableType
-
buildThrowableTypeAssert
-
describedAs
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
describedAs
in interfaceDescriptable<T extends Throwable>
- Parameters:
description
- the new description to set.- Returns:
this
object.
-