开发者

junit and easymock, exception while saving

开发者 https://www.devze.com 2023-03-23 09:59 出处:网络
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

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

精彩评论

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

关注公众号