From 5490ba94aec14aba13f526e62664b3a3a6ec8e21 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Tue, 20 Jan 2026 17:10:07 +0100 Subject: [PATCH] Simplify tests --- .../web/client/RestClientIntegrationTests.java | 6 ++++-- .../web/client/RestTemplateIntegrationTests.java | 6 ++++-- .../server/BindingFunctionIntegrationTests.java | 12 ++++++------ .../server/DispatcherHandlerIntegrationTests.java | 11 +++-------- .../annotation/JacksonStreamingIntegrationTests.java | 10 +++------- .../MultipartWebClientIntegrationTests.java | 5 ++--- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java index 8d2192fb4d9..8ed7f76d337 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java @@ -406,8 +406,10 @@ class RestClientIntegrationTests { } catch (HttpServerErrorException ex) { assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assumeFalse(requestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); - assertThat(ex.getStatusText()).isEqualTo("Server Error"); + // JDK HttpClient does not expose status text + if (!(requestFactory instanceof JdkClientHttpRequestFactory)) { + assertThat(ex.getStatusText()).isEqualTo("Server Error"); + } assertThat(ex.getResponseHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage); } 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 1a0a63fb14c..82d4ea0ed03 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 @@ -248,8 +248,10 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { assertThat(ex.getStatusText()).isNotNull(); assertThat(ex.getResponseBodyAsString()).isNotNull(); assertThat(ex.getMessage()).containsSubsequence("404", "on GET request for \"" + url + "\": [no body]"); - assumeFalse(clientHttpRequestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); - assertThat(ex.getMessage()).isEqualTo("404 Client Error on GET request for \"" + url + "\": [no body]"); + // JDK HttpClient does not expose status text + if (!(clientHttpRequestFactory instanceof JdkClientHttpRequestFactory)) { + assertThat(ex.getMessage()).isEqualTo("404 Client Error on GET request for \"" + url + "\": [no body]"); + } }); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java index 2b28853c1d6..52d9369081a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java @@ -95,13 +95,13 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT @ParameterizedHttpServerTest void bindToMixed(HttpServer httpServer) throws Exception { - startServer(httpServer); + startServer(httpServer); - Mono result = this.webClient.get() - .uri("/mixed?foo=FOO") - .header("bar", "BAR") - .retrieve() - .bodyToMono(String.class); + Mono result = this.webClient.get() + .uri("/mixed?foo=FOO") + .header("bar", "BAR") + .retrieve() + .bodyToMono(String.class); StepVerifier.create(result) .expectNext("FOO:BAR") diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java index 59e724d56ba..e926e85169a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java @@ -24,6 +24,7 @@ import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -61,17 +62,11 @@ class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe private final RestTemplate restTemplate = new RestTemplate(); - private AnnotationConfigApplicationContext wac; - @Override protected HttpHandler createHttpHandler() { - this.wac = new AnnotationConfigApplicationContext(); - this.wac.register(TestConfiguration.class); - this.wac.refresh(); - - DispatcherHandler webHandler = new DispatcherHandler(); - webHandler.setApplicationContext(this.wac); + ApplicationContext wac = new AnnotationConfigApplicationContext(TestConfiguration.class); + DispatcherHandler webHandler = new DispatcherHandler(wac); return WebHttpHandlerBuilder.webHandler(webHandler).build(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java index b614c54b519..4dcb8971c7b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java @@ -23,6 +23,7 @@ import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -46,18 +47,13 @@ import static org.springframework.http.MediaType.APPLICATION_NDJSON_VALUE; */ class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private AnnotationConfigApplicationContext wac; - private WebClient webClient; @Override protected HttpHandler createHttpHandler() { - this.wac = new AnnotationConfigApplicationContext(); - this.wac.register(TestConfiguration.class); - this.wac.refresh(); - - return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build(); + ApplicationContext wac = new AnnotationConfigApplicationContext(TestConfiguration.class); + return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); } @Override diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java index 580f7c58d39..9d36639253a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java @@ -30,6 +30,7 @@ import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.test.StepVerifier; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -70,9 +71,7 @@ class MultipartWebClientIntegrationTests extends AbstractHttpHandlerIntegrationT @Override protected HttpHandler createHttpHandler() { - AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); - wac.register(TestConfiguration.class); - wac.refresh(); + ApplicationContext wac = new AnnotationConfigApplicationContext(TestConfiguration.class); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); }