模拟一个复杂的api调用

时间:2020-02-13 18:33:58

标签: java spring

我在复杂的api调用中对spring @MockBean的理解有些问题:

serviceCommunication.callAPI(HttpMethod.POST,
                                    ServiceCommunication.TokenType.TokenTypeApplication,
                                    "document-service",
                                    URIConstants.CREATE_DOCUMENT,
                                    docDTO,
                                    new ParameterizedTypeReference<ApiResultResponse<String>>() {
                                    });

我在考试前嘲笑着:

when(serviceCommunication.callAPI(eq(HttpMethod.POST),
                any(ServiceCommunication.TokenType.class),
                eq("document-service"),
                eq(URIConstants.CREATE_DOCUMENT),
                any(),
                eq(new ParameterizedTypeReference<ApiResultResponse<String>>() {}))).thenReturn(new ApiResultResponse<>(documentID));

byut我得到的结果为空,我在哪里弄错了?

非常感谢

1 个答案:

答案 0 :(得分:0)

我解决了,我已经模拟了任务执行器,问题是当在另一个线程中调用模拟bean时

相关问题