Skip to content

Commit

Permalink
Fixed JRE11 only test cases with broken Mockito verifications due to …
Browse files Browse the repository at this point in the history
…HTTP client call signature changing
  • Loading branch information
tomakehurst committed Jul 25, 2023
1 parent e21394e commit 5ec352e
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
import java.util.List;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

@DisabledForJreRange(
Expand Down Expand Up @@ -167,7 +169,7 @@ void doesNotAddEntityIfEmptyBodyReverseProxy() throws IOException {
ServeEvent serveEvent = reverseProxyServeEvent("/proxied");

proxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null), ArgumentMatchers.any(HttpClientResponseHandler.class));
}

@Test
Expand All @@ -178,7 +180,7 @@ void doesNotAddEntityIfEmptyBodyForwardProxy() throws IOException {
ServeEvent serveEvent = forwardProxyServeEvent("/proxied");

proxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null), ArgumentMatchers.any(HttpClientResponseHandler.class));
}

@Test
Expand All @@ -190,7 +192,7 @@ void addsEntityIfNotEmptyBodyReverseProxy() throws IOException {
serveEvent("/proxied", false, "Text body".getBytes(StandardCharsets.UTF_8));

proxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null), ArgumentMatchers.any(HttpClientResponseHandler.class));
}

@Test
Expand All @@ -202,7 +204,7 @@ void addsEntityIfNotEmptyBodyForwardProxy() throws IOException {
serveEvent("/proxied", true, "Text body".getBytes(StandardCharsets.UTF_8));

proxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null), ArgumentMatchers.any(HttpClientResponseHandler.class));
}

@Test
Expand All @@ -223,7 +225,7 @@ void addsEmptyEntityIfEmptyBodyForwardProxyPOST() throws IOException {
new HttpHeaders(new HttpHeader("Content-Length", "0")));

trustAllProxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null), ArgumentMatchers.any(HttpClientResponseHandler.class));
List<LoggedRequest> requests =
origin.findAll(postRequestedFor(urlPathMatching("/proxied/empty-post")));
Assertions.assertThat(requests)
Expand All @@ -250,7 +252,7 @@ void addsEmptyEntityIfEmptyBodyForwardProxyGET() throws IOException {
new HttpHeaders(new HttpHeader("Content-Length", "0")));

trustAllProxyResponseRenderer.render(serveEvent);
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));
Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null), ArgumentMatchers.any(HttpClientResponseHandler.class));
List<LoggedRequest> requests =
origin.findAll(getRequestedFor(urlPathMatching("/proxied/empty-get")));
Assertions.assertThat(requests)
Expand Down

0 comments on commit 5ec352e

Please sign in to comment.