Skip to content

Verify with any ignores exactly #25

@a1flecke

Description

@a1flecke

Specifying exactly=0 on a verify where an any() matcher is used results in a verification failure when a different call does happen on the mock . This should not be an error as the call did specified did not happen

Example from your io.mockk.it.VerifyAtLeastAtMostExactlyTest class.

class MockCls {
        fun op(a: Int) = a + 1
        fun op2(a: Int, b: Int) = a + b
    }

val mock = mockk<MockCls>()

@Test
    fun exactlyZeroWithAny() {
        doCalls()

        verify(exactly = 0) {
            mock.op2(3, any())
        }
    }

fun doCalls() {
        every { mock.op(0) } throws RuntimeException("test")
        every { mock.op(1) } returnsMany listOf(1, 2, 3)
        every { mock.op2(2, 1) } returns 3

        assertFailsWith(RuntimeException::class) {
            mock.op(0)
        }

        assertEquals(1, mock.op(1))
        assertEquals(2, mock.op(1))
        assertEquals(3, mock.op(1))
        assertEquals(3, mock.op(1))
        assertEquals(3, mock.op2(2, 1))
    }

Error:

java.lang.AssertionError: Verification failed: call 1 of 1: MockCls(#387).op2(eq(3), any())). Only one matching call to MockCls(#387)/op2(Int, Int) happened, but arguments are not matching:
[0]: argument: 2, matcher: eq(3), result: -
[1]: argument: 1, matcher: any(), result: +

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions