Skip to content

Conversation

@jselbo
Copy link
Contributor

@jselbo jselbo commented Nov 10, 2025

This adds nice reified functions for Mockito.mockStatic and Mockito.mockConstruction. This also adds a whenever wrapper for MockedStatic stubbing.

Before:

mockStatic(A::class.java).use { mock ->
  mock.`when`<String> { A.method() }.thenReturn("hi")
}

After:

mockStatic<A>().use { mock ->
  mock.whenever { A.method() } .thenReturn("hi")
}

In the future I'd like to add some documentation with caveats around "static" method stubbing of Kotlin code.

Thank you for submitting a pull request! But first:

  • Can you back your code up with tests?

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks!

@TimvdLippe TimvdLippe merged commit c523b9c into mockito:main Nov 11, 2025
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants