我有一个这样的班。现在,我正在对此进行单元测试。我可以将事件对象更改为无效输入以测试结果。问题是该网址暂时不正确。我该如何做,例如假URL或响应来测试成功的请求?由于某些原因,我只能使用Mockito,而不能使用其他测试框架。此类仍可测试吗?
Class processor{
public int sendRequest(Event event) {
Client client = ClientBuilder.newClient();
WebTarget baseTarget = client.target(some url);
Invocation.Builder builder = baseTarget.request();
Response response = builder.post(Entity.entity(event, MediaType.APPLICATION_JSON));
int statusCode = response.getStatus();
if (Status.Family.SUCCESSFUL == Status.Family.familyOf(statusCode)) {
m_log.debug("The event was successfully processed by t API %s", event);
}
else if (Status.Family.CLIENT_ERROR == Status.Family.familyOf(statusCode)) {
m_log.error("Status code : <%s> The request was not successfully processed by API. %s", statusCode, event);
}
return statusCode;
}
}