Oleg Shuliak
11/02/2023, 1:32 PMMockk
library.
my call has awaitBody<>
withContext(requestContext.coroutineContext) {
monolithClient.get("$PATH?company_id=${requestContext.getCompanyId()}")
.retrieve()
.onStatus(HttpStatus::isError) { response ->
return@onStatus response.bodyToMono(String::class.java).map {
log(ERROR_MESSAGE, response.statusCode(), it)
RuntimeException("$ERROR_MESSAGE: $it")
}
}
.awaitBody<DepartmentResponse>()
}
Trying to mock that response with the setup like this:
val client: MonolithClient = mockk()
val requestSpec: WebClient.RequestHeadersSpec<*> = mockk()
val responseSpec: WebClient.ResponseSpec = mockk()
val expectedResponse = //some data
every { client.get(capture(pathSlot)) } returns requestSpec
every { requestSpec.retrieve() } returns responseSpec
coEvery {
responseSpec.onStatus(any(), any()).awaitBody<DepartmentResponse>()
} returns expectedResponse
leads the test to freeze and the coroutine is never finishing on awaitBody
changing the implementation of the client to use bodyToMono
helps with the test, but I would really like to understand how to manage mocking calls with awaitBody
Any tips are appreciated 🙏Viorel Ștefan Alexandrescu
11/08/2023, 10:01 AMOleg Shuliak
11/08/2023, 1:53 PM@Mockk
annotation - still the same