ArgumentCaptor в Kotlin возвращает исключение NotAMockException - PullRequest
0 голосов
/ 05 февраля 2020

Я пытаюсь понять, как использовать argumentsCaptor с Kotlin.

У меня есть класс, который я хочу проверить, который использует nestedBean:

@Component
class ClassToTest (private val nestedBean: NestedBean) {

    fun methodToTest() {

        ....
        val argumentToCapture: Argument = Argument()
        nestedBean.doSmth(argumentToCapture)
        ....
    }
}

В моем test Я хочу захватить аргумент nestedBean:

@SpringBootTest
class TestForClassToTest() {

    @Autowired
    lateinit var classToTest: ClassToTest

    @MockkBean
    lateinit var nestedBean: NestedBean

    @Test
    fun `test with capture`() {

        every { nestedBean.doSmth(any()) } just Runs

        classToTest.methodToTest()

        argumentCaptor<Argument>().apply {
            com.nhaarman.mockitokotlin2.verify(nestedBean).doSmth(capture())
        }
    }

}

Последняя строка кода всегда возвращает мне исключение NotAMockException, но, как вы можете видеть, я определенно объявил его как фиктивный компонент. Вы знаете, что я должен изменить?

    org.mockito.exceptions.misusing.NotAMockException: 
    Argument passed to verify() is of type NestedBean and is not a mock!
    Make sure you place the parenthesis correctly!
    See the examples of correct verifications:
       verify(mock).someMethod();
       verify(mock, times(10)).someMethod();
       verify(mock, atLeastOnce()).someMethod();
    at com.nhaarman.mockitokotlin2.VerificationKt.verify(Verification.kt:42)```
...