I have code like
我的代码就像
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 ) ;
I'd like Eclipse to suspend the program any time mockClockService.getNow() is called. However, since ClockService is an interface, I can't set a breakpoint on ClockService.getNow() and since mockClockService is an EasyMock proxy, I can't set a breakpoint on the expect lines either.
我希望Eclipse在调用mockClockService.getNow()时暂停程序。但是,由于ClockService是一个接口,我不能在ClockService.getNow()上设置断点,因为mockClockService是一个EasyMock代理,所以我也不能在expect行上设置断点。
1 个解决方案
#1
0
I guess you could use the andAnswer (or andDelegateTo) method to respond to getNow() calls; you'd write an implementation of IAnswer (or ClockService) and set a breakpoint in your implementation. As in:
我猜你可以使用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
}
});
That ought to do it.
应该这样做。
But maybe you want to say more about why you want to do this? It suggests that you might have a design problem...
但也许你想更多地谈谈你为什么要这样做?它表明你可能有设计问题......
#1
0
I guess you could use the andAnswer (or andDelegateTo) method to respond to getNow() calls; you'd write an implementation of IAnswer (or ClockService) and set a breakpoint in your implementation. As in:
我猜你可以使用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
}
});
That ought to do it.
应该这样做。
But maybe you want to say more about why you want to do this? It suggests that you might have a design problem...
但也许你想更多地谈谈你为什么要这样做?它表明你可能有设计问题......