我试图在单元测试中使用mockito模拟下面的rest调用。
String url = baseUrl + "/samples";
ResponseEntity<SampleDto> response =
restTemplate.exchange(url, HttpMethod.GET, null, SampleDto.class);
及其模拟使用:
when(restTemplate.exchange(eq(anyString()),eq(HttpMethod.GET), null,
eq(SampleDto.class))).thenReturn(new ResponseEntity<>(new SampleDto(), HttpStatus.OK));
但是CCD_ 1一直变为空。有什么建议吗?
请尝试以下配置
when(restTemplate.exchange(Mockito.anyString()
, Mockito.eq(HttpMethod.GET)
, null
, Mockito.<Class<SampleDto>>any())
).thenReturn(new ResponseEntity<>(new SampleDto(), HttpStatus.OK));