Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Spring 无法模拟rest客户端的响应_Spring_Mocking_Rest Client - Fatal编程技术网

Spring 无法模拟rest客户端的响应

Spring 无法模拟rest客户端的响应,spring,mocking,rest-client,Spring,Mocking,Rest Client,我正在尝试为junit测试模拟rest客户端。这是我的rest客户机代码行 ResponseEntity<MyClass[]> responseEntity = restTemplate.postForEntity(myurl, input, MyClass[].class); ResponseEntity ResponseEntity=restTemplate.postForEntity(myurl,input,MyClass[].class); 在我的少年时代,我试过 My

我正在尝试为junit测试模拟rest客户端。这是我的rest客户机代码行

ResponseEntity<MyClass[]> responseEntity = restTemplate.postForEntity(myurl, input, MyClass[].class); 
ResponseEntity ResponseEntity=restTemplate.postForEntity(myurl,input,MyClass[].class);
在我的少年时代,我试过

MyClass[] classArr= new MyClass[myClassList.size()]; //here myClassList is list of MyClass
        classArr = myClassList.toArray(classArrclassArr);


        ResponseEntity<MyClass[]> responseEntity = new ResponseEntity<MyClass[]>(classArr, HttpStatus.OK);       
        when(restTemplate.postForEntity(any(String.class), any(InputParam.class), MyClass[].class)).thenReturn(responseEntity);
MyClass[]classArr=newmyclass[myClassList.size()]//这里myClassList是MyClass的列表
classArr=myClassList.toArray(classArr);
ResponseEntity ResponseEntity=新的ResponseEntity(classArr,HttpStatus.OK);
when(restemplate.postForEntity(any(String.class)、any(InputParam.class)、MyClass[].class)).thenReturn(responseEntity);

但是
responseEntity
返回空值。这里是否有我做错的事情

您是否尝试过
any(MyClass[].class)
我做过。我得到错误--类型不匹配:无法从MyClass[]转换到Classtry this
Matchers.any()
我修复了该部分,但返回空值。我更新了问题。你能看一下吗?你发布的代码无法编译。MyClass[]应该是eq(MyClass[].class)