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(ThrowableAssert.ThrowingCallable).
| 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 |
|---|---|
ThrowableTypeAssert<T> |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
ThrowableTypeAssert<T> |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
ThrowableTypeAssert<T> |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
ThrowableTypeAssert<T> |
describedAs(String description,
Object... args)
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. |
protected 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.public ThrowableTypeAssert<T> as(String description, Object... args)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows String.format(String, Object...) syntax.
Example :
try {
// set a bad age to Mr Frodo which is really 33 years old.
frodo.setAge(50);
// specify a test description (call as() before the assertion !), it supports String format syntax.
assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33);
} catch (AssertionError e) {
assertThat(e).hasMessage("[check Frodo's age] expected:<[33]> but was:<[50]>");
}as in interface Descriptable<ThrowableTypeAssert<T extends Throwable>>description - the new description to set.args - optional parameter if description is a format String.this object.Descriptable.describedAs(String, Object...)public ThrowableTypeAssert<T> as(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.
as in interface Descriptable<ThrowableTypeAssert<T extends Throwable>>description - the new description to set.this object.Descriptable.describedAs(Description)public ThrowableTypeAssert<T> describedAs(String description, Object... args)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for since "as" is a keyword in Groovy.Descriptable.as(String, Object...)
describedAs in interface Descriptable<ThrowableTypeAssert<T extends Throwable>>description - the new description to set.args - optional parameter if description is a format String.this object.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 © 2014–2019 AssertJ. All rights reserved.