我正在使用EasyMock和JUnit。我在保存时遇到异常。请在下面找到代码。
EasyMock.expect(someDao.save(pojo))。andReturn(pojo); // pojo我用值创建 EasyMock.replay(someDao);
Pojo savedObject = someService.save(pojo);
但 someService.save(pojo)在保存之前再调用一个服务。那怎么可以嘲笑那个服务?
谢谢, 大卫
答案 0 :(得分:0)
以同样的方式:
SomeDao someDao = createMock(SomeDao.class);
SomeOtherDao someOtherDao = createMock(SomeOtherDao.class);
someService.setSomeDao(someDao);
someService.setSomeOtherDao(someOtherDao);
EasyMock.expect(someOtherDao.save(pojo)).andReturn(pojo);
EasyMock.expect(someDao.save(pojo)).andReturn(pojo);
EasyMock.replay(someOtherDao, someDao);
Pojo savedObject = someService.save(pojo);