2011-07-27 77 views
0

我正在使用EasyMock和JUnit。我在保存時遇到異常。請找到下面的代碼。 EasyMock.explay(someDao.save(pojo))。andReturn(pojo); // pojo我創建了值 EasyMock.replay(someDao);junit和easymock,同時保存異常

Pojo savedObject = someService.save(pojo);

someService.save(pojo)在保存之前調用另一個服務。那麼如何嘲笑該服務?

謝謝, 大衛

回答

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