Skip to content

Commit

Permalink
remove need for a custom AssertionErrorFactory - see #203
Browse files Browse the repository at this point in the history
  • Loading branch information
bodewig committed Nov 5, 2020
1 parent baaa84a commit ab90c1d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 155 deletions.
Expand Up @@ -38,8 +38,6 @@

import static org.xmlunit.assertj3.error.ShouldBeNotSimilar.shouldBeNotIdentical;
import static org.xmlunit.assertj3.error.ShouldBeNotSimilar.shouldBeNotSimilar;
import static org.xmlunit.assertj3.error.ShouldBeSimilar.shouldBeIdentical;
import static org.xmlunit.assertj3.error.ShouldBeSimilar.shouldBeSimilar;
import static org.xmlunit.assertj3.error.ShouldNotHaveThrown.shouldNotHaveThrown;
import static org.xmlunit.diff.DifferenceEvaluators.Default;
import static org.xmlunit.diff.DifferenceEvaluators.chain;
Expand Down Expand Up @@ -346,7 +344,6 @@ private void compare(ComparisonContext context) {
Diff diff;

try {

diff = diffBuilder.build();
} catch (Exception e) {
throwAssertionError(shouldNotHaveThrown(e));
Expand All @@ -359,17 +356,38 @@ private void compare(ComparisonContext context) {
if (diff.hasDifferences()) {
Comparison firstDifferenceComparison = diff.getDifferences().iterator().next().getComparison();
if (ComparisonContext.IDENTICAL == context) {
throwAssertionError(shouldBeIdentical(controlSystemId, testSystemId, firstDifferenceComparison, formatter, formatXml));
failComparison("identical", controlSystemId, testSystemId, firstDifferenceComparison, formatter, formatXml);
} else if (ComparisonContext.SIMILAR == context) {
throwAssertionError(shouldBeSimilar(controlSystemId, testSystemId, firstDifferenceComparison, formatter, formatXml));
failComparison("similar", controlSystemId, testSystemId, firstDifferenceComparison, formatter, formatXml);
}
} else {

if (ComparisonContext.NOT_IDENTICAL == context) {
throwAssertionError(shouldBeNotIdentical(controlSystemId, testSystemId));
} else if (ComparisonContext.NOT_SIMILAR == context) {
throwAssertionError(shouldBeNotSimilar(controlSystemId, testSystemId));
}
}
}


private static final String COMPARISON_FAILURE_PATTERN = "%nExpecting:%n <%s> and <%s> to be %s%n%s%nexpected:<%s> but was:<%s>>";

private void failComparison(final String type, final String controlSystemId,
final String testSystemId, final Comparison difference,
final ComparisonFormatter formatter, final boolean formatXml) {
final String controlId = controlSystemId != null ? controlSystemId : "control instance";
final String testId = testSystemId != null ? testSystemId : "test instance";
final String description = formatter.getDescription(difference);

final String expected = formatter.getDetails(difference.getControlDetails(),
difference.getType(), formatXml);
final String actual = formatter.getDetails(difference.getTestDetails(),
difference.getType(), formatXml);

final String msg = String.format(COMPARISON_FAILURE_PATTERN, controlId, testId, type,
description, expected, actual);

failWithActualExpectedAndMessage(expected, actual, msg);
}

}

This file was deleted.

This file was deleted.

Expand Up @@ -123,7 +123,7 @@ public void testAreIdentical_withWhitespaces_shouldFailed() {

thrown.expectAssertionError("Expecting:%n <control instance> and <test instance> to be identical");
thrown.expectAssertionError("Expected child nodelist length '1' but was '3'");
thrown.expectAssertionError("expected:<<a>[<b/>]</a>> but was:<<a>[%n <b/>%n]</a>>");
thrown.expectAssertionError("expected:<<a><b/></a>> but was:<<a>%n <b/>%n</a>>");

String testXml = String.format("<a>%n <b/>%n</a>");
String controlXml = "<a><b/></a>";
Expand Down

0 comments on commit ab90c1d

Please sign in to comment.