### Verify interactions with mocks Source: https://site.mockito.org/ Create a mock object and verify that specific methods were called on it. ```java import static org.mockito.Mockito.*; // mock creation List mockedList = mock(List.class); // or even simpler with Mockito 4.10.0+ // List mockedList = mock(); // using mock object - it does not throw any "unexpected interaction" exception mockedList.add("one"); mockedList.clear(); // selective, explicit, highly readable verification verify(mockedList).add("one"); verify(mockedList).clear(); ``` -------------------------------- ### Configure Mockito dependency in Gradle Source: https://site.mockito.org/ Add the mockito-core dependency to your Gradle build file to include the library in your project. ```gradle repositories { mavenCentral() } dependencies { testImplementation "org.mockito:mockito-core:5.+" } ``` -------------------------------- ### Stub method calls on mocks Source: https://site.mockito.org/ Define behavior for mock methods using stubbing to return specific values when called. ```java // you can mock concrete classes, not only interfaces LinkedList mockedList = mock(LinkedList.class); // or even simpler with Mockito 4.10.0+ // LinkedList mockedList = mock(); // stubbing appears before the actual execution when(mockedList.get(0)).thenReturn("first"); // the following prints "first" System.out.println(mockedList.get(0)); // the following prints "null" because get(999) was not stubbed System.out.println(mockedList.get(999)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.