Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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 MockMvc访问MockMvc将使用的MockHttpServletRequest对象_Spring_Junit_Controller_Easymock_Mockmvc - Fatal编程技术网

Spring MockMvc访问MockMvc将使用的MockHttpServletRequest对象

Spring MockMvc访问MockMvc将使用的MockHttpServletRequest对象,spring,junit,controller,easymock,mockmvc,Spring,Junit,Controller,Easymock,Mockmvc,在执行以下操作时,mockMvc将使用的实际请求对象是否仍然可以得到控制: mockMvc.perform(RequestBuilder RequestBuilder) 我知道我可以自己构建请求(即) 但是我不能传递这个请求,因为mockMvc.perform方法只接受将创建MockHttpServletRequest新实例的构建器。我正在使用EasyMock,它在匹配器中使用equals()(至少在默认情况下是这样),并且由于MockHttpServletRequest中缺少equals()实

在执行以下操作时,mockMvc将使用的实际请求对象是否仍然可以得到控制: mockMvc.perform(RequestBuilder RequestBuilder)

我知道我可以自己构建请求(即)

但是我不能传递这个请求,因为mockMvc.perform方法只接受将创建MockHttpServletRequest新实例的构建器。我正在使用EasyMock,它在匹配器中使用equals()(至少在默认情况下是这样),并且由于MockHttpServletRequest中缺少equals()实现,它只是比较对象ID。i、 e

      EasyMock.reset(localeHelper);

  localeHelper.getLocale(request);
  EasyMock.expectLastCall().andReturn(locale);
  /* this matcher will always fail because the request object is rebuilt by the mockMvc.perform(requestBuilder) call 
    and MockHttpServletRequest does not have an equals() method that these mocking tools can fall back on for object equivalency */
  EasyMock.replay(localeHelper);

你可能想要一个俘虏

Capture<HttpServletRequest> capture  = EasyMock.newCapture();
EasyMock.expect(localeHelper.getLocale(EasyMock.capture(capture))).andReturn(locale);
EasyMock.replay(localeHelper);

mockMvc.perform(requestBuilder);

HttpServletRequest request = capture.getValue();
// Then assert whatever you want on the `request` that was received in parameter by the mock
Capture-Capture=EasyMock.newCapture();
expect(localeHelper.getLocale(EasyMock.capture(capture)).andReturn(locale);
EasyMock.replay(localeHelper);
mockMvc.perform(requestBuilder);
HttpServletRequest请求=capture.getValue();
//然后对mock在参数中接收到的'request'断言您想要的任何内容
Capture<HttpServletRequest> capture  = EasyMock.newCapture();
EasyMock.expect(localeHelper.getLocale(EasyMock.capture(capture))).andReturn(locale);
EasyMock.replay(localeHelper);

mockMvc.perform(requestBuilder);

HttpServletRequest request = capture.getValue();
// Then assert whatever you want on the `request` that was received in parameter by the mock