I am trying to verify that a function was not called using the following:
verify {
managementService.deleteUser(any()) wasNot Called
}
That verification fails with the message:
Verification failed: call 1 of 1: ManagementService(#11).deleteUser(any())) was not called.
If I invert the verification to this:
verify {
managementService.deleteUser(any())
}
I still receive the same failure message.
There are other functions on ManagementService
that pass wasNot Called
just fine.
Why would my verification failing for wasNot Called
, while the error message says the failure is because it was not called? And why would inverting the check produce the same error?
CodePudding user response:
wasNot Called
is not used to verify that a specific function call has not been made, but that an entire mock was never called, like this:
verify {
managementService wasNot Called
}
If you want to verify that deleteUser
was not called with any argument, you can verify that the call happened exactly zero times:
verify(exactly = 0) {
managementService.deleteUser(any())
}