When working with Mockito, you might need to confirm that no interaction occurred with a specific mock object during a test. Instead of checking each method individually using never(), Mockito provides a simpler approach. You can use the verifyNoInteractions(mock) method to assert that the mock was never called at all.
For example:
verifyNoInteractions(systemOut);
This ensures that no methods of the mocked object were invoked. Similarly, you can use verifyNoMoreInteractions(mock) to confirm that no unexpected calls were made beyond the verified ones.
This is especially useful for ensuring that debug statements like System.out.println() or e.printStackTrace() aren’t unintentionally left in production code.
I’ve run into this exact issue before! If you just want to confirm that a mock wasn’t touched at all during the test, you can use:
verifyNoInteractions(systemOut);
This one-liner ensures that no methods were called on that mock — super handy for sanity checks.
In cases where you’ve already verified some calls and want to make sure nothing extra happened, try:
verifyNoMoreInteractions(systemOut);
I usually add this at the end of tests to catch any unexpected behavior or side effects.
If you want to target a specific method, never() works great:
verify(systemOut, never()).println(anyString());
This explicitly checks that a method like println() wasn’t triggered at all — useful for making sure no debug logs or unwanted outputs slipped in.