Created
September 2, 2015 15:41
-
-
Save peekg/61ddd7c7752b44861b3f to your computer and use it in GitHub Desktop.
Test class for mocking HttpClient requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockRequestHandler extends RequestHandler { | |
private GetMethod mockGetMethod; | |
private HttpClient mockHttpClient; | |
public MockRequestHandler(int responseStatus, | |
byte[] responseBody) throws HttpException, IOException, | |
SecurityException, IllegalArgumentException, | |
NoSuchMethodException, IllegalAccessException, | |
InvocationTargetException { | |
mockGetMethod = Mockito.mock(GetMethod.class); | |
mockHttpClient = Mockito.mock(HttpClient.class); | |
Mockito.when( | |
mockHttpClient.executeMethod(Mockito.any(GetMethod.class))) | |
.thenReturn(responseStatus); | |
Mockito.when(mockGetMethod.getResponseBody()).thenReturn( | |
responseBody); | |
} | |
@Override | |
protected HttpClient getHttpClient() { | |
return mockHttpClient; | |
} | |
@Override | |
protected GetMethod getGetMethod() { | |
return mockGetMethod; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment