mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.1k stars 200 forks source link

captor.capture() must not be null #394

Open ArbenMaloku opened 3 years ago

ArbenMaloku commented 3 years ago

I'm trying to use argumentCaptor for inline function. Every time I run the test I'm getting captor.capture() must not be null. Any suggestion?

 val captor = argumentCaptor<(Boolean) -> Unit>()

   @Before
  fun setUp() {
    MockitoAnnotations.openMocks(this)
   ...
  }

@Test
  fun shouldTestSomething() {
    val captor = argumentCaptor<(Boolean) -> Unit>()
    viewModel.doSomething(stringParam, captor.capture())
  }
Farix1337 commented 3 years ago

You need to make your capture call in your verify not directly and you can't mix values and matchers at one verification