Skip to content

Commit

Permalink
Separate conditions that did and did not match in auto-config report
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Oct 6, 2016
1 parent 668993c commit 20a2db7
Showing 1 changed file with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ private StringBuilder getLogMessage(ConditionEvaluationReport report) {
report.getConditionAndOutcomesBySource());
for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) {
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("Negative matches:%n"));
message.append(String.format("-----------------%n"));
for (Map.Entry<String, ConditionAndOutcomes> entry : shortOutcomes.entrySet()) {
if (!entry.getValue().isFullMatch()) {
addLogMessage(message, entry.getKey(), entry.getValue());
addNonMatchLogMessage(message, entry.getKey(), entry.getValue());
}
}
message.append(String.format("%n%n"));
Expand Down Expand Up @@ -109,28 +109,56 @@ private Map<String, ConditionAndOutcomes> orderByName(
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) {
message.append(String.format("%n %s", source));
message.append(conditionAndOutcomes.isFullMatch() ? " matched" : " did not match")
.append(String.format("%n"));
message.append(String.format("%n %s:%n", source));
List<ConditionAndOutcome> matches = new ArrayList<ConditionAndOutcome>();
List<ConditionAndOutcome> nonMatches = new ArrayList<ConditionAndOutcome>();
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
message.append(" - ");
String outcomeMessage = conditionAndOutcome.getOutcome().getMessage();
if (StringUtils.hasLength(outcomeMessage)) {
message.append(outcomeMessage);
if (conditionAndOutcome.getOutcome().isMatch()) {
matches.add(conditionAndOutcome);
}
else {
message.append(conditionAndOutcome.getOutcome().isMatch() ? "matched"
: "did not match");
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);
}
message.append(" (");
message.append(ClassUtils
.getShortName(conditionAndOutcome.getCondition().getClass()));
message.append(String.format(")%n"));
}
}

private void logConditionAndOutcome(StringBuilder message, String indent,
ConditionAndOutcome conditionAndOutcome) {
message.append(String.format("%s- ", indent));
String outcomeMessage = conditionAndOutcome.getOutcome().getMessage();
if (StringUtils.hasLength(outcomeMessage)) {
message.append(outcomeMessage);
}
else {
message.append(conditionAndOutcome.getOutcome().isMatch() ? "matched"
: "did not match");
}
message.append(" (");
message.append(
ClassUtils.getShortName(conditionAndOutcome.getCondition().getClass()));
message.append(String.format(")%n"));
}

@Override
public String toString() {
return this.message.toString();
Expand Down

0 comments on commit 20a2db7

Please sign in to comment.