在 EasyMock Expect 调用上设置 Eclipse 断点的最佳方法是什么?

发布于 2024-09-28 15:43:41 字数 532 浏览 2 评论 0原文

我有这样的代码,

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 代理,因此我也无法在预期行上设置断点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再见回来 2024-10-05 15:43:41

我想您可以使用 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
   }
});

应该可以。

但也许您想更多地说明为什么要这样做?这表明您可能存在设计问题......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文