Spoofing postMethod (apache in java)?
-
08-10-2020 - |
Question
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
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow