https://kotlinlang.org logo
Title
s

Sergio Crespo Toubes

04/13/2021, 10:50 AM
Hello, i am getting error with args and i dont know what is the solution.
answers {
    thirdArg<(String) -> Unit>().invoke("text")
}
i had to change it to
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

Mattia Tommasone

04/13/2021, 10:52 AM
what’s the signature of the function you are mocking? does it have any overloads?
s

Sergio Crespo Toubes

04/13/2021, 10:55 AM
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

Mattia Tommasone

04/13/2021, 10:58 AM
what error are you getting if you mock it with
thirdArg<(String) -> Unit>
?
s

Sergio Crespo Toubes

04/13/2021, 10:59 AM
Type mismatch.
Required:
Boolean
Found:
Unit
if i change it with Boolean compile
but that is different from signature
m

Mattia Tommasone

04/13/2021, 11:02 AM
that’s pretty weird indeed
s

Sergio Crespo Toubes

04/13/2021, 11:03 AM
😅
e

ephemient

04/13/2021, 4:16 PM
what happens if you write
answers {
    thirdArg<(String) -> Unit>().invoke("text")
    Unit
}
s

Sergio Crespo Toubes

04/13/2021, 4:20 PM
it works with true, not with Unit becuase the signature of the method return
Boolean
thanks
e

ephemient

04/13/2021, 4:29 PM
ah, of course that's what I should have written
s

Sergio Crespo Toubes

04/13/2021, 4:30 PM
thank you so much
m

Mattia Tommasone

04/13/2021, 4:30 PM
ah, that’s right, thanks a lot!