Mockito - check if any method was called on the object (the object was available)

I want to write a test that passes the layout of object A to the object under testing B, and checks if ANY of methods A is called. To give some context, class B is designed to control A in a certain way, based on a set of parameters, and for certain under conditions, he should not do anything with him. Therefore, my goal is to test this scenario. I know how to check if a particular method has been called:

verify(A, never()).myMethod(); 

But I canโ€™t find a way to make sure that NONE from Method A was called. Is there any way to do this?

+5
source share
1 answer

I believe verifyZeroInteractions may be what you are looking for. In your case, you call Mockito.verifyZeroInteractions(A) .

public static void verifyZeroInteractions(java.lang.Object... mocks)

 Verifies that no interactions happened on given mocks. 

http://static.javadoc.io/org.mockito/mockito-core/2.8.47/org/mockito/Mockito.html#verifyZeroInteractions (java.lang.Object ...)

+8
source

Source: https://habr.com/ru/post/1214372/


All Articles