我想测试这个DAO方法
//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);
}
这是我目前尝试过的:
//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());
现在,我想测试使用虚假参数paramEntityId和paramEntityType的getChildren是否能够正确返回WrapperProject 1和01/01/2000,使用模拟的方法,但是我无法找出如何启动read方法,让它使用模拟的dao。