Simplify tests

This commit is contained in:
Sam Brannen
2026-01-20 17:10:07 +01:00
parent 17e02804ba
commit 5490ba94ae
6 changed files with 22 additions and 28 deletions
@@ -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);
}
@@ -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]");
}
});
}
@@ -95,13 +95,13 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT
@ParameterizedHttpServerTest
void bindToMixed(HttpServer httpServer) throws Exception {
startServer(httpServer);
startServer(httpServer);
Mono<String> result = this.webClient.get()
.uri("/mixed?foo=FOO")
.header("bar", "BAR")
.retrieve()
.bodyToMono(String.class);
Mono<String> result = this.webClient.get()
.uri("/mixed?foo=FOO")
.header("bar", "BAR")
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.expectNext("FOO:BAR")
@@ -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();
}
@@ -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
@@ -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();
}