Hey folks I wanted to know how can we capture lamda arguments using argument captor, I am able to do when lamda values contains single value ,but how to cature more than one
Single argument
api.doSomething(function1:(value:String)->Unit){
//doSomeStruff
function1.invoke("SOME_VALUE")
}
Case 1
val mockfunction = mock<((value: String) -> Unit)>()
api.doSomething(mockfuntion)
val captor = argumentCaptor<String>()
verify(mockfunction).invoke(captor.capture)
Case 2:
Can you guys guide me how can we test for than one argument
api.doSomething(function1:(title:String,message:String)->Unit){
//doSomeStruff
function1.invoke("SOME_VALUE","SOME_VALUE")
}
val mockFunction = mock<(title: String, message: String) -> Unit>()
val captor = argumentCaptor<((title: String, message: String) -> Unit)>()
^^ Not sure is this the correct way to do for the above or how to verify the arguments
o
oleksiyp
11/27/2018, 11:14 AM
If something is not working tell me that 😄
a
am
11/27/2018, 11:14 AM
???
o
oleksiyp
11/27/2018, 11:15 AM
Im mockk author
a
am
11/27/2018, 11:20 AM
ok let me try to elaborate if I have only argument passed in lambda as stated in case 1, when I call captor.invoke with the appropriate class i.e the string value that needs to capture
But in case 2 I try to capture the arguments using specified captor but when
capture()
is invoked it gets me a function object, this is wrong ,but I do not know how to capture the multiple arguments,thats passed, for actual code it does pass strings