Anybody can point me to some resources which will ...
# android
w
Anybody can point me to some resources which will ease the pain to work with Mockito + Kotlin, specifically ArgumentCapture is broken after converting to Kotlin. I went through these already: https://kotlinlang.org/docs/reference/compiler-plugins.html#all-open-compiler-plugin http://hadihariri.com/2016/10/04/Mocking-Kotlin-With-Mockito/ https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
a
I use https://github.com/nhaarman/mockito-kotlin. You can check out the Wiki for information on the syntax. I've no issues with capturing arguments after switching to it.
w
@annyce thanks for the quick link, I read in third link I posted that it only works if Class has default constructor.
Copy code
Using Mockito-Kotlin
There’s a library <https://github.com/nhaarman/mockito-kotlin> which seems to address the Non-null issue. Great!! … But… that only works for parameter that have default constructor.
ArgumentCapture works now, it was just about giving it an empty list (not null) using
?:
, so that it;s not null. And asserts will fail anyhow because size and other stuff won't match from empty list.
a
Ok, so are you saying you're good now or you are still having issues?
w
Yes thanks I'm good now. Btw instead of mockito-kotlin library for Any(), I am using this 4 lines of code as suggested in the article I posted.
Copy code
private fun <T> any(): T {
    Mockito.any<T>()
    return uninitialized()
}
private fun <T> uninitialized(): T = null as T
👍 1