Skip to content

Mocking a function with matchers that has default arguments throws InvalidUseOfMatchersException #240

Open
@guelo

Description

@guelo
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")
}

InvalidUseOfMatchersException "This exception may occur if matchers are combined with raw values"

Theoretically adding @jvmoverloads to doStuff should fix it but it didn't. Even if it did, it would be nice if mockito-kotlin could figure out how to generate a matcher that matches the default value. Alternatively, automatically generate an any() matcher.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions