我正在为控制器方法之一编写一个junit,其方法签名如下:
@RequestMapping(value="/getTokenizedURL.json",method=RequestMethod.POST)
@ResponseBody
public ResponseData getTokenizedURL(@RequestBody final RequestData requestData, final HttpServletRequest request) throws CustomException
Run Code Online (Sandbox Code Playgroud)
我需要使用 MockMvc 调用此方法,并且可以使用以下方式调用:
mockMvc.perform(post("/user/getTokenizedURL.json")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andDo(print())
.andExpect(status().isOk());
Run Code Online (Sandbox Code Playgroud)
但问题是我无法HttpServletRequest
在使用模拟 mvc 调用原始方法时设置参数。如果不设置HttpServletRequest
参数,我的测试就会出现问题,因为它是原始方法中必需的和使用的。
请让我知道我应该如何设置相同的内容。谢谢!