Alberto Quario
11/22/2022, 2:29 PMshould("respond OK") {
testApplication {
application {
mockService("11111111111")
configureServing()
configureRouting()
}
client.get("/v1/foo/XXX00000000123").apply {
assertEquals(HttpStatusCode.OK, status)
}
}
}
should("respond to Unauthorized") {
testApplication {
application {
mockService("12345678")
configureServing()
configureRouting()
}
client.get("/v1/foo/XXX00000000123").apply {
assertEquals(HttpStatusCode.Unauthorized, status)
}
}
}
and the mockService mock a static builder using mockk
private fun mockService(id: String?) {
mockkObject(ReferenceClientBuilder)
val fakeService = mockk<ReferenceClient>()
coEvery { fakeService.customerId(any()) } returns id
...
coEvery { ReferenceClientBuilder.getClient(any()) } returns fakeService
}
Up to ktor 2.1.2 everything was ok, but now with 2.1.3 the second test fails cause the static mockk is just set on the first test and not updated on following ones.
Any hints? Thanks!Aleksei Tirman [JB]
11/22/2022, 3:00 PMAlberto Quario
11/22/2022, 3:30 PM