mockito-kotlin: Mockito 5.0 breaks vararg argument capture in Kotlin

Hence issue was wrongly put on the mockito project.

Have code:

class PreferencesRepository {
    suspend fun getPreferences(
        vararg preferences: String
    ): Map<String, Any> 
{}

Write tests:

        val preferencesRepository: PreferencesRepository = mock()
        val preferencesCapture = argumentCaptor<String>()
        whenever(preferencesRepository.getPreferences(anyVararg())) doReturn emptyMap()

        verify(preferencesRepository).getPreferences(preferencesCapture.capture())

Run test and observe:

at PreferencesRepository.getPreferences(PreferecesRepository.kt:11)
Actual invocations have different arguments:
preferencesRepository.getPreferences(
    [String, String]
);

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

This seems to be working. Please check the tests if they reflect your use-case.

5.1.0 should be published later today

The original code still needs to be fixed - even it fails with a similar error. Please re-open.