Merge branch '1.5.x'

pull/7125/head
Andy Wilkinson 8 years ago
commit c465fcefad

@ -55,7 +55,7 @@ public class ConditionEvaluationReportMessage {
report.getConditionAndOutcomesBySource()); report.getConditionAndOutcomesBySource());
for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) { for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) {
if (entry.getValue().isFullMatch()) { if (entry.getValue().isFullMatch()) {
addLogMessage(message, entry.getKey(), entry.getValue()); addMatchLogMessage(message, entry.getKey(), entry.getValue());
} }
} }
message.append(String.format("%n%n")); message.append(String.format("%n%n"));
@ -63,7 +63,7 @@ public class ConditionEvaluationReportMessage {
message.append(String.format("-----------------%n")); message.append(String.format("-----------------%n"));
for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) { for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) {
if (!entry.getValue().isFullMatch()) { if (!entry.getValue().isFullMatch()) {
addLogMessage(message, entry.getKey(), entry.getValue()); addNonMatchLogMessage(message, entry.getKey(), entry.getValue());
} }
} }
message.append(String.format("%n%n")); message.append(String.format("%n%n"));
@ -109,13 +109,42 @@ public class ConditionEvaluationReportMessage {
return result; return result;
} }
private void addLogMessage(StringBuilder message, String source, private void addMatchLogMessage(StringBuilder message, String source,
ConditionAndOutcomes matches) {
message.append(String.format("%n %s matched:%n", source));
for (ConditionAndOutcome match : matches) {
logConditionAndOutcome(message, " ", match);
}
}
private void addNonMatchLogMessage(StringBuilder message, String source,
ConditionAndOutcomes conditionAndOutcomes) { ConditionAndOutcomes conditionAndOutcomes) {
message.append(String.format("%n %s", source)); message.append(String.format("%n %s:%n", source));
message.append(conditionAndOutcomes.isFullMatch() ? " matched" : " did not match") List<ConditionAndOutcome> matches = new ArrayList<ConditionAndOutcome>();
.append(String.format("%n")); List<ConditionAndOutcome> nonMatches = new ArrayList<ConditionAndOutcome>();
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) { for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
message.append(" - "); if (conditionAndOutcome.getOutcome().isMatch()) {
matches.add(conditionAndOutcome);
}
else {
nonMatches.add(conditionAndOutcome);
}
}
message.append(String.format(" Did not match:%n"));
for (ConditionAndOutcome nonMatch : nonMatches) {
logConditionAndOutcome(message, " ", nonMatch);
}
if (!matches.isEmpty()) {
message.append(String.format(" Matched:%n"));
for (ConditionAndOutcome match : matches) {
logConditionAndOutcome(message, " ", match);
}
}
}
private void logConditionAndOutcome(StringBuilder message, String indent,
ConditionAndOutcome conditionAndOutcome) {
message.append(String.format("%s- ", indent));
String outcomeMessage = conditionAndOutcome.getOutcome().getMessage(); String outcomeMessage = conditionAndOutcome.getOutcome().getMessage();
if (StringUtils.hasLength(outcomeMessage)) { if (StringUtils.hasLength(outcomeMessage)) {
message.append(outcomeMessage); message.append(outcomeMessage);
@ -125,11 +154,10 @@ public class ConditionEvaluationReportMessage {
: "did not match"); : "did not match");
} }
message.append(" ("); message.append(" (");
message.append(ClassUtils message.append(
.getShortName(conditionAndOutcome.getCondition().getClass())); ClassUtils.getShortName(conditionAndOutcome.getCondition().getClass()));
message.append(String.format(")%n")); message.append(String.format(")%n"));
} }
}
@Override @Override
public String toString() { public String toString() {

Loading…
Cancel
Save