我正在使用第三方API。我想对要模拟发布请求(URL)的方法进行单元测试。
String textFilePath = config.getString(TEXTFILE);
File file = new File(textFilePath + uuid + TEXTFILE_EXTENSION);
Future<HttpResponse<String>> future = Unirest.post(URL)
.field("accept", ContentType.create("text/plain", "UTF-8"))
.field("file ", file)
.asStringAsync(new Callback<String>() {
@Override
public void completed(HttpResponse<String> httpResponse) {
String responseBody = httpResponse.getBody();
System.out.println("\n\n\nRESPONSE BODY: " + responseBody + "\n\n\n");
frameDAO.updateMoM(uuid, responseBody);
}
@Override
public void failed(UnirestException e) {
LOGGER.error("The request is failed to process");
}
@Override
public void cancelled() {
LOGGER.info("The request has been cancelled");
}
});
return future.get().getStatus();
}
我想在上面的代码中模拟URL