Anyone can please help with Mockito? I have a meth...
# getting-started
d
Anyone can please help with Mockito? I have a method in Kotlin that expects a lambda function and I try to mock it for any arguemnt, how do you do it?
j
1. mockito and kotlin don't go well together. mockito matchers return null which plays havoc with koltins non-nullable type. I recommend mockK instead 2. Be liberal with the stubbing of the method. Let the stub work for any lambda. If you want to verify that the right lambda was passed in, you can do a verifcation with argumentCaptor and test the captured argument for correctness
g
1. I suppose it's true if you don't use Mockito-Kotlin. Did you try with that lib @Jacob? Didn't experience issue while working with lambda, but today I'd prefer a SAM (functionnal) interface instead, so that the signature makes more sense (ex:
()->String
can become
UserIdProvider
,
UuidGenerator
...). Maybe another workaround for your issue?