views:

10

answers:

1

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.

A: 

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...

Ladlestein