diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index c9dce22f2a..56a41deaa1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -378,7 +378,14 @@ class DefaultWebTestClient implements WebTestClient { @Override public FluxExchangeResult returnResult(Class elementClass) { - Flux body = this.response.bodyToFlux(elementClass); + Flux body; + if (elementClass.equals(Void.class)) { + this.response.releaseBody().block(); + body = Flux.empty(); + } + else { + body = this.response.bodyToFlux(elementClass); + } return new FluxExchangeResult<>(this.exchangeResult, body); } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 6b55d52075..ed9b1ecde7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -172,7 +172,7 @@ public interface WebTestClient { // Static factory methods /** - * Use this server setup to test one `@Controller` at a time. + * Use this server setup to test one {@code @Controller} at a time. * This option loads the default configuration of * {@link org.springframework.web.reactive.config.EnableWebFlux @EnableWebFlux}. * There are builder methods to customize the Java config. The resulting @@ -229,8 +229,8 @@ public interface WebTestClient { } /** - * This server setup option allows you to connect to a running server via - * Reactor Netty. + * This server setup option allows you to connect to a live server through + * a Reactor Netty client connector. *

 	 * WebTestClient client = WebTestClient.bindToServer()
 	 *         .baseUrl("http://localhost:8080")
@@ -244,11 +244,6 @@ public interface WebTestClient {
 
 	/**
 	 * A variant of {@link #bindToServer()} with a pre-configured connector.
-	 * 

-	 * WebTestClient client = WebTestClient.bindToServer()
-	 *         .baseUrl("http://localhost:8080")
-	 *         .build();
-	 * 
* @return chained API to customize client config * @since 5.0.2 */ @@ -802,18 +797,13 @@ public interface WebTestClient { BodyContentSpec expectBody(); /** - * Exit the chained API and consume the response body externally. This - * is useful for testing infinite streams (e.g. SSE) where you need to - * to assert decoded objects as they come and then cancel at some point - * when test objectives are met. Consider using {@code StepVerifier} - * from {@literal "reactor-test"} to assert the {@code Flux} stream - * of decoded objects. + * Exit the chained flow in order to consume the response body + * externally, e.g. via {@link reactor.test.StepVerifier}. * - *

Note: Do not use this option for cases where there - * is no content (e.g. 204, 4xx) or you're not interested in the content. - * For such cases you can use {@code expectBody().isEmpty()} or - * {@code expectBody(Void.class)} which ensures that resources are - * released regardless of whether the response has content or not. + *

Note that when {@code Void.class} is passed in, the response body + * is consumed and released. If no content is expected, then consider + * using {@code .expectBody().isEmpty()} instead which asserts that + * there is no content. */ FluxExchangeResult returnResult(Class elementClass);