Skip to content

Commit

Permalink
Change KiwiXmlAssertTest assertions to check for instanceof Assertion…
Browse files Browse the repository at this point in the history
…Error

okhttp3.mockwebserver in version 4.12.0 depends on JUnit 4 (because
MockWebServer actually extends ExternalResource). This caused some
tests in KiwiXmlAssertTest to fail because they were expecting errors to
be exactly instance of AssertionError. But xmlunit-assertj (deep inside
org.xmlunit.assertj.error.ComparisonFailureErrorFactory) actually changes
the error it throws to be an org,junit.ComparisonFailure if that class is
available at runtime, whereas it simply delegates to AssertJ and throws a
regular AssertionError if it is not available. So, by mockwebserver
depending on JUnit 4.x, it makes ComparisonFailure available on the
class path, so the throwable changes to ComparisonFailure instead of
a raw AssertionError. ComparisonFailure is a subclass of AssertionError
so we can fix it by changing our assertions in KiwiXmlAssertTest to
only check that a Throwable is an instance of (not exactly) AssertionError,
so it will pass whether ComparisonFailure exists or not.

I don't know for sure, but am guessing they have to do it this way
for JUnit 4.x environments to work properly. But I'm not at all sure.
  • Loading branch information
sleberknight committed Jun 19, 2024
1 parent db04838 commit 35d55f1
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void shouldAcceptTestNameAsString() {
.withTestName("custom-test-name")
.and(otherXml)
.areIdentical())
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}

@Test
Expand All @@ -63,7 +63,7 @@ void shouldAcceptTestNameFromTestInfo(TestInfo testInfo) {
.withTestNameFrom(testInfo)
.and(otherXml)
.areIdentical())
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ void shouldThrowAssertionErrorWhenXmlIsDifferent() {

assertThatThrownBy(() ->
KiwiXmlAssert.assertThat(xml).isIdenticalTo(otherXml))
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ void shouldThrowAssertionErrorWhenXmlIsDifferent() {

assertThatThrownBy(() ->
KiwiXmlAssert.assertThat(xml).isIdenticalToIgnoringWhitespace(otherXml))
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ void canaryDoesNotIgnoreCommentsBetweenTags() {

assertThatThrownBy(() ->
KiwiXmlAssert.assertThat(xml).isIdenticalToIgnoringComments(otherXml))
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}
}

Expand All @@ -189,7 +189,7 @@ void shouldThrowAssertionErrorWhenXmlIsDifferent() {

assertThatThrownBy(() ->
KiwiXmlAssert.assertThat(xml).isIdenticalToIgnoringWhitespaceAndComments(otherXml))
.isExactlyInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class);
}
}
}
Expand Down

0 comments on commit 35d55f1

Please sign in to comment.