hi guys, I have a function that looks like below `...
# mockk
t
hi guys, I have a function that looks like below
Copy code
interface StorageService {
    fun upload(inputStream: InputStream): String
}

class LocalStorageService: StorageService {

    override upload(inputStream: InputStream): String {
        //Some uploading logic
    }
}

I want to verify that the function was called with the following code

verify {
    storageService.putFile(
        inputStream = withArg { assertEquals("Hello, World!".toByteArray(),it.readBytes())}
    )
}
and I got an error, that my inputStreams byteArray is empty, can anyone help me please
m
i think what you want to do can be achieved by doing
Copy code
verify {
    storageService.putFile(match {
        it.readBytes() == "Hello, World!".toByteArray()
    })
}
or, in an even clearer way, by using a slot
Copy code
val inputStreamSlot = slot<InputStream>()
verify {
    storageService.putFile(capture(inputStreamSlot))
}

assertEquals("Hello, World!".toByteArray(), inputStreamSlot.captured.readBytes())
t
Thank you for an answer, but both of the variants are not working. In the first one tells that the bytes of
Hello, World!
and bytes of an inputStream are not equal. Second one(with the
slot
) tells that the
inputStreamSlot.captured.readBytes
is empty
When I am using mock
every { storageService.putFile(match{}) }
matcher is working fine, however, in verify section, it is not working. Strange
finally, I do something like
verify {storageService.upload(inputStream = matcher{it.reset and then it.readBytes() contentEquals "Hello, wordl".toByteArray()}
What do you think is it okay variant?