Hi, supposing I have a `mockInstance` that has a m...
# mockk
k
Hi, supposing I have a
mockInstance
that has a member function
fun foo(arg: MyClass): Int
, and I want to mock the function
foo
only if it takes an arg that is constructed with specific values:
Copy code
every { mockInstance.foo(MyClass(1, "a", 0)) } returns 42
every { mockInstance.foo(MyClass(1, "a", 1)) } returns 42
every { mockInstance.foo(MyClass(1, "a", 2)) } returns 42
every { mockInstance.foo(MyClass(1, "a", 3)) } returns 42
every { mockInstance.foo(MyClass(1, "a", 4)) } returns 42
...
In fact, I would like to say
Copy code
every { mockInstance.foo(MyClass(1, "a", any())) } returns 42
but I can't because the argument passed to
foo
is a real instance of
MyClass
and so I can't pass
any()
to it. Is there a particular matcher I can use?
e
https://mockk.io/#matchers
Copy code
every { mockInstance.foo(match { it.first == 1 && it.second == "a" }) } returns 42