title: Mockito test DAO with mocked objects
body: <p>I would like to test this DAO method</p>
  
  <pre><code>//in GrabDao.java
  public WrapperProject getChildren(Integer entityId, String entityType){
  
      EntityDao entityDao = new EntityDao();
      UserDao userDao = new UserDao();
  
      EntityBase entity = entityDao.getEntityById(entityId, entityType);
      Date dateProjet = userDao.getOrganismeFromSession().getExercice().getDateProjet();
  
      return new Wrapper(dateProjet, entity);
  }
  </code></pre>
  
  <p>This is what I've tried so far</p>
  
  <pre><code>    //in GrabDaoTest.java
      Integer paramEntityId = 1; 
      String paramEntityType = "type";
  
      EntityBase entityBase = Mockito.mock(EntityBase.class);
  
      EntityDao entityDao = Mockito.mock(EntityDao.class);
      when(entityDao.getEntityById(paramEntityId, paramEntityType)).thenReturn(entityBase);
  
      UserDao userDao = Mockito.mock(UserDao.class);
      Organisme organisme = Mockito.mock(Organisme.class);
      Exercice excercice = Mockito.mock(Exercice.class);
  
      when(userDao.getOrganismeFromSession()).thenReturn(organisme);
      when(organisme.getExercice()).thenReturn(excercice);
      when(userDao.getOrganismeFromSession().getExercice().getDateProjet()).thenReturn(new GregorianCalendar(2000, 01, 01).getTime());
  </code></pre>
  
  <p>Now I would like to test that the <strong>getChildren</strong> with fake params <strong>paramEntityId</strong> and <strong>paramEntityType</strong> will correctly return a WrapperProject 1 and 01/01/2000 <strong>using the mocked methods</strong> but I can't figured out how to launch the read method telling her to use the mocked dao</p>