在kotlinunit testing中获得lambda捕获器的调用计数

我有这个小小的和平代码,我想在我的主持人(MVP)

fun load(id: String) { storage.load(id, { result -> this.result = result view?.notifyLoaded(result) }, { string -> ... }) } 

。 我在我的unit testing用例中storage.load(String, (Result)->Unit, (String)->Unit)

 `when`(storage.load(eq(testResult.id), any Unit>(), any Unit>())).thenAnswer({ invocation -> (invocation.getArgument(1) as? (Result) -> Unit)?.invoke(testResult) }) 

现在我的测试案例看起来像这样

 @Test fun testLoading() { /* Given */ ... /* When */ presenterUnderTest.load(testResult.id) /* Then */ verify(storage, times(1)).load(eq(testResult.id), successCaptor.capture(), errorCaptor.capture()) assertTrue(presenterUnderTest.result == testResult) assertTrue(successCaptor.allValues.size == 1) assertTrue(errorCaptor.allValues.size == 1) verify(view, times(1)).notifyLoaded(testResult) } 

我是否有机会发现, successCaptor背后的lambda被调用了一次,而且errorCaptor背后的lambda从未被调用过? 我不想隐式地假设,因为view?.notifyLoaded(result)被调用。