Mockk - MockKException when testing password against regex

Viewed 225

I've just started to do Unit testing in Kotlin using Mockk. I'm trying to test the following function:

    fun evaluatePredicate(regEx: String, passwordInserted: String) : Boolean {
        return passwordInserted.matches(regEx.toRegex())
    }

My test look like this:

    @Test
    fun evaluatePredicate_shouldContainLowerCase_trueExpected() {

        //given
        val regEx = ".*[a-z]+.*" //lower case
        val password = "password"

        every { password.matches(regEx.toRegex()) } returns true
        every { SUT.evaluatePredicate(regEx, password) } returns true

        //when
        val evaluate = password.matches(regEx.toRegex())
        val result = SUT.evaluatePredicate(regEx, password)

        //then
        assertEquals(evaluate, result)
    }

But I'm getting :

io.mockk.MockKException: Missing calls inside every { ... } block.

at line:

every { password.matches(regEx.toRegex()) } returns true

I've tried to use Mockk Matcher any() instead of matches(regEx.toRegex()) but nothing changed.

I'm not sure if I'm using the right tools for the job here. Any suggestion is welcome.

0 Answers
Related