开发者

What's the best way to set an Eclipse breakpoint on a EasyMock expect call?

开发者 https://www.devze.com 2023-01-21 07:54 出处:网络
I have code like ClockService mockClockService = createMock( ClockService.class ); Long timeFirstNodeCreated = new Date().getTime();

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号