title: How to PUT multipart/form-data using Spring MockMvc?
body: <p>I have a controller's method with a <code>PUT</code> method, which receives multipart/form-data:</p>
  
  <pre><code>   @RequestMapping(value = "/putIn", method = RequestMethod.PUT)
     public Foo updateFoo(HttpServletRequest request,
                             @RequestBody Foo foo,
                             @RequestParam("foo_icon") MultipartFile file) {
      ...
     }
  </code></pre>
  
  <p>and I want to test it using <code>MockMvc</code>. Unfortunately <code>MockMvcRequestBuilders.fileUpload</code> creates essentially an instance of <code>MockMultipartHttpServletRequestBuilder</code> which has a <code>POST</code> method:</p>
  
  <pre><code>super(HttpMethod.POST, urlTemplate, urlVariables)
  </code></pre>
  
  <p><strong>EDIT:</strong>
  <strike>Surely I can</strike> <strong>I can not</strong> create my own implementation of <code>MockHttpServletRequestBuilder</code>, say</p>
  
  <pre><code>public MockPutMultipartHttpServletRequestBuilder(String urlTemplate, Object... urlVariables) {
      super(HttpMethod.PUT, urlTemplate, urlVariables);
      super.contentType(MediaType.MULTIPART_FORM_DATA);
  }
  </code></pre>
  
  <p>because <code>MockHttpServletRequestBuilder</code> has a package-local constructor.</p>
  
  <p><strike>But I'm wondering is there any more convenient</strike> Is any way to do this, may be I missed some existent class or method for doing this?</p>