Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RecordedRequests testing utility class #499

Merged
merged 5 commits into from
Jun 20, 2024

Conversation

sleberknight
Copy link
Member

@sleberknight sleberknight commented Jun 19, 2024

  • Add test utility class for getting RecordedRequests from an OkHttp MockWebServer.
  • Because XmlUnit does some shenanigans when JUnit 4 is in the class path, several
    tests in KiwiXmlAssertTest started failing, because they were getting a JUnit 4
    ComparisonFailure (which is a subclass of AssertionError). So, I changed the assertions
    to only check that an instance of AssertionError was thrown. See below for the Gory Details.

Gory Details:

okhttp3.mockwebserver version 4.12.0 depends on JUnit 4 (and
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.

Closes #492

Add test utility class for getting RecordedRequests from an OkHttp MockWebServer.

Closes #492
@sleberknight sleberknight requested a review from dsingley June 19, 2024 19:51
@sleberknight sleberknight marked this pull request as draft June 19, 2024 20:00
…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.
@sleberknight sleberknight marked this pull request as ready for review June 20, 2024 14:10
Copy link

@sleberknight sleberknight merged commit 96b785a into main Jun 20, 2024
5 checks passed
@sleberknight sleberknight deleted the 492-add-RecordedRequests-test-utils branch June 20, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test utility class for getting RecordedRequests from an OkHttp MockWebServer
2 participants