Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mustafa-Hassan2001 opened this issue Feb 16, 2024 · 0 comments

Comments

@Mustafa-Hassan2001
Copy link

Mustafa-Hassan2001 commented Feb 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant