mockito-kotlin icon indicating copy to clipboard operation
mockito-kotlin copied to clipboard

captor.capture() must not be null

Open ArbenMaloku opened this issue 4 years ago • 1 comments
trafficstars

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())
  }

ArbenMaloku avatar Nov 25 '20 13:11 ArbenMaloku

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

Farix1337 avatar May 31 '21 13:05 Farix1337