From 386836055562cdde7dfb8a7af4fdc33eeb5dc46c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 30 Jul 2021 07:29:59 -0500 Subject: [PATCH] Issue #6544 - More updates based on review and merge Signed-off-by: Joakim Erdfelt --- .../tests/distribution/GzipModuleTests.java | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/GzipModuleTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/GzipModuleTests.java index af1755687e3..040e79e9d6a 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/GzipModuleTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/GzipModuleTests.java @@ -16,7 +16,6 @@ package org.eclipse.jetty.tests.distribution; import java.io.File; import java.nio.file.Path; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.http.HttpHeader; @@ -68,8 +67,9 @@ public class GzipModuleTests extends AbstractJettyHomeTest startHttpClient(); ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/index.html"); - assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response)); - assertThat("Ensure that gzip is working", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), containsString("gzip")); + String responseDetails = toResponseDetails(response); + assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails); + assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), containsString("gzip")); } } } @@ -111,9 +111,10 @@ public class GzipModuleTests extends AbstractJettyHomeTest startHttpClient(); ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.webp"); - assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response)); - assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/webp")); - assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip"))); + String responseDetails = toResponseDetails(response); + assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails); + assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/webp")); + assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip"))); } } } @@ -156,30 +157,20 @@ public class GzipModuleTests extends AbstractJettyHomeTest startHttpClient(); ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.icon"); - assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response)); - assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip"))); - assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/vnd.microsoft.icon")); + String responseDetails = toResponseDetails(response); + assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails); + assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip"))); + assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/vnd.microsoft.icon")); } } } - private static class ResponseDetails implements Supplier + private static String toResponseDetails(ContentResponse response) { - private final ContentResponse response; - - public ResponseDetails(ContentResponse response) - { - this.response = response; - } - - @Override - public String get() - { - StringBuilder ret = new StringBuilder(); - ret.append(response.toString()).append(System.lineSeparator()); - ret.append(response.getHeaders().toString()).append(System.lineSeparator()); - ret.append(response.getContentAsString()).append(System.lineSeparator()); - return ret.toString(); - } + StringBuilder ret = new StringBuilder(); + ret.append(response.toString()).append(System.lineSeparator()); + ret.append(response.getHeaders().toString()).append(System.lineSeparator()); + ret.append(response.getContentAsString()).append(System.lineSeparator()); + return ret.toString(); } }