I've recently started using Kotlin and am loving it so far. I've however had to use some workarounds for Mockito matchers, since Kotlin doesn't like null -- a great thing IMO. See http://stackoverflow.com/q/30305217
There is a library out there called MockitoKotlin that provides matchers that do work with Kotlin, but I'd rather use Mockito directly since that way I can have access to the latest features and patches by official Mockito.
What do you guys think? Is this a reasonable ask? I know Kotlin isn't Java, but it is gaining popularity. :)
I think this usecase can be safely supported with the new lambda when syntax and implementation. Will try it out!
@TimvdLippe Do you think it's a lot of work to support it? What do you envision this snippet would look like with the lambda when syntax?
when(mockGreeter.welcome(eq("John"))).thenReturn("Welcome, John!");
@ihanjo There is an open proposal PR at #742 . The syntax I imagine will be
when(mockGreeter::welcome).invokedWith(eq("John")).thenReturn("Welcome, John!");
Note this is typesafe and Kotlin-friendly because passing the matcher is decoupled from the method invocation.
I'm not sure this should be part of mockito yet. As matchers will create new mocks for types without default values.
Most helpful comment
@ihanjo There is an open proposal PR at #742 . The syntax I imagine will be
Note this is typesafe and Kotlin-friendly because passing the matcher is decoupled from the method invocation.