0

This is a mockito example from mockito website: It mocks a List object and test it. What's the point doing this? what's the benefits from this? Why can't i just instantiated a list?

 //Let's import Mockito statically so that the code looks clearer
 import static org.mockito.Mockito.*;

 //mock creation
 List mockedList = mock(List.class);

 //using mock object
 mockedList.add("one");
 mockedList.clear();

 //verification
 verify(mockedList).add("one");
 verify(mockedList).clear();
BufBills
  • 8,005
  • 12
  • 48
  • 90
  • 2
    Read http://stackoverflow.com/questions/28783722/when-using-mokito-what-is-the-difference-between-the-actual-object-and-the-mock/28783849#28783849 – JB Nizet Jun 04 '15 at 16:35
  • 3
    You are right, though, that _the specific case of List_ is probably a bad example. There's generally no reason to mock a List. (It was probably picked because people are familiar with the interface.) – Jeff Bowman Jun 04 '15 at 16:59

0 Answers0