Top Description Inners Fields Constructors Methods
org.assertj.core.api

public Class Condition<T>

extends Object
implements Descriptable<Condition<T>>
Class Inheritance
All Implemented Interfaces
org.assertj.core.api.Descriptable
Known Direct Subclasses
org.assertj.core.condition.Join, org.assertj.core.condition.MappedCondition, org.assertj.core.condition.Negative, org.assertj.core.condition.VerboseCondition, org.assertj.core.api.HamcrestCondition
Type Parameters
<T>
the type of object this condition accepts.
Static Imports
java.util.Objects.requireNonNull, org.assertj.core.api.Condition.Status.FAIL, .Condition.Status.SUCCESS

A condition to be met by an object.
Authors
Yvonne Wang, Alex Ruiz

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Condition.Status

Describes the condition status after being evaluated.

Field Summary

Modifier and TypeField and Description
pack-priv Description
private Predicate<T>

Constructor Summary

AccessConstructor and Description
public
Condition()

Creates a new Condition.

public
Condition(String
the description of this condition.
description
)

Creates a new Condition.

public
Condition(Predicate<T>
the Predicate used to build the condition.
predicate
,
String
the description of this condition.
description
,
Object...
optional parameter if description is a format String.
args
)

Creates a new Condition with the given Predicate, the built Condition will be met if the Predicate is.

public
Condition(Description
the description of this condition.
description
)

Creates a new Condition.

Method Summary

Modifier and TypeMethod and Description
private void
checkPredicate(Predicate<T> predicate)

public Description

Returns:

the description of this condition with its status.
conditionDescriptionWithStatus
(T
the instance to evaluate the condition status against.
actual
)

Returns the description of this condition with its status failed or success.

public Condition<T>
describedAs(Description
the new description to set.
newDescription
)

Implements org.assertj.core.api.Descriptable.describedAs.

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

Returns:

the description of this condition.
description
()

Returns the description of this condition.

public boolean

Returns:

true if the given value satisfies this condition; false otherwise.
matches
(T
the value to verify.
value
)

Verifies that the given value satisfies this condition.

protected Condition.Status
status(T actual)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

descriptionback to summary
pack-priv Description description
Annotations
@VisibleForTesting
predicateback to summary
private Predicate<T> predicate

Constructor Detail

Conditionback to summary
public Condition()

Creates a new Condition. The default description of this condition will the simple name of the condition's class.

Conditionback to summary
public Condition(String description)

Creates a new Condition.

Parameters
description:String

the description of this condition.

Exceptions
NullPointerException:
if the given description is null.
Conditionback to summary
public Condition(Predicate<T> predicate, String description, Object... args)

Creates a new Condition with the given 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:

 // 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);
Error message example:
 // 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:Predicate<T>

the Predicate used to build the condition.

description:String

the description of this condition.

args:Object[]

optional parameter if description is a format String.

Exceptions
NullPointerException:
  • if the given Predicate is null.
  • if the given description is null.
Conditionback to summary
public Condition(Description description)

Creates a new Condition.

Parameters
description:Description

the description of this condition.

Exceptions
NullPointerException:
if the given description is null.

Method Detail

checkPredicateback to summary
private void checkPredicate(Predicate<T> predicate)
conditionDescriptionWithStatusback to summary
public Description conditionDescriptionWithStatus(T actual)

Returns the description of this condition with its status failed or success.

Parameters
actual:T

the instance to evaluate the condition status against.

Returns:Description

the description of this condition with its status.

describedAsback to summary
public Condition<T> describedAs(Description newDescription)

Implements org.assertj.core.api.Descriptable.describedAs.

Doc from org.assertj.core.api.Descriptable.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.

Parameters
newDescription:Description

the new description to set.

Returns:Condition<T>

this object.

Annotations
@Override
descriptionback to summary
public Description description()

Returns the description of this condition.

Returns:Description

the description of this condition.

matchesback to summary
public boolean matches(T value)

Verifies that the given value satisfies this condition.

Parameters
value:T

the value to verify.

Returns:boolean

true if the given value satisfies this condition; false otherwise.

statusback to summary
protected Condition.Status status(T actual)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
org.assertj.core.api back to summary

public final Enum Condition.Status

extends Enum<Condition.Status>
Class Inheritance

Describes the condition status after being evaluated.

Field Summary

Modifier and TypeField and Description
public static final Condition.Status
public final String
public static final Condition.Status

Constructor Summary

AccessConstructor and Description
private
Status(String label)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Condition.Status
public static Condition.Status[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

FAILback to summary
public static final Condition.Status FAIL
labelback to summary
public final String label
SUCCESSback to summary
public static final Condition.Status SUCCESS

Constructor Detail

Statusback to summary
private Status(String label)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Condition.Status valueOf(String name)
valuesback to summary
public static Condition.Status[] values()