title: Mockito -mocking implementation class
body: <p>Hi i am trying to mock dao layer 
  my application has some class hire achy like this Application->parser->dao(interface)->dao implementation class</p>
  
  <p>my problem is when i am mocking dao interface  or daoimp class using mockito 
  in my test case they are not working simply test case going to db how to do make our test case to use these mocked objects </p>
  
  <pre><code>    @RunWith(MockitoJUnitRunner.class)  
      public class CsvDataLoadServiceImplTest {
  
      @Mock private MeteringDataDao meteringDataDao;
  
      List&lt;Object&gt; persistedList;
      Object meteringData;
      List&lt;Object&gt; s=new ArrayList&lt;Object&gt;();
  
      @SuppressWarnings({ "rawtypes", "unchecked" })
      @Before public void setup(){
          Mockito.doAnswer(new Answer&lt;List&lt;Object&gt;&gt;() {
              @Override
              public List&lt;Object&gt; answer(InvocationOnMock invocation) throws Throwable {
                  Object[] args = invocation.getArguments();
                  System.out.println("persist all");
                  if(persistedList == null){
  
                      persistedList = (List)args[0];
  
                  }
                  else
                      persistedList.addAll((List)args[0]);
                  return null;
              }}).when(meteringDataDao).persistAll(anyList());
  
          Mockito.doAnswer(new Answer&lt;Object&gt;() {
              @Override
              public Object answer(InvocationOnMock invocation) {
                  Object[] args = invocation.getArguments();
                  if(meteringData == null)
  
                      meteringData = (List)args[0];
  
                  return true;
              }}).when(meteringDataDao).persist(anyObject());
      }
  
      @After public void tearDown(){
          persistedList = null;
          meteringData = null;
  
      }
  
      @Test
      public void testDataAccuricy(){
  
          CsvDataLoadService csvDataLoadService =new CsvDataLoadServiceImpl();
          csvDataLoadService.loadRackspaceCsvData();
      }
  }
  </code></pre>