TIL Mockito Kotlin has awesome argument matchers

Oliver Peate posted on March 5th, 2019

Mockito Kotlin has argThat and argForWhich argument matchers for use with verify:

verify(myClass).setItems(argThat { size == 2 })
verify(myClass).setItems(argForWhich { size == 2 })

Or you can use check and write assertions:

verify(myClass).setItems(check { 
  assertThat(it).hasSize(2)
  assertThat(it[0]).isEqualTo("value")
})

For simple assertions it’s much cleaner than using an argumentCaptor

What did you learn today?

Write a quick TIL post to reflect on what you've learned.

Write a post