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:
@@ -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>()
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user