我想在控制器中模拟此服务,以便我可以对其进行测试。我如何模拟coreservice.getRelatedInfo抛出给定的异常进行测试。 我试图扔掉它们,但是,我遇到了错误。当我测试运行时异常时,它正在工作。
@PostMapping("/realtedcustomerinfo")
public ResponseEntity<List<CustomerInfoDTO>>
getRelatedCustomerInfo(@RequestBody RelatedCustomerInfo
relatedCustomerInfo) {
log.info("Start of getRelatedCustomerInfo() input {}",
relatedCustomerInfo);
List<CustomerInfoDTO> customerInfoDTOs = null;
try {
customerInfoDTOs =
coreService.getRelatedCustomerInfo(relatedCustomerInfo);
} catch (JsonParseException e) {
log.error("Exception details", e);
} catch (JsonMappingException e) {
log.error("Exception details", e);
} catch (IOException e) {
log.error("Exception details", e);
}
if (null == customerInfoDTOs) {
log.info("End of getRelatedCustomerInfo() return {}", customerInfoDTOs);
return new ResponseEntity<List<CustomerInfoDTO>>(new ArrayList<CustomerInfoDTO>(), HttpStatus.OK);
}
log.info("End of getRelatedCustomerInfo() return {}", customerInfoDTOs);
return new ResponseEntity<List<CustomerInfoDTO>>(customerInfoDTOs, HttpStatus.OK);
}