junit和easymock,保存时例外

时间:2011-07-27 10:20:06

标签: easymock

我正在使用EasyMock和JUnit。我在保存时遇到异常。请在下面找到代码。

EasyMock.expect(someDao.save(pojo))。andReturn(pojo); // pojo我用值创建 EasyMock.replay(someDao);

Pojo savedObject = someService.save(pojo);

someService.save(pojo)在保存之前再调用一个服务。那怎么可以嘲笑那个服务?

谢谢, 大卫

1 个答案:

答案 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);