考虑一个内部使用lambda函数的rest api调用方法,我们如何编写junit测试用例。我尝试了一下,但未能模拟uri构建器,该构建器在post api调用中表示为lambda函数。还有如何在flatMap中模拟块。下面给出了我尝试为其编写单元测试的代码段。
public ResponseEntity<String> findEmployee(String empName,String empId) {
response = employeeService.post.uri(builder -> builder.path(pathMapper.get("GET_PATH")).queryParam(EMP_ID,empId).build())
.accept(APPLICATION.JSON)
.syncBody(empName)
.exchange()
.flatMap( empResponse -> {
LOGGER.info(empResponse.getStatusCode());
return empResponse.toEntity(String.class);
}).block();
return response;
}
在这里,employeeService是一个Webclient对象。任何帮助将不胜感激。