我一直在尝试使用 ResponseHandler 模拟 Apache HTTPClient,以便使用 Mockito 测试我的服务。有问题的方法是:
String response = httpClient.execute(httpGet, responseHandler);
Run Code Online (Sandbox Code Playgroud)
其中“responseHandler”是一个ResponseHandler:
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
return EntityUtils.toString(response.getEntity());
} else {
log.error("Accessing API returned error code: {}, reason: {}", status, response.getStatusLine().getReasonPhrase());
return "";
}
};
Run Code Online (Sandbox Code Playgroud)
有人可以建议我如何做到这一点吗?我想模拟“execute()”方法,但我不想模拟“responseHandler”(我不想测试现有的)。
谢谢!