11package org .baeldung .mockito ;
22
33import static org .junit .Assert .assertEquals ;
4- import static org .mockito .Mockito .doReturn ;
5- import static org .mockito .Mockito .mock ;
6- import static org .mockito .Mockito .spy ;
7- import static org .mockito .Mockito .verify ;
84
95import java .util .ArrayList ;
106import java .util .List ;
117
128import org .junit .Test ;
139import org .junit .runner .RunWith ;
10+ import org .mockito .Mockito ;
1411import org .mockito .Spy ;
1512import org .mockito .runners .MockitoJUnitRunner ;
1613
@@ -20,60 +17,60 @@ public class MockitoSpyTest {
2017 @ Test
2118 public void whenSpyOnList_thenCorrect () {
2219 final List <String > list = new ArrayList <String >();
23- final List <String > spy = spy (list );
20+ final List <String > spyList = Mockito . spy (list );
2421
25- spy .add ("one" );
26- spy .add ("two" );
22+ spyList .add ("one" );
23+ spyList .add ("two" );
2724
28- verify (spy ).add ("one" );
29- verify (spy ).add ("two" );
25+ Mockito . verify (spyList ).add ("one" );
26+ Mockito . verify (spyList ).add ("two" );
3027
31- assertEquals (2 , spy .size ());
28+ assertEquals (2 , spyList .size ());
3229 }
3330
3431 @ Spy
35- List <String > spyList = new ArrayList <String >();
32+ List <String > aSpyList = new ArrayList <String >();
3633
3734 @ Test
3835 public void whenUseSpyAnnotation_thenCorrect () {
39- spyList .add ("one" );
40- spyList .add ("two" );
36+ aSpyList .add ("one" );
37+ aSpyList .add ("two" );
4138
42- verify (spyList ).add ("one" );
43- verify (spyList ).add ("two" );
39+ Mockito . verify (aSpyList ).add ("one" );
40+ Mockito . verify (aSpyList ).add ("two" );
4441
45- assertEquals (2 , spyList .size ());
42+ assertEquals (2 , aSpyList .size ());
4643 }
4744
4845 @ Test
4946 public void whenStubASpy_thenStubbed () {
5047 final List <String > list = new ArrayList <String >();
51- final List <String > spy = spy (list );
48+ final List <String > spyList = Mockito . spy (list );
5249
53- assertEquals (0 , spy .size ());
50+ assertEquals (0 , spyList .size ());
5451
55- doReturn (100 ).when (spy ).size ();
56- assertEquals (100 , spy .size ());
52+ Mockito . doReturn (100 ).when (spyList ).size ();
53+ assertEquals (100 , spyList .size ());
5754 }
5855
5956 @ Test
6057 public void whenCreateMock_thenCreated () {
61- final List mockedList = mock (List .class );
58+ final List mockedList = Mockito . mock (List .class );
6259
6360 mockedList .add ("one" );
64- verify (mockedList ).add ("one" );
61+ Mockito . verify (mockedList ).add ("one" );
6562
6663 assertEquals (0 , mockedList .size ());
6764 }
6865
6966 @ Test
7067 public void whenCreateSpy_thenCreate () {
71- final List spy = spy (new ArrayList ());
68+ final List spyList = Mockito . spy (new ArrayList ());
7269
73- spy .add ("one" );
74- verify (spy ).add ("one" );
70+ spyList .add ("one" );
71+ Mockito . verify (spyList ).add ("one" );
7572
76- assertEquals (1 , spy .size ());
73+ assertEquals (1 , spyList .size ());
7774 }
7875
7976}
0 commit comments