Remove bodyWithType extension from WebTestClient

Since there is no more clash with the new bodyValue
method name.

See gh-23523
This commit is contained in:
Sebastien Deleuze
2019-08-31 11:40:44 +02:00
parent 3dfd0a24dc
commit 57f0c2b7df
2 changed files with 10 additions and 23 deletions

View File

@@ -30,13 +30,12 @@ import org.springframework.test.web.reactive.server.WebTestClient.*
* @author Sebastien Deleuze
* @since 5.0
*/
@Deprecated("Use 'bodyWithType' instead.", replaceWith = ReplaceWith("bodyWithType(publisher)"))
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*>
= body(publisher, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [RequestBodySpec.body] providing a `bodyWithType<T>(Any)` variant
* Extension for [RequestBodySpec.body] providing a `body<T>(Any)` variant
* leveraging Kotlin reified type parameters. This extension is not subject to type
* erasure and retains actual generic type arguments.
* @param producer the producer to write to the request. This must be a
@@ -46,23 +45,11 @@ inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> RequestBodySpec.bodyWithType(producer: Any): RequestHeadersSpec<*>
inline fun <reified T : Any> RequestBodySpec.body(producer: Any): RequestHeadersSpec<*>
= body(producer, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [RequestBodySpec.body] providing a `bodyWithType(Publisher<T>)` variant
* leveraging Kotlin reified type parameters. This extension is not subject to type
* erasure and retains actual generic type arguments.
* @param publisher the [Publisher] to write to the request
* @param <T> the type of the elements contained in the publisher
* @author Sebastien Deleuze
* @since 5.2
*/
inline fun <reified T : Any> RequestBodySpec.bodyWithType(publisher: Publisher<T>): RequestHeadersSpec<*> =
body(publisher, object : ParameterizedTypeReference<T>() {})
/**
* Extension for [RequestBodySpec.body] providing a `bodyWithType(Flow<T>)` variant
* Extension for [RequestBodySpec.body] providing a `body(Flow<T>)` variant
* leveraging Kotlin reified type parameters. This extension is not subject to type
* erasure and retains actual generic type arguments.
* @param flow the [Flow] to write to the request
@@ -71,7 +58,7 @@ inline fun <reified T : Any> RequestBodySpec.bodyWithType(publisher: Publisher<T
* @since 5.2
*/
@ExperimentalCoroutinesApi
inline fun <reified T : Any> RequestBodySpec.bodyWithType(flow: Flow<T>): RequestHeadersSpec<*> =
inline fun <reified T : Any> RequestBodySpec.body(flow: Flow<T>): RequestHeadersSpec<*> =
body(flow, object : ParameterizedTypeReference<T>() {})
/**

View File

@@ -40,24 +40,24 @@ class WebTestClientExtensionsTests {
@Test
fun `RequestBodySpec#bodyWithType with Publisher and reified type parameters`() {
fun `RequestBodySpec#body with Publisher and reified type parameters`() {
val body = mockk<Publisher<Foo>>()
requestBodySpec.bodyWithType(body)
requestBodySpec.body(body)
verify { requestBodySpec.body(body, object : ParameterizedTypeReference<Foo>() {}) }
}
@Test
@ExperimentalCoroutinesApi
fun `RequestBodySpec#bodyWithType with Flow and reified type parameters`() {
fun `RequestBodySpec#body with Flow and reified type parameters`() {
val body = mockk<Flow<Foo>>()
requestBodySpec.bodyWithType(body)
requestBodySpec.body(body)
verify { requestBodySpec.body(body, object : ParameterizedTypeReference<Foo>() {}) }
}
@Test
fun `RequestBodySpec#bodyWithType with CompletableFuture and reified type parameters`() {
fun `RequestBodySpec#body with CompletableFuture and reified type parameters`() {
val body = mockk<CompletableFuture<Foo>>()
requestBodySpec.bodyWithType<Foo>(body)
requestBodySpec.body<Foo>(body)
verify { requestBodySpec.body(body, object : ParameterizedTypeReference<Foo>() {}) }
}