How to verify that a specific method was not called using Mockito?

To verify that a specific method was not called using Mockito, you can use the verifyZeroInteractions method.

Here's an example of how you can use this method:

@Test
public void testMethod() {
  MyClass mock = mock(MyClass.class);
  // ...
  verifyZeroInteractions(mock);
}

This test will pass if the mock object was not interacted with during the test. If any methods were called on the mock object, the test will fail with an error message indicating which methods were called.

You can also use the verifyNoMoreInteractions method to verify that a mock object was not interacted with after a certain point in the test. For example:

@Test
public void testMethod() {
  MyClass mock = mock(MyClass.class);
  // ...
  verify(mock).someMethod();
  verifyNoMoreInteractions(mock);
}

This test will pass if the mock object was only interacted with by calling the someMethod method. If any other methods were called on the mock object, the test will fail.

I hope this helps! Let me know if you have any questions.