I have a piece of java code that runs in a CompletableFuture#runAsync block and I want to verify that in this block, a specific service is never called.
Normally to verify that it is actually called, I can use the timeout VerificationMode to assert when the runAsync is likely completed
verify(myService, timeout(500)).methodX(param);But in my case I want to check if the service had no interactions. Normally this is done with verifyNoInteractions(myService); but this fires immediately and has a high chance for false positives.
The workaround is that, for every method in the service, I type use the times(0) VerificationMode e.g.:
verify(myService, timeout(500).times(0)).methodX(param);But this is an awful idea for all obvious reasons.
I know another possibility would be adding Thread.sleep(500); but I want to use the Mockito API if possible.
I just have not seen it done elsewhere.
Thank you for your support!