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);
精彩评论