@@ -19,7 +19,6 @@ package org.springframework.test.web.reactive.server
19
19
import kotlinx.coroutines.flow.Flow
20
20
import org.reactivestreams.Publisher
21
21
import org.springframework.core.ParameterizedTypeReference
22
- import org.springframework.test.util.AssertionErrors.assertEquals
23
22
import org.springframework.test.web.reactive.server.WebTestClient.*
24
23
25
24
/* *
@@ -59,53 +58,17 @@ inline fun <reified T : Any> RequestBodySpec.body(flow: Flow<T>): RequestHeaders
59
58
body(flow, object : ParameterizedTypeReference <T >() {})
60
59
61
60
/* *
62
- * Extension for [ResponseSpec.expectBody] providing an `expectBody<Foo>()` variant and
63
- * a workaround for [KT-5464](https://youtrack.jetbrains.com/issue/KT-5464) which
64
- * prevents to use `WebTestClient.BodySpec` in Kotlin .
61
+ * Extension for [ResponseSpec.expectBody] providing an `expectBody<Foo>()` variant
62
+ * leveraging Kotlin reified type parameters. This extension is not subject ot type
63
+ * erasure and retains actual generic type arguments .
65
64
*
66
65
* @author Sebastien Deleuze
66
+ * @author Arjen Poutsma
67
67
* @since 5.0
68
68
*/
69
69
@Suppress(" EXTENSION_SHADOWED_BY_MEMBER" )
70
- inline fun <reified B : Any > ResponseSpec.expectBody (): KotlinBodySpec <B > =
71
- expectBody(object : ParameterizedTypeReference <B >() {}).returnResult().let {
72
- object : KotlinBodySpec <B > {
73
-
74
- override fun isEqualTo (expected : B ): KotlinBodySpec <B > = it
75
- .assertWithDiagnostics { assertEquals(" Response body" , expected, it.responseBody) }
76
- .let { this }
77
-
78
- override fun consumeWith (consumer : (EntityExchangeResult <B >) -> Unit ): KotlinBodySpec <B > =
79
- it.assertWithDiagnostics { consumer.invoke(it) }.let { this }
80
-
81
- override fun returnResult (): EntityExchangeResult <B > = it
82
- }
83
- }
84
-
85
- /* *
86
- * Kotlin compliant `WebTestClient.BodySpec` for expectations on the response body decoded
87
- * to a single Object, see [KT-5464](https://youtrack.jetbrains.com/issue/KT-5464) for
88
- * more details.
89
- * @since 5.0.6
90
- */
91
- interface KotlinBodySpec <B > {
92
-
93
- /* *
94
- * Assert the extracted body is equal to the given value.
95
- */
96
- fun isEqualTo (expected : B ): KotlinBodySpec <B >
97
-
98
- /* *
99
- * Assert the exchange result with the given consumer.
100
- */
101
- fun consumeWith (consumer : (EntityExchangeResult <B >) -> Unit ): KotlinBodySpec <B >
102
-
103
- /* *
104
- * Exit the chained API and return an `ExchangeResult` with the
105
- * decoded response content.
106
- */
107
- fun returnResult (): EntityExchangeResult <B >
108
- }
70
+ inline fun <reified B : Any > ResponseSpec.expectBody (): BodySpec <B , * > =
71
+ expectBody(object : ParameterizedTypeReference <B >() {})
109
72
110
73
/* *
111
74
* Extension for [ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant.
0 commit comments