mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.11k stars 202 forks source link

When a function with default arguments is mocked using matchers, an InvalidUseOfMatchersException is raised. #511

Open Mustafa-Hassan2001 opened 7 months ago

Mustafa-Hassan2001 commented 7 months ago

class UnderTest { fun doStuff(string1: String, string2: String = "hello world") = "do stuff" }

@Test fun testIt() { val underTest = mock(UnderTest::class.java) whenever(underTest.doStuff(anyString())).thenReturn("stuff done") }

Use of Matchers Is Invalid Exception "This exception may occur if matchers are combined with raw values"

It should have been fixed theoretically by adding @jvmoverloads to doStuff, but it wasn't. If mockito-kotlin could figure out how to construct a matcher that matches the default value, that would be helpful, too. Alternatively, have an any() matcher generated automatically.