Klitos Kyriacou
11/20/2022, 6:58 PMmockInstance
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:
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
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?ephemient
11/21/2022, 5:53 AMevery { mockInstance.foo(match { it.first == 1 && it.second == "a" }) } returns 42