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 d7277f9d36f..a939dba9e47 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 @@ -19,7 +19,6 @@ package org.springframework.test.web.reactive.server import kotlinx.coroutines.flow.Flow import org.reactivestreams.Publisher import org.springframework.core.ParameterizedTypeReference -import org.springframework.test.util.AssertionErrors.assertEquals import org.springframework.test.web.reactive.server.WebTestClient.* /** @@ -59,53 +58,17 @@ inline fun RequestBodySpec.body(flow: Flow): RequestHeaders body(flow, object : ParameterizedTypeReference() {}) /** - * Extension for [ResponseSpec.expectBody] providing an `expectBody()` variant and - * a workaround for [KT-5464](https://youtrack.jetbrains.com/issue/KT-5464) which - * prevents to use `WebTestClient.BodySpec` in Kotlin. + * Extension for [ResponseSpec.expectBody] providing an `expectBody()` variant + * leveraging Kotlin reified type parameters. This extension is not subject ot type + * erasure and retains actual generic type arguments. * * @author Sebastien Deleuze + * @author Arjen Poutsma * @since 5.0 */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") -inline fun ResponseSpec.expectBody(): KotlinBodySpec = - expectBody(object : ParameterizedTypeReference() {}).returnResult().let { - object : KotlinBodySpec { - - override fun isEqualTo(expected: B): KotlinBodySpec = it - .assertWithDiagnostics { assertEquals("Response body", expected, it.responseBody) } - .let { this } - - override fun consumeWith(consumer: (EntityExchangeResult) -> Unit): KotlinBodySpec = - it.assertWithDiagnostics { consumer.invoke(it) }.let { this } - - override fun returnResult(): EntityExchangeResult = it - } - } - -/** - * Kotlin compliant `WebTestClient.BodySpec` for expectations on the response body decoded - * to a single Object, see [KT-5464](https://youtrack.jetbrains.com/issue/KT-5464) for - * more details. - * @since 5.0.6 - */ -interface KotlinBodySpec { - - /** - * Assert the extracted body is equal to the given value. - */ - fun isEqualTo(expected: B): KotlinBodySpec - - /** - * Assert the exchange result with the given consumer. - */ - fun consumeWith(consumer: (EntityExchangeResult) -> Unit): KotlinBodySpec - - /** - * Exit the chained API and return an `ExchangeResult` with the - * decoded response content. - */ - fun returnResult(): EntityExchangeResult -} +inline fun ResponseSpec.expectBody(): BodySpec = + expectBody(object : ParameterizedTypeReference() {}) /** * Extension for [ResponseSpec.expectBodyList] providing a `expectBodyList()` variant.