开发者

Spoofing postMethod (apache in java)?

开发者 https://www.devze.com 2023-01-10 04:26 出处:网络
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开发者_如何学C. For instance I want to set my PostMethod to 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开发者_如何学C. 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


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.

0

精彩评论

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