Hello, i am getting error with args and i dont kno...
# mockk
s
Hello, i am getting error with args and i dont know what is the solution.
Copy code
answers {
    thirdArg<(String) -> Unit>().invoke("text")
}
i had to change it to
Copy code
answers {
    thirdArg<(String) -> Boolean>().invoke("text")
}
but i am getting the next solution
Unit cannot be cast to java.lang.Boolean
any idea? thanks
m
what’s the signature of the function you are mocking? does it have any overloads?
s
Copy code
fun doSomething(
    data1: Int,
    data2: String,
    onSuccess: (String) -> Unit,
    onError: (Throwable) -> Unit
): Boolean
every { manager.doSomething( data1, data2, captureLambda(), captureLambda() ) } answers { thirdArg<(String) -> Boolean>().invoke("text") }
m
what error are you getting if you mock it with
thirdArg<(String) -> Unit>
?
s
Copy code
Type mismatch.
Required:
Boolean
Found:
Unit
if i change it with Boolean compile
but that is different from signature
m
that’s pretty weird indeed
s
😅
e
what happens if you write
Copy code
answers {
    thirdArg<(String) -> Unit>().invoke("text")
    Unit
}
s
it works with true, not with Unit becuase the signature of the method return
Boolean
thanks
e
ah, of course that's what I should have written
s
thank you so much
m
ah, that’s right, thanks a lot!