什么';在EasyMock expect调用上设置Eclipse断点的最佳方法是什么?
我有这样的代码什么';在EasyMock expect调用上设置Eclipse断点的最佳方法是什么?,eclipse,debugging,expect,easymock,breakpoints,Eclipse,Debugging,Expect,Easymock,Breakpoints,我有这样的代码 ClockService mockClockService = createMock( ClockService.class ); Long timeFirstNodeCreated = new Date().getTime(); expect( mockClockService.getNow() ).andReturn( timeFirstNodeCreated ) ; Long timeFirstNodeDeleted = new Date().getTi
ClockService mockClockService = createMock( ClockService.class );
Long timeFirstNodeCreated = new Date().getTime();
expect( mockClockService.getNow() ).andReturn( timeFirstNodeCreated ) ;
Long timeFirstNodeDeleted = new Date().getTime();
expect( mockClockService.getNow() ).andReturn( timeFirstNodeDeleted ) ;
我希望Eclipse在调用mockClockService.getNow()时随时挂起该程序。但是,由于ClockService是一个接口,我无法在ClockService.getNow()上设置断点,并且由于mockClockService是EasyMock代理,我也无法在expect行上设置断点。我想您可以使用andAnswer(或andDelegateTo)方法响应getNow()调用;您需要编写IAnswer(或ClockService)的实现,并在实现中设置断点。例如:
expect( mockClockService.getNow() ).andAnswer( new IAnswer<Long>() {
public Long answer() throws Throwable {
return WHATEVER_YOUR_WANT; // Put your breakpoint on this line
}
});
expect(mockClockService.getNow()).andAnswer(new IAnswer()){
公共长答案()可丢弃{
返回所需内容;//将断点放在这一行上
}
});
应该这样做
但也许你想多说一点你为什么要这么做?这表明您可能有设计问题