Top Description Methods
org.assertj.core.api

public Interface Descriptable<SELF>

Known Direct Subinterfaces
org.assertj.core.api.Assert
Known Direct Implementers
org.assertj.core.api.NotThrownAssert, org.assertj.core.api.Condition, org.assertj.core.api.ThrowableTypeAssert
Type Parameters
<SELF>
the "self" type of this assertion class.
Imports
java.util.function.Supplier, org.assertj.core.description.Description, .LazyTextDescription, .TextDescription

An object that has a description.
Authors
Alex Ruiz, Yvonne Wang, Mikhail Mazursky

Method Summary

Modifier and TypeMethod and Description
public default SELF

Returns:

this object.
as
(String
the new description to set.
description
,
Object...
optional parameter if description is a format String.
args
)

Sets the description of the assertion that is going to be called after.

public default SELF

Returns:

this object.
as
(final Supplier<String>
the description Supplier.
descriptionSupplier
)

Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.

public default SELF

Returns:

this object.
as
(Description
the new description to set.
description
)

Sets the description of the assertion that is going to be called after.

public default SELF

Returns:

this object.
describedAs
(String
the new description to set.
description
,
Object...
optional parameter if description is a format String.
args
)

Sets the description of the assertion that is going to be called after.

public default SELF

Returns:

this object.
describedAs
(final Supplier<String>
the description Supplier.
descriptionSupplier
)

Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.

public SELF

Returns:

this object.
describedAs
(Description
the new description to set.
description
)

Sets the description of the assertion that is going to be called after.

Method Detail

asback to summary
public default SELF as(String description, Object... args)

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.

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");
}
Parameters
description:String

the new description to set.

args:Object[]

optional parameter if description is a format String.

Returns:SELF

this object.

Exceptions
NullPointerException:
if the description is null.
See Also
describedAs(String, Object...)
asback to summary
public default SELF as(final 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.

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");
}
Parameters
descriptionSupplier:Supplier<String>

the description Supplier.

Returns:SELF

this object.

Exceptions
IllegalStateException:
if the descriptionSupplier is null when evaluated.
asback to summary
public default SELF as(Description description)

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.

Parameters
description:Description

the new description to set.

Returns:SELF

this object.

Exceptions
NullPointerException:
if the description is null.
See Also
describedAs(Description)
describedAsback to summary
public default SELF describedAs(String description, Object... args)

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.

Alias for as(String, Object...) since "as" is a keyword in Groovy.

Parameters
description:String

the new description to set.

args:Object[]

optional parameter if description is a format String.

Returns:SELF

this object.

Exceptions
NullPointerException:
if the description is null.
describedAsback to summary
public default SELF describedAs(final 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.

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");
}
Parameters
descriptionSupplier:Supplier<String>

the description Supplier.

Returns:SELF

this object.

Exceptions
IllegalStateException:
if the descriptionSupplier is null when evaluated.
describedAsback to summary
public SELF describedAs(Description description)

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.

Parameters
description:Description

the new description to set.

Returns:SELF

this object.

Exceptions
NullPointerException:
if the description is null.