我在代码中使用了restTemplate.postForEntity()。在测试它周围的类时,我使用Mockito来模拟RestTemplate。Mockito.when(restTemplate.postForEntity(.....)).thenReturn(response)ResponseEntity<String> response= new ResponseEntity(HttpStatus.UNAUTHORIZED);
现在,当我运行这个测试时,postForEntity返回我刚才显示的模拟响应。