我们可以使用java jmockit在unirest httpClient中模拟发布请求(及其URL)吗?

时间:2019-05-01 02:01:17

标签: java asynchronous httpclient unirest

我正在使用第三方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

0 个答案:

没有答案