I'm using an ArgumentCaptor with @Captor annotation in Kotlin like this
@Captor private lateinit var captor: ArgumentCaptor<MyObject>
@Mock private lateinit var mockObject: InnerObject
private lateinit var objectToTest: MyClass
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
objectToTest = MyClass(mockObject)
}
fun testSomething() {
objectToTest.doSomething()
verify(mockObject).callMethod(captor.capture())
assertThat(expectedResult, captor.value)
}
The method callMethod() is called inside doSomething() and I want to capture the parameter sent to it.
My problem is that I'm getting:
java.lang.IllegalStateException: captor.capture() must not be null
I tried the same approach using java and it's working, when I convert it to Kotlin I get the exception.
Is this related to Kotlin? Or am I not using @Captor the right way?