Package org.assertj.core.api
Class Condition<T>
java.lang.Object
org.assertj.core.api.Condition<T>
- Type Parameters:
T
- the type of object this condition accepts.
- All Implemented Interfaces:
Descriptable<Condition<T>>
- Direct Known Subclasses:
HamcrestCondition
,Join
,MappedCondition
,Negative
,VerboseCondition
A condition to be met by an object.
- Author:
- Yvonne Wang, Alex Ruiz
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describes the condition status after being evaluated. -
Constructor Summary
ConstructorDescriptionCreates a new
.Condition
Creates a new
.Condition
Condition
(Description description) Creates a new
.Condition
-
Method Summary
Modifier and TypeMethodDescriptionconditionDescriptionWithStatus
(T actual) Returns the description of this condition with its status failed or success.describedAs
(Description newDescription) Sets the description of the assertion that is going to be called after.Returns the description of this condition.boolean
Verifies that the given value satisfies this condition.protected Condition.Status
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs
-
Constructor Details
-
Condition
public Condition()Creates a new
. The default description of this condition will the simple name of the condition's class.Condition
-
Condition
Creates a new
.Condition
- Parameters:
description
- the description of this condition.- Throws:
NullPointerException
- if the given description isnull
.
-
Condition
Creates a new
with the givenCondition
Predicate
, the built Condition will be met if the Predicate is.You must give a description, it will be used to build a nice error message when the condition fails, you can pass args to build the description as in
String.format(String, Object...)
.Example:
Error message example:// build condition with Predicate<String> and set description using String#format pattern. Condition<String> fairyTale = new Condition<String>(s -> s.startsWith("Once upon a time"), "a %s tale", "fairy"); String littleRedCap = "Once upon a time there was a dear little girl ..."; assertThat(littleRedCap).is(fairyTale);
// unfortunately this assertion fails ... but contact me if you can make it pass :) assertThat("life").is(fairyTale); // error message Expecting: <"life"> to be <a fairy tale>
- Parameters:
predicate
- thePredicate
used to build the condition.description
- the description of this condition.args
- optional parameter if description is a format String.- Throws:
NullPointerException
- if the givenPredicate
isnull
.NullPointerException
- if the given description isnull
.
-
Condition
Creates a new
.Condition
- Parameters:
description
- the description of this condition.- Throws:
NullPointerException
- if the given description isnull
.
-
-
Method Details
-
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>
- Parameters:
newDescription
- the new description to set.- Returns:
this
object.
-
description
Returns the description of this condition.- Returns:
- the description of this condition.
-
conditionDescriptionWithStatus
Returns the description of this condition with its status failed or success.- Parameters:
actual
- the instance to evaluate the condition status against.- Returns:
- the description of this condition with its status.
-
status
-
matches
Verifies that the given value satisfies this condition.- Parameters:
value
- the value to verify.- Returns:
true
if the given value satisfies this condition;false
otherwise.
-
toString
-