Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify with any ignores exactly #25

Closed
a1flecke opened this issue Feb 14, 2018 · 2 comments
Closed

Verify with any ignores exactly #25

a1flecke opened this issue Feb 14, 2018 · 2 comments
Labels

Comments

@a1flecke
Copy link

a1flecke commented Feb 14, 2018

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: +
@oleksiyp oleksiyp added the bug label Feb 15, 2018
oleksiyp added a commit that referenced this issue Feb 15, 2018
@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 15, 2018

Version 1.7.5 should resolve issue you found. @a1flecke please check and close ticket if everything fine.

@a1flecke
Copy link
Author

@oleksiyp Confirmed. Thanks for the quick turnaround. Closing the ticket

Endhuine pushed a commit to Endhuine/mockk that referenced this issue May 13, 2021
…AtMostExactlyTest.kt;

tests for issue mockk#35 are moved to a Maps dedicated test class.
Endhuine pushed a commit to Endhuine/mockk that referenced this issue May 14, 2021
…AtMostExactlyTest.kt;

tests for issue mockk#35 are moved to a Maps dedicated test class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants