title: Mock Mvc unit test throws Http 406
body: <p>My controller has this code</p>
  
  <pre><code>@RequestMapping(value = "/getUserByEmailId/{emailId}", method = GET, produces = "application/json")
  public ResponseEntity&lt;UserRegistrationResponse&gt; getUserByEmailId(@PathVariable String emailId) throws ServiceException {
      return new ResponseEntity(generateUserOutput(userService.findUserByEmail(emailId)), OK);
  }
  </code></pre>
  
  <p>My test has this:</p>
  
  <pre><code>@Test
  public void testGetUserByEmailId() throws Exception {
      when(userService.findUserByEmail(any())).thenReturn(userOutput);
      MvcResult mvcResult = performGet("/user/getUserByEmailId/{emailId}", userRegistrationRequest.getEmail());
      assertEquals(200, mvcResult.getResponse().getStatus());
  }
  
  private MvcResult performGet(String path, String pathVariable) throws Exception {
      return mockMvc.perform(get(path,pathVariable)
              .accept(APPLICATION_JSON))
              .andDo(print())
              .andReturn();
  }
  </code></pre>
  
  <p>This is returning HTTP status code 406.</p>
  
  <pre><code>MockHttpServletRequest:
    HTTP Method = GET
    Request URI = /user/getUserByEmailId/testEmailId@test.com
     Parameters = {}
        Headers = {Accept=[application/json]}
           Body = &lt;no character encoding set&gt;
  Session Attrs = {}
  
  Handler:
           Type = com.nz.unicorn.web.controller.UserController
         Method = public org.springframework.http.ResponseEntity&lt;com.nz.unicorn.web.response.UserRegistrationResponse&gt; com.nz.unicorn.web.controller.UserController.getUserByEmailId(java.lang.String) throws com.nz.unicorn.service.exception.ServiceException
  
  Async:
  Async started = false
   Async result = null
  
  Resolved Exception:
           Type = org.springframework.web.HttpMediaTypeNotAcceptableException
  
  ModelAndView:
      View name = null
           View = null
          Model = null
  
  FlashMap:
     Attributes = null
  
  MockHttpServletResponse:
         Status = 406
  Error message = null
        Headers = {}
   Content type = null
           Body = 
  Forwarded URL = null
  Redirected URL = null
        Cookies = []
  </code></pre>
  
  <p>Is there anything I can do? I have seen a lot of questions without an answer that I can use. Do note, mine is not a spring test, it's a unit test.</p>