https://kotlinlang.org logo
#android
Title
# android
w

waqas

10/23/2017, 2:44 PM
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

annyce

10/23/2017, 2:45 PM
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

waqas

10/23/2017, 2:49 PM
@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

annyce

10/23/2017, 3:03 PM
Ok, so are you saying you're good now or you are still having issues?
w

waqas

10/23/2017, 3:05 PM
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