[MappedCondition] generate proper conditionDescriptionWithStatus
@@ -14,11 +14,14 @@ package org.assertj.core.condition;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
+import static org.assertj.core.util.Lists.list;
import java.util.function.Function;
import org.assertj.core.annotations.Beta;
import org.assertj.core.api.Condition;
+import org.assertj.core.description.Description;
+import org.assertj.core.description.JoinDescription;
/**
* Container {@link Condition} that maps the object under test and then check the resulting mapped value against its nested {@link Condition}.
@@ -131,6 +134,11 @@ public class MappedCondition<FROM, TO> extends Condition<FROM> {
* @return the mapped condition description .
*/
protected String buildMappingDescription(FROM from, TO to) {
+ return buildMappingDescription(from, to, true);
+ }
+
+ private String buildMappingDescription(FROM from, TO to, boolean withNested) {
+
StringBuilder sb = new StringBuilder("mapped");
if (!mappingDescription.isEmpty()) sb.append(format("%n using: %s", mappingDescription));
@@ -141,10 +149,19 @@ public class MappedCondition<FROM, TO> extends Condition<FROM> {
else sb.append(format(" to: <%s> %s%n", className(to), to));
sb.append(" then checked:");
- sb.append(format("%n %-10s", condition));
+ if (withNested) sb.append(format("%n %-10s", condition));
return sb.toString();
}
+ @Override
+ public Description conditionDescriptionWithStatus(FROM actual) {
+ TO mappedObject = mapping.apply(actual);
+ Description descriptionsWithStatus = condition.conditionDescriptionWithStatus(mappedObject);
+ Status status = status(actual);
+ String descriptionStart = format("%s %s", status, buildMappingDescription(actual, mappedObject, false));
+ return new JoinDescription(descriptionStart, "", list(descriptionsWithStatus));
+ }
+
private static String className(Object object) {
return object.getClass().getSimpleName();
}
