Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Resttemplate交换方法的Mockito_Java_Rest_Mockito - Fatal编程技术网

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
like
eq(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);
}