Refine WebFlux Coroutines API

This commit provides both nullable and non-nullable variants for
awaitBody, makes awaitPrincipal return type nullable and rename
awaitResponse to awaitExchange for better consistency with Java API.

See gh-19975
This commit is contained in:
Sebastien Deleuze
2019-03-28 10:17:12 +01:00
parent 811f315440
commit c5c4ac164b
6 changed files with 39 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpStatus
@@ -69,6 +70,15 @@ class ClientResponseExtensionsTests {
}
}
@Test
fun awaitBodyOrNull() {
val response = mockk<ClientResponse>()
every { response.bodyToMono<String>() } returns Mono.empty()
runBlocking {
assertNull(response.awaitBodyOrNull<String>())
}
}
@Test
fun awaitEntity() {
val response = mockk<ClientResponse>()

View File

@@ -58,11 +58,11 @@ class WebClientExtensionsTests {
}
@Test
fun awaitResponse() {
fun awaitExchange() {
val response = mockk<ClientResponse>()
every { requestBodySpec.exchange() } returns Mono.just(response)
runBlocking {
assertEquals(response, requestBodySpec.awaitResponse())
assertEquals(response, requestBodySpec.awaitExchange())
}
}

View File

@@ -61,10 +61,10 @@ class ServerRequestExtensionsTests {
}
@Test
fun awaitBodyNull() {
fun awaitBodyOrNull() {
every { request.bodyToMono<String>() } returns Mono.empty()
runBlocking {
assertNull(request.awaitBody<String>())
assertNull(request.awaitBodyOrNull<String>())
}
}