Java Resttemplate交换方法的Mockito
您需要将Java Resttemplate交换方法的Mockito,java,rest,mockito,Java,Rest,Mockito,您需要将Mockito.eq(HttpMethod.GET)添加到存根中的HttpMethod.GET,如下所示 getting error like org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 4 matchers expected, 3 recorded: @Mock 私有RestTemplate RestTemplate; @试验 pub
Mockito.eq(HttpMethod.GET)
添加到存根中的HttpMethod.GET
,如下所示
getting error like org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
4 matchers expected, 3 recorded:
@Mock
私有RestTemplate RestTemplate;
@试验
public void getWebDlpPoliciesTest()引发异常{
字符串responseValue=“{\n”+
“\“策略\”:[\n”+
“{\n”+
“lastUpdatedBy\”:“15678000\”,\n+
“\“LastUpdateTime\”:\”test@gmail.com\“,\n”+
“\“description\”:\“此规则集基于McAfee维护且您可以配置的DLP分类,阻止敏感信息在组织网络外部传输。\”,\n”+
“\”已发布状态\“:\”已发布\“,\n”+
“\”启用\“:\”正确\“,\n”+
“\”名称\“:\”DLP分类\“,\n”+
“\“id\”:\“DLP\U分类规则\”\n”+
“}\n”+
“\t\t\t\t]\n”+
"}";
ResponseEntity stringResponse=新的ResponseEntity(responseValue,HttpStatus.OK);
当(restemplate.exchange(anyString(),eq(HttpMethod.GET),anyObject(),(Class)anyObject())。然后返回(stringResponse);
}
不能使用3个匹配器和一个文本。包装HttpMethod.GET
likeeq(HttpMethod.GET)
getting error like org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
4 matchers expected, 3 recorded:
@Mock
private RestTemplate restTemplate;
@Test
public void getWebDlpPoliciesTest() throws Exception {
String responseValue = "{\n" +
" \"policies\": [\n" +
" {\n" +
" \"lastUpdatedBy\": \"15678000\",\n" +
" \"lastUpdatedTime\": \"test@gmail.com\",\n" +
" \"description\": \"This rule set blocks the transfer of sensitive information outside your organization's network based on DLP Classifications that McAfee maintains and that you can configure.\",\n" +
" \"publishedStatus\": \"PUBLISHED\",\n" +
" \"enabled\": \"true\",\n" +
" \"name\": \"DLP Classification\",\n" +
" \"id\": \"DLP_Classification_Rules\"\n" +
" }\n" +
"\t\t\t\t]\n" +
"}";
ResponseEntity<Object> stringResponse = new ResponseEntity<>(responseValue, HttpStatus.OK);
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), anyObject(), (Class<Object>) anyObject())).thenReturn(stringResponse);
}