Hi there. What is the preferred way of mocking App...
# ktor
j
Hi there. What is the preferred way of mocking ApplicationCall? I don’t want to create whole
testApplication { … }
, but I have a method that is simply
Copy code
suspend fun readPartsContents(call: ApplicationCall): List<UploadedContent> = call
    .receiveMultipart()
    .readAllParts()
    .flatMap(::processPart)
and I’d like to mock that
call
in my unit test. But I can’t since
.receiveMultipart()
is unmockable extension function…
ok nvm, apparently it’s possible to mock extension functions as well, using mockkStatic:
Copy code
val call: ApplicationCall = mockk()
val multiPartData: MultiPartData = mockk()
val input: Input = mockk()
val zipPart = PartData.FileItem({ input }, { input.release() }, partHeaders(Application.Zip, "zip/random.zip"))

mockkStatic(ApplicationCall::receiveMultipart)
mockkStatic(MultiPartData::readAllParts)
mockkStatic(Input::asStream)

coEvery { call.receiveMultipart() } returns multiPartData
coEvery { multiPartData.readAllParts() } returns listOf(zipPart)
every { input.asStream() } returns randomZip.inputStream()
justRun { input.release() }
130 Views