When the test runs instead of passing like it should, it returns the following error
Wanted but not invoked:
fileDeleter.delete(
<Purge data and expired drafts clears purge media$$inlined$arg that$ 1>
);
-> at com.FileDeleter.delete(FileDeleter.kt:7)
However, there was exactly 1 interaction with this mock:
fileDeleter.deleteRecursively(
/path/purge_media
);
I can get around this by using an argument captor instead
@Test
fun `clearPurgeDataAndExpiredDrafts clears PugeMedia`() {
val file: File = mock()
whenever(context.filesDir).thenReturn(file)
whenever(file.absolutePath).thenReturn("/path/")
val captor = argumentCaptor<File>()
mediaCleaner.clearPurgeDataAndExpiredDrafts()
verify(fileDeleter).deleteRecursively(captor.capture())
assertEquals("/path/purge_media", captor.firstValue.absolutePath)
}
I verified it's still in the latest versions of Mockito and Mockito Kotlin, but it was happening as far back as the 2.0 betas which I hadn't upgraded from.
I'm writing a test where I want to validate that the path of a file i'm about to delete is correct.
When the test runs instead of passing like it should, it returns the following error
I can get around this by using an argument captor instead
I verified it's still in the latest versions of Mockito and Mockito Kotlin, but it was happening as far back as the 2.0 betas which I hadn't upgraded from.
Mockito 3.5.15 Mockito Kotlin 2.2.0