tschuchort
01/29/2020, 1:35 PMMike
01/29/2020, 1:43 PMtschuchort
01/29/2020, 2:13 PMnot()
which means you can't verify that an argument is not equal to something with using argWhere { ... }
. MockK's API is completely asinine. Who thought verify(exactly = 1, atLeast = 2)
would be a good idea? MockK also lacks Mockito's check
matcher. And neither seem to allow me to verify that all calls to a function satisfy a predicate. Mockito has verifyAll
of course but that applies to all methods and not just one. So for an n-argument method you end up writing n+1 separate verify
clauses: One to verify the positive case and n to verify the negative case for each argument.Mike
01/29/2020, 2:36 PMMike
01/29/2020, 2:39 PMPersonally, I don’t recommend this kind of verification because it is too strict: it means that you don’t trust the actual implementation and the test needs to be updated frequently, every time when more interaction is added with the target mock object.
tschuchort
01/29/2020, 2:49 PMverifyNoMoreInteractions
won't work here because it also excludes calls to other methods of the mock. I want to verify: any number of calls to any method except foo
and at least one call to foo
with parameter x
and for all calls to foo
parameter is x
. Or in pseudocode:
val callsToFoo = calls.filter { it.methodName == "foo" }
assert(callsToFoo.all { it.argument == "x" } && callsToFoo.size >= 1)
tschuchort
01/29/2020, 2:55 PMverify(inverse = true)
and verify(exactly = 0)
. Shouldn't they be the same?Mike
01/29/2020, 2:58 PMinverse = true
and it would ensure that those aren't called. And because of possible parameters, you'll just end up with some equivalencies.Mike
01/29/2020, 3:05 PM//argument matchers can also be written as Java 8 Lambdas
verify(mockedObject).foo(argThat(someString -> someString == "X"));
From: https://javadoc.io/static/org.mockito/mockito-core/3.2.4/org/mockito/Mockito.html#argument_matchersErik
01/29/2020, 4:42 PMErik
01/29/2020, 4:43 PMverifyNoMoreInteractions
, called confirmVerified
. You can verify that you've verified all recorded interactions with your mocks.tschuchort
01/29/2020, 8:28 PMargThat
instead of not
but it's not really convenienttschuchort
01/29/2020, 8:29 PMconfirmVerified
wont work because I only want to verify all interactions on one method not on all methodskyleg
01/30/2020, 5:02 AMErik
01/30/2020, 7:42 AMtschuchort
01/30/2020, 12:57 PMMike
01/30/2020, 1:46 PM