'How to mock a local variables using mockito/powermock
I have a function as follows :
private Response getHttpResponse(String url) {
WebTarget target = client.target(url);
Invocation.Builder requestBuilder = target.request().accept(StandardCharSets.UTF_8.toString());
if (headerMap != null) {
for (final Map.Entry<String, Object> header: headerMap.entrySet()) {
requestBuilder.header(oneHeader.getKey(), String.valueOf(header.getValue());
}
}
Invocation request = requestBuilder.buildGet();
Response response = request.invoke();
return response;
}
I've spent way too much time on this. So I thought I should share my findings. Here my question is how to mock such local variable(request), so that I can mock invoke method response.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|