0

I've been away from mockito for awhile, so this is probably a newbie issue.

package somepackage

import org.junit.jupiter.api.Test
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

var called = false

open class SUT {
    fun doWork(type: String) {
        println("Doing $type work")
        called = true
    }
}

class MockTest {

    @Test
    fun `test doNothing`() {
        val sut: SUT = mock()
        doNothing().whenever(sut).doWork("busy")

        sut.doWork("busy")
        assert(!called)
    }
}

The test fails as doWork() was called. Twice. If I replace "busy" with any() in the mock, it fails with a NPE.

I'm expecting it to not call the actual method and do, well, nothing. Any ideas?

Kurt
  • 399
  • 3
  • 14

1 Answers1

0

Easy solve: Just add an open to the function:

open fun doWork(type: String) {

Kurt
  • 399
  • 3
  • 14