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.
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:
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...
精彩评论