Java Unirest调用后模拟-空指针异常

Java Unirest调用后模拟-空指针异常,java,nullpointerexception,mockito,powermock,unirest,Java,Nullpointerexception,Mockito,Powermock,Unirest,我正在使用Unirest调用一个API,其中包含以下代码行 HttpResponse<JsonNode> response = Unirest.post("/upstream_url"). field("username", username). field("password", password). field("grant_type", "password").

我正在使用Unirest调用一个API,其中包含以下代码行

        HttpResponse<JsonNode> response = Unirest.post("/upstream_url").
                field("username", username).
                field("password", password).
                field("grant_type", "password").
                field("client_id", getSSOClientId()).
                field("client_secret", getClientSecret())).
                asJson();
        return response;
post调用本身仍返回null

        httpRequestWithBody = Mockito.mock(HttpRequestWithBody.class);
        httpRequestWithBody.field("username", "username@userdomin.com");
        httpRequestWithBody.field("password", "***");
        httpRequestWithBody.field("grant_type", "password");
        httpRequestWithBody.field("client_id", "xyz");
        httpRequestWithBody.field("client_secret", "xxdf-112-ddfg");
        String requestStr = "upstream_url";

        Mockito.when(Unirest.post(requestStr + "/")).thenReturn(httpRequestWithBody);
        Mockito.when(httpResponse.getStatus()).thenReturn(Integer.valueOf(200));