SELF - the "self" type of this assertion class.public interface Descriptable<SELF>
| Modifier and Type | Method and Description |
|---|---|
default SELF |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
default SELF |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
default SELF |
as(Supplier<String> descriptionSupplier)
Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated
if the assertion succeeds.
|
SELF |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
default SELF |
describedAs(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
default SELF 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 an incorrect 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]\n
expected: 33\n
but was: 50");
}description - the new description to set.args - optional parameter if description is a format String.this object.NullPointerException - if the description is null.describedAs(String, Object...)default SELF as(Supplier<String> descriptionSupplier)
The description must be set before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Example :
// set an incorrect age to Mr Frodo which we all know is 33 years old.
frodo.setAge(50);
// the lazy test description is not evaluated as the assertion succeeds
assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(50);
try
{
// the lazy test description is evaluated as the assertion fails
assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(33);
}
catch (AssertionError e)
{
assertThat(e).hasMessage("[check Frodo's age]\n
expected: 33\n
but was: 50");
}descriptionSupplier - the description Supplier.this object.IllegalStateException - if the descriptionSupplier is null when evaluated.default SELF 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.
description - the new description to set.this object.NullPointerException - if the description is null.describedAs(Description)default SELF 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.as(String, Object...)
description - the new description to set.args - optional parameter if description is a format String.this object.NullPointerException - if the description is null.SELF 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.
description - the new description to set.this object.NullPointerException - if the description is null.Copyright © 2025. All rights reserved.