jeudi 17 décembre 2020

MOCKITO How to mock object method if object is not a bean

Inside the method I'm testing, I have this:

val client = PushClient() 
... 
client.sendPushNotificationsAsync(chunk)

PushClient is not a bean as you can see... how can I mock the sendPushNotificationsAsync method?

tried like this, but doesn't work, doesn't get called...

        val mockPushClient = mock(PushClient::class.java)
        val ticket = ExpoPushTicket()
        ticket.status = Status.OK
        val cf = CompletableFuture.completedFuture(listOf(ticket))
        Mockito.doReturn(cf).`when`(mockPushClient).sendPushNotificationsAsync(any())

Aucun commentaire:

Enregistrer un commentaire