let’s see how to use the @Spy annotation. We can use @Spy annotation instead of spy() as in the following example:
@Spy
List<String> spyList = new ArrayList<String>();
@Test
public void whenUsingTheSpyAnnotation_thenObjectIsSpied() {
spyList.add("one");
spyList.add("two");
Mockito.verify(spyList).add("one");
Mockito.verify(spyList).add("two");
assertEquals(2, spyList.size());