hestia-rsps / hestia

An open-source Kotlin game server.
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Mockito verify suspend function called #52

Closed GregHib closed 4 years ago

GregHib commented 4 years ago

verify(mock).suspend()

Minimum reproducible example:

package worlds.gregs.hestia.core.plugins.dialogue.systems

import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock

internal class SuspendTest {

    interface Suspendable {
        suspend fun suspend()
    }

    fun calledElsewhere(mock: Suspendable) = runBlocking {
        mock.suspend()
    }

    @Test
    fun `Suspend test`() = runBlocking {
        //Given
        val mock = mock(Suspendable::class.java)
        `when`(mock.suspend()).thenReturn(Unit)
        //When
        calledElsewhere(mock)
        //Then
        Mockito.verify(mock).suspend()
    }

}
Argument(s) are different! Wanted:
suspendable.suspend(
    Continuation at worlds.gregs.hestia.core.plugins.dialogue.systems.SuspendTest$Suspend test$1.invokeSuspend(SuspendTest.kt:27)
);
-> at worlds.gregs.hestia.core.plugins.dialogue.systems.SuspendTest$Suspend test$1.invokeSuspend(SuspendTest.kt:27)
Actual invocation has different arguments:
suspendable.suspend(
    Continuation at worlds.gregs.hestia.core.plugins.dialogue.systems.SuspendTest$calledElsewhere$1.invokeSuspend(SuspendTest.kt:16)
);
-> at worlds.gregs.hestia.core.plugins.dialogue.systems.SuspendTest$calledElsewhere$1.invokeSuspend(SuspendTest.kt:16)
GregHib commented 4 years ago

Used Mockk instead se3906f625d7f05c5bac8f7934fbdf7bbedb18ae5b Mockito usage deprecated #59