From 5d5f9aceca7e953fa8c783e9730478205f7d3e2a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 6 Sep 2019 16:03:36 +0200 Subject: [PATCH] Avoid accidental usage of JUnit 4 assumptions This commit also avoids starting a server if an assumption fails. --- .../reactive/AbstractHttpHandlerIntegrationTests.java | 6 ++++-- .../http/server/reactive/ZeroCopyIntegrationTests.java | 8 ++++---- .../web/client/RestTemplateIntegrationTests.java | 8 ++++---- .../result/method/annotation/SseIntegrationTests.java | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java index 830e9ad38b..88f47e37e6 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java @@ -90,8 +90,10 @@ public abstract class AbstractHttpHandlerIntegrationTests { @AfterEach void stopServer() { - this.server.stop(); - this.port = 0; + if (this.server != null) { + this.server.stop(); + this.port = 0; + } } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index f2db7fe7ef..ea045b8e86 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -33,7 +33,7 @@ import org.springframework.http.server.reactive.bootstrap.UndertowHttpServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * @author Arjen Poutsma @@ -51,10 +51,10 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest @ParameterizedHttpServerTest public void zeroCopy(HttpServer httpServer) throws Exception { - startServer(httpServer); + assumeTrue(httpServer instanceof ReactorHttpServer || httpServer instanceof UndertowHttpServer, + "Zero-copy only does not support servlet"); - // Zero-copy only does not support servlet - assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer); + startServer(httpServer); URI url = new URI("http://localhost:" + port); RequestEntity request = RequestEntity.get(url).build(); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index 7e64c6653c..d74c4c7677 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -57,7 +57,7 @@ import org.springframework.util.MultiValueMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.MediaType.MULTIPART_MIXED; @@ -224,10 +224,10 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { @ParameterizedRestTemplateTest void patchForObject(ClientHttpRequestFactory clientHttpRequestFactory) throws Exception { - setUpClient(clientHttpRequestFactory); + assumeFalse(clientHttpRequestFactory instanceof SimpleClientHttpRequestFactory, + "JDK client does not support the PATCH method"); - // JDK client does not support the PATCH method - assumeFalse(this.clientHttpRequestFactory instanceof SimpleClientHttpRequestFactory); + setUpClient(clientHttpRequestFactory); String s = template.patchForObject(baseUrl + "/{method}", helloWorld, String.class, "patch"); assertThat(s).as("Invalid content").isEqualTo(helloWorld); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 8e7019904f..9d545d6ab1 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -141,9 +141,9 @@ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedSseTest void sseAsEvent(HttpServer httpServer, ClientHttpConnector connector) throws Exception { - startServer(httpServer, connector); + assumeTrue(httpServer instanceof JettyHttpServer); - assumeTrue(super.server instanceof JettyHttpServer); + startServer(httpServer, connector); Flux> result = this.webClient.get() .uri("/event") @@ -190,9 +190,9 @@ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedSseTest // SPR-16494 @Disabled // https://github.com/reactor/reactor-netty/issues/283 void serverDetectsClientDisconnect(HttpServer httpServer, ClientHttpConnector connector) throws Exception { - startServer(httpServer, connector); + assumeTrue(httpServer instanceof ReactorHttpServer); - assumeTrue(super.server instanceof ReactorHttpServer); + startServer(httpServer, connector); Flux result = this.webClient.get() .uri("/infinite")