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

EXPERIMENTAL: Update to use alpha version of mockwebserver3-junit5 #500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<!-- Versions for provided dependencies -->
<jakarta.persistence-api.version>3.2.0</jakarta.persistence-api.version>

<!-- This version must match the okhttp version in kiwi-bom. TODO: Consider adding this to kiwi-bom. -->
<ohttp3.mockwebserver.version>4.12.0</ohttp3.mockwebserver.version>
<!-- TODO: This is an ALPHA version!!! This is an EXPERIMENTAL branch only!!! Consider adding this to kiwi-bom. -->
<okhttp3.mockwebserver3.version>5.0.0-alpha.14</okhttp3.mockwebserver3.version>

<xmlunit.version>2.10.0</xmlunit.version>

Expand All @@ -55,6 +55,14 @@
<scope>import</scope>
</dependency>

<!-- Override version in kiwi-bom to ensure okhttp artifacts have same version
TODO: Remove once okhttp and mockwebserver3 versions are in sync -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.mockwebserver3.version}</version>
</dependency>

<dependency>
<groupId>org.kiwiproject</groupId>
<artifactId>kiwi</artifactId>
Expand Down Expand Up @@ -195,8 +203,8 @@

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${ohttp3.mockwebserver.version}</version>
<artifactId>mockwebserver3-junit5</artifactId>
<version>${okhttp3.mockwebserver3.version}</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import mockwebserver3.MockWebServer;
import mockwebserver3.RecordedRequest;
import org.kiwiproject.base.UncheckedInterruptedException;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import mockwebserver3.MockResponse;
import mockwebserver3.MockWebServer;
import mockwebserver3.RecordedRequest;
import mockwebserver3.junit5.internal.MockWebServerExtension;
import org.apache.commons.lang3.RandomStringUtils;
import org.awaitility.Durations;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.kiwiproject.base.UncheckedInterruptedException;
import org.kiwiproject.io.KiwiIO;

import java.io.IOException;
import java.net.URI;
Expand All @@ -40,25 +40,22 @@
@DisplayName("RecordedRequests")
class RecordedRequestsTest {

@RegisterExtension
static final MockWebServerExtension MOCK_WEB_SERVER_EXTENSION = new MockWebServerExtension();

private MockWebServer server;

@BeforeEach
void setUp() throws IOException {
server = new MockWebServer();
server.start();
}

@AfterEach
void tearDown() {
KiwiIO.closeQuietly(server);
void setUp(MockWebServer server) {
this.server = server;
}

@Nested
class TakeRequiredRequest {

@Test
void shouldReturnTheAvailableRequest() {
server.enqueue(new MockResponse().setResponseCode(200));
server.enqueue(new MockResponse(200));

var path = randomPath();
makeRequest(path);
Expand All @@ -81,7 +78,7 @@ class TakeRequestOrEmpty {

@Test
void shouldReturnTheAvailableRequest() {
server.enqueue(new MockResponse().setResponseCode(202));
server.enqueue(new MockResponse(202));

var path = randomPath();
makeRequest(path);
Expand Down Expand Up @@ -109,7 +106,7 @@ void shouldPass_WhenThereIsNoRequestAvailable() {

@Test
void shouldFail_WhenAnyRequestIsAvailable() {
server.enqueue(new MockResponse().setResponseCode(202));
server.enqueue(new MockResponse(202));

var path = randomPath();
makeRequest(path);
Expand All @@ -126,7 +123,7 @@ class TakeRequestOrNull {

@Test
void shouldReturnTheAvailableRequest() {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(new MockResponse(204));

var path = randomPath();
makeRequest(path);
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/org/kiwiproject/test/xmlunit/KiwiXmlAssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ void shouldAcceptTestNameAsString() {
var xml = fixture("KiwiXmlAssertTest/alice-smith.xml");
var otherXml = fixture("KiwiXmlAssertTest/alice-jones.xml");

// TODO: Should we revert this to use 'isExactlyInstanceOf' now that JUnit 4
// is no longer present. See the "Gory Details" in the following PR for why
// that matters: https://github.com/kiwiproject/kiwi-test/pull/499
// For now, they have been changed to verify the tests pass.
assertThatThrownBy(() ->
KiwiXmlAssert.assertThat(xml)
.withTestName("custom-test-name")
.and(otherXml)
.areIdentical())
.isInstanceOf(AssertionError.class);
.isExactlyInstanceOf(AssertionError.class);
}

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

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

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

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

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

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

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

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

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