我正在尝试模拟 restTemplate.postForEntity
方法,
实际的方法调用是:
URI myUri = new URI(myString);
HttpEntity<String> myEntity ...
String myResponse = restTemplate.postForEntity(myUri, myEntity, String.class);
我的测试课是:
Mockito.when(restTemplate.postForEntity(any(URI.class), any(HttpEntity.class), eq(String.class))).thenReturn(response);
这行不通;我也尝试过其他几种排列方式,但都没有成功。任何建议表示赞赏,谢谢。
这不起作用我的意思是调用了实际方法而不是模拟方法(因此没有返回所需的结果等)
最佳答案
以下代码对我有用 -
when(mockRestTemplate.postForEntity(anyString(), any(), eq(String.class))).thenReturn(response);
关于java - Mockito 模拟 restTemplate.postForEntity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25272391/