FROM - the type of object this condition accepts.TO - the type of object the nested condition accepts.public class MappedCondition<FROM,TO> extends Condition<FROM>
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"));Condition.Status| Modifier and Type | Method and Description |
|---|---|
protected String |
buildMappingDescription(FROM from,
TO to)
Build the mapped condition description when applied with the FROM and TO values.
|
Description |
conditionDescriptionWithStatus(FROM actual)
Returns the description of this condition with its status failed or success.
|
static <FROM,TO> MappedCondition<FROM,TO> |
mappedCondition(Function<FROM,TO> mapping,
Condition<TO> condition)
Creates a new
|
static <FROM,TO> MappedCondition<FROM,TO> |
mappedCondition(Function<FROM,TO> mapping,
Condition<TO> condition,
String mappingDescription,
Object... args)
Creates a new
. |
boolean |
matches(FROM value)
Maps the value with the given function and verifies that it satisfies the nested
. |
describedAs, description, status, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitas, as, as, describedAspublic static <FROM,TO> MappedCondition<FROM,TO> mappedCondition(Function<FROM,TO> mapping, Condition<TO> condition, String mappingDescription, Object... args)
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.
FROM - the type of object the given condition accept.TO - the type of object the nested condition accept.mapping - the Function that maps the value to test to the a value for the nested condition.condition - the nested condition to evaluate.mappingDescription - describes the mapping, follows String.format(String, Object...) syntax.args - for describing the mapping as in String.format(String, Object...) syntax.MappedCondition.NullPointerException - if the given condition is null.NullPointerException - if the given mapping is null.public static <FROM,TO> MappedCondition<FROM,TO> mappedCondition(Function<FROM,TO> mapping, Condition<TO> condition)
MappedConditionFROM - the type of object the given condition accept.TO - the type of object the nested condition accept.mapping - the Function that maps the value to test to the a value for the nested condition.condition - the nested condition to evaluate.MappedCondition.NullPointerException - if the given condition is null.NullPointerException - if the given mapping is null.public boolean matches(FROM value)
Condition.protected String buildMappingDescription(FROM from, TO to)
from - the value to mapto - the mapped valuepublic Description conditionDescriptionWithStatus(FROM actual)
ConditionconditionDescriptionWithStatus in class Condition<FROM>actual - the instance to evaluate the condition status against.Copyright © 2025. All rights reserved.