Top Description Fields Constructors Methods
org.assertj.core.condition

public Class MappedCondition<FROM, TO>

extends Condition<FROM>
Class Inheritance
Annotations
@Beta
Type Parameters
<FROM>
the type of object this condition accepts.
<TO>
the type of object the nested condition accepts.
Static Imports
java.lang.String.format, java.util.Objects.requireNonNull, org.assertj.core.util.Lists.list

Container Condition that maps the object under test and then check the resulting mapped value against its nested Condition.

Example:

 Condition<String> hasLineSeparator = new Condition<>(t -> t.contains(System.lineSeparator()), "has lineSeparator");

Condition<Optional<String>> optionalWithLineSeparator = MappedCondition.mappedCondition(Optional::get, hasLineSeparator, "optional value has lineSeparator");

// assertion succeeds
assertThat(Optional.of("a" + System.lineSeparator())).is(optionalWithLineSeparator);
// returns true
optionalWithLineSeparator.matches(Optional.of("a" + System.lineSeparator()));

// assertion fails
assertThat(Optional.of("a")).is(optionalWithLineSeparator);
// returns false
optionalWithLineSeparator.matches(Optional.of("a"));
Author
Stefan Bischof

Field Summary

Modifier and TypeField and Description
private Condition<TO>
private Function<FROM, TO>
private String

Constructor Summary

AccessConstructor and Description
private
MappedCondition(Function<FROM, TO> mapping, Condition<TO> condition, String mappingDescription)

Method Summary

Modifier and TypeMethod and Description
protected String

Returns:

the mapped condition description .
buildMappingDescription
(FROM
the value to map
from
,
TO
the mapped value
to
)

Build the mapped condition description when applied with the FROM and TO values.

private String
buildMappingDescription(FROM from, TO to, boolean withNested)

private static String
className(Object object)

public Description
conditionDescriptionWithStatus(FROM
the instance to evaluate the condition status against.
actual
)

Overrides org.assertj.core.api.Condition.conditionDescriptionWithStatus.

Returns the description of this condition with its status failed or success.
public static <
the type of object the given condition accept.
FROM
,
the type of object the nested condition accept.
TO
>
MappedCondition<FROM, TO>

Returns:

the created MappedCondition.
mappedCondition
(Function<FROM, TO>
the Function that maps the value to test to the a value for the nested condition.
mapping
,
Condition<TO>
the nested condition to evaluate.
condition
,
String
describes the mapping, follows String#format(String, Object...) syntax.
mappingDescription
,
Object...
for describing the mapping as in String#format(String, Object...) syntax.
args
)

Creates a new MappedCondition.

public static <
the type of object the given condition accept.
FROM
,
the type of object the nested condition accept.
TO
>
MappedCondition<FROM, TO>

Returns:

the created MappedCondition.
mappedCondition
(Function<FROM, TO>
the Function that maps the value to test to the a value for the nested condition.
mapping
,
Condition<TO>
the nested condition to evaluate.
condition
)

Creates a new MappedCondition

public boolean

Returns:

true if the given mapped value satisfies the nested condition; false otherwise.
matches
(FROM
the value to map
value
)

Overrides org.assertj.core.api.Condition.matches.

Maps the value with the given function and verifies that it satisfies the nested Condition.
Inherited from org.assertj.core.api.Condition:
describedAsdescriptionstatustoString

Field Detail

conditionback to summary
private Condition<TO> condition
mappingback to summary
private Function<FROM, TO> mapping
mappingDescriptionback to summary
private String mappingDescription

Constructor Detail

MappedConditionback to summary
private MappedCondition(Function<FROM, TO> mapping, Condition<TO> condition, String mappingDescription)

Method Detail

buildMappingDescriptionback to summary
protected String buildMappingDescription(FROM from, TO to)

Build the mapped condition description when applied with the FROM and TO values.

Parameters
from:FROM

the value to map

to:TO

the mapped value

Returns:String

the mapped condition description .

buildMappingDescriptionback to summary
private String buildMappingDescription(FROM from, TO to, boolean withNested)
classNameback to summary
private static String className(Object object)
conditionDescriptionWithStatusback to summary
public Description conditionDescriptionWithStatus(FROM actual)

Overrides org.assertj.core.api.Condition.conditionDescriptionWithStatus.

Doc from org.assertj.core.api.Condition.conditionDescriptionWithStatus.

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

Parameters
actual:FROM

the instance to evaluate the condition status against.

Returns:Description

the description of this condition with its status.

Annotations
@Override
mappedConditionback to summary
public static <FROM, TO> MappedCondition<FROM, TO> mappedCondition(Function<FROM, TO> mapping, Condition<TO> condition, String mappingDescription, Object... args)

Creates a new MappedCondition.

Example:

 Condition<String> hasLineSeparator = new Condition<>(t -> t.contains(System.lineSeparator()), "has lineSeparator");

Condition<Optional<String>> optionalWithLineSeparator = MappedCondition.mappedCondition(Optional::get, hasLineSeparator, "optional value has lineSeparator");

// assertion succeeds
assertThat(Optional.of("a" + System.lineSeparator())).is(optionalWithLineSeparator);
// returns true
optionalWithLineSeparator.matches(Optional.of("a" + System.lineSeparator()));

// assertion fails
assertThat(Optional.of("a")).is(optionalWithLineSeparator);
// returns false
optionalWithLineSeparator.matches(Optional.of("a"));

Note that the mappingDescription argument follows String#format(String, Object...) syntax.

Parameters
<FROM>
the type of object the given condition accept.
<TO>
the type of object the nested condition accept.
mapping:Function<FROM, TO>

the Function that maps the value to test to the a value for the nested condition.

condition:Condition<TO>

the nested condition to evaluate.

mappingDescription:String

describes the mapping, follows String#format(String, Object...) syntax.

args:Object[]

for describing the mapping as in String#format(String, Object...) syntax.

Returns:MappedCondition<FROM, TO>

the created MappedCondition.

Exceptions
NullPointerException:
  • if the given condition is null.
  • if the given mapping is null.
mappedConditionback to summary
public static <FROM, TO> MappedCondition<FROM, TO> mappedCondition(Function<FROM, TO> mapping, Condition<TO> condition)

Creates a new MappedCondition

Parameters
<FROM>
the type of object the given condition accept.
<TO>
the type of object the nested condition accept.
mapping:Function<FROM, TO>

the Function that maps the value to test to the a value for the nested condition.

condition:Condition<TO>

the nested condition to evaluate.

Returns:MappedCondition<FROM, TO>

the created MappedCondition.

Exceptions
NullPointerException:
  • if the given condition is null.
  • if the given mapping is null.
matchesback to summary
public boolean matches(FROM value)

Overrides org.assertj.core.api.Condition.matches.

Maps the value with the given function and verifies that it satisfies the nested Condition.

Parameters
value:FROM

the value to map

Returns:boolean

true if the given mapped value satisfies the nested condition; false otherwise.

Annotations
@Override