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 05654d676fe..7a3b1e75e17 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 @@ -900,13 +900,13 @@ public interface WebTestClient { * List-specific assertions. * @param elementType the expected List element type */ - ListBodySpec expectBodyList(Class elementType); + ListBodySpec expectBodyList(Class elementType); /** * Alternative to {@link #expectBodyList(Class)} that accepts information * about a target type with generics. */ - ListBodySpec expectBodyList(ParameterizedTypeReference elementType); + ListBodySpec expectBodyList(ParameterizedTypeReference elementType); /** * Consume and decode the response body to {@code byte[]} and then apply diff --git a/spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt b/spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt index e6900204d91..24cf9c13125 100644 --- a/spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt +++ b/spring-test/src/main/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensions.kt @@ -75,7 +75,7 @@ inline fun ResponseSpec.expectBody(): BodySpec = * @author Sebastien Deleuze * @since 5.0 */ -inline fun ResponseSpec.expectBodyList(): ListBodySpec = +inline fun ResponseSpec.expectBodyList(): ListBodySpec = expectBodyList(object : ParameterizedTypeReference() {}) /** diff --git a/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt b/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt index 252ce31ca36..e7247f62c15 100644 --- a/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt +++ b/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt @@ -23,6 +23,7 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.reactivestreams.Publisher import org.springframework.core.ParameterizedTypeReference +import org.springframework.http.MediaType import org.springframework.web.reactive.function.server.router import java.util.concurrent.CompletableFuture @@ -95,6 +96,14 @@ class WebTestClientExtensionsTests { verify { responseSpec.expectBodyList(object : ParameterizedTypeReference() {}) } } + @Test + fun `ResponseSpec#expectBodyList with null value`() { + WebTestClient + .bindToRouterFunction( router { GET("/") { ok().contentType(MediaType.APPLICATION_JSON).bodyValue("[null]") } } ) + .build() + .get().uri("/").exchange().expectBodyList().hasSize(0) + } + @Test fun `ResponseSpec#returnResult with reified type parameters`() { responseSpec.returnResult()