开发者

junit and easymock, exception while saving

I am using EasyMock and JUnit. i am getting exception while saving. Please find below code.

EasyMock.expect(someDao.save(pojo)).andReturn(pojo);//pojo开发者_运维知识库 i have created with values EasyMock.replay(someDao);

Pojo savedObject = someService.save(pojo);

but the someService.save(pojo) calls one more service before saving. so how can mock that service?

Thanks, David


The same way:

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜