欺骗 postMethod (java 中的 apache)?

发布于 2024-09-12 10:04:26 字数 138 浏览 2 评论 0原文

我对此还很陌生,所以请不要让我失望。

我正在尝试模拟 Post 方法,以便我可以设置它返回的状态。例如,我想将 PostMethod 设置为 200。

这样做的原因是我试图模拟一台没有互联网连接的计算机,

提前致谢

Im fairly new to this so please dont slam me down.

I'm trying to mock a Postmethod so that I can set the status it returns. For instance I want to set my PostMethod to 200.

The reason for doing this is I am trying to mock a computer without an internet connection

Thanks in advance

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

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

发布评论

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

评论(1

拥抱我好吗 2024-09-19 10:04:26

你使用什么模拟库?语法会有所不同。

例如,在 Mockito 中,您可以执行以下操作:

final PostMethod mockPostMethod = Mockito.mock(PostMethod.class);
when(mockPostMethod.execute(Mockito.any(HttpState.class),
    Mockito.any(HttpConnection.class))).thenReturn(200);

当然,您可以使用 Mockito 类的静态导入以避免额外的合格参考文献。

What mocking library are you using? The syntax will vary.

In Mockito, for example, you might do the following:

final PostMethod mockPostMethod = Mockito.mock(PostMethod.class);
when(mockPostMethod.execute(Mockito.any(HttpState.class),
    Mockito.any(HttpConnection.class))).thenReturn(200);

And of course you could use a static import of the Mockito class to avoid the extra qualified references.

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