Complete the code to create a spy of the List class using Mockito.
List<String> spyList = Mockito.[1](new ArrayList<>());Mockito.spy() creates a spy object that wraps a real instance, allowing you to track interactions while keeping original behavior.
Complete the code to verify that the add method was called once on the spyList.
Mockito.[1](spyList).add("item");
Mockito.verify() is used to check if a method was called on a mock or spy object.
Fix the error in stubbing the size method of spyList to return 5.
Mockito.[1](5).when(spyList).size();
When stubbing spy methods, doReturn().when() is preferred to avoid calling the real method during stubbing.
Fill both blanks to stub the get method of spyList to return "mocked" for index 0.
Mockito.[1]("mocked").when(spyList).[2](0);
doReturn(value).when(spy).method(args) is the correct pattern to stub spy methods. Here, get(0) is stubbed to return "mocked".
Fill all three blanks to verify that the clear method was called exactly twice on spyList.
Mockito.[1](spyList, Mockito.[2](2)).[3]();
verify(mock, times(n)).method() checks that method was called n times on the mock or spy.