T - type of throwable to be thrown.public class ThrowableTypeAssert<T extends Throwable> extends Object implements Descriptable<ThrowableTypeAssert<T>>
Throwable type.
The class itself does not do much, it delegates the work to ThrowableAssertAlternative after calling #isThrownBy(ThrowingCallable).
NotThrownAssert| Modifier and Type | Field and Description |
|---|---|
protected Description |
description |
protected Class<? extends T> |
expectedThrowableType |
| Constructor and Description |
|---|
ThrowableTypeAssert(Class<? extends T> throwableType)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected ThrowableAssertAlternative<T> |
buildThrowableTypeAssert(T throwable) |
ThrowableTypeAssert<T> |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
ThrowableAssertAlternative<T> |
isThrownBy(ThrowableAssert.ThrowingCallable throwingCallable)
Assert that an exception of type T is thrown by the
throwingCallable
and allow to chain assertions on the thrown exception. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitas, as, as, describedAsprotected Description description
public ThrowableAssertAlternative<T> isThrownBy(ThrowableAssert.ThrowingCallable throwingCallable)
throwingCallable
and allow to chain assertions on the thrown exception.
Example:
assertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); })
.withMessage("boom!"); throwingCallable - code throwing the exception of expected typeThrowableAssertAlternative.protected ThrowableAssertAlternative<T> buildThrowableTypeAssert(T throwable)
public ThrowableTypeAssert<T> describedAs(Description description)
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.
describedAs in interface Descriptable<ThrowableTypeAssert<T extends Throwable>>description - the new description to set.this object.Copyright © 2025. All rights reserved.