Package org.assertj.core.condition
Class MappedCondition<FROM,TO>
java.lang.Object
org.assertj.core.api.Condition<FROM>
org.assertj.core.condition.MappedCondition<FROM,TO>
- Type Parameters:
FROM- the type of object this condition accepts.TO- the type of object the nested condition accepts.
- All Implemented Interfaces:
Descriptable<Condition<FROM>>
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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.assertj.core.api.Condition
Condition.Status -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildMappingDescription(FROM from, TO to) Build the mapped condition description when applied with the FROM and TO values.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 newMappedConditionstatic <FROM,TO> MappedCondition <FROM, TO> mappedCondition(Function<FROM, TO> mapping, Condition<TO> condition, String mappingDescription, Object... args) Creates a new.MappedConditionbooleanMaps the value with the given function and verifies that it satisfies the nested.ConditionMethods inherited from class org.assertj.core.api.Condition
describedAs, description, status, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Method Details
-
mappedCondition
public static <FROM,TO> MappedCondition<FROM,TO> mappedCondition(Function<FROM, TO> mapping, Condition<TO> condition, String mappingDescription, Object... args) Creates a new.MappedConditionExample:
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.- Type Parameters:
FROM- the type of object the given condition accept.TO- the type of object the nested condition accept.- Parameters:
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, followsString.format(String, Object...)syntax.args- for describing the mapping as inString.format(String, Object...)syntax.- Returns:
- the created
MappedCondition. - Throws:
NullPointerException- if the given condition isnull.NullPointerException- if the given mapping isnull.
-
mappedCondition
public static <FROM,TO> MappedCondition<FROM,TO> mappedCondition(Function<FROM, TO> mapping, Condition<TO> condition) Creates a newMappedCondition- Type Parameters:
FROM- the type of object the given condition accept.TO- the type of object the nested condition accept.- Parameters:
mapping- the Function that maps the value to test to the a value for the nested condition.condition- the nested condition to evaluate.- Returns:
- the created
MappedCondition. - Throws:
NullPointerException- if the given condition isnull.NullPointerException- if the given mapping isnull.
-
matches
Maps the value with the given function and verifies that it satisfies the nested.Condition -
buildMappingDescription
Build the mapped condition description when applied with the FROM and TO values.- Parameters:
from- the value to mapto- the mapped value- Returns:
- the mapped condition description .
-
conditionDescriptionWithStatus
Description copied from class:ConditionReturns the description of this condition with its status failed or success.- Overrides:
conditionDescriptionWithStatusin classCondition<FROM>- Parameters:
actual- the instance to evaluate the condition status against.- Returns:
- the description of this condition with its status.
-