title: MvcResult has a status of 200 including the response but the assertion fails
body: <p>I am currently writing a JUnit test case for a controller in my application which returns a object (a URL). I am trying to assert the expected and the actual URL to be the same. There are 2 things happening here when I <strong>inspect</strong> the MvcResult result:</p>
  
  <ol>
  <li><p><strong>mockResponse</strong> has a status code of 200.</p></li>
  <li><p>In <strong>ModelAndView</strong>, the model does have the expected url value but when I try to assert the result using <code>result.getResponse().getContentAsString()</code>, 
  the assertion fails as the result is empty.</p></li>
  </ol>
  
  <p><strong>What I have already tried:</strong></p>
  
  <ol>
  <li><p>While debugging, I see the control moving to the service which means that the values were properly mocked and the expected url got returned to the result (as it was present in the ModelAndView when inspected). </p></li>
  <li><p>I have tried to give the expected url as a json object, used object mapper to read it and then tried a JSONAssert but the result is still empty. </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  public class StudentControllerTest {
  
    private static final String CACHE_URL= "cacheurl";
  
    @Mock
    StudentCacheService studentCacheService; 
  
    @InjectMocks
    StudentCacheController studentCacheController;
  
    private MockMvc mockMvc;
  
    @Before
    public void setUp() throws Exception {
    mockMvc = MockMvcBuilders.standaloneSetup(studentCacheController).build();
    }
  
    @Test
    public void testGetScoresUrl() throws Exception {
    Mockito.when(studentCacheService.getStudentUrl("123", "science"))
          .thenReturn(new StudentUrl(CACHE_URL));
    MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/123/scores")
          .header("subject", "science").contentType(MediaType.APPLICATION_JSON)).andExpect(status().is2xxSuccessful())
          .andReturn();
    Assert.assertEquals(CACHE_URL, result.getResponse().getContentAsString());
    }
  } 
  </code></pre></li>
  </ol>
  
  <p>My Controller class is as below: </p>
  
  <pre><code>@Controller
  @RequestMapping("/student")
  public class StudentCacheController {
     @Autowired
     StudentCacheService studentCacheService;
  
     @GetMapping(path = "/{studentId}/scores",produces = MediaType.APPLICATION_JSON_VALUE)
     public StudentUrl getScores(@PathVariable String studentId, @RequestHeader(value = "subject", required = true) String subject) throws Exception {
      return studentCacheService.getStudentUrl(studentId, subject);
   }
  }
  </code></pre>
  
  <p>The response is as below:</p>
  
  <pre><code>MockHttpServletResponse:
        Status = 200
        Error message = null
        Forwarded URL = student/123/scores
        Included URL = []
  
  ModelAndView:
        model = ModelMap
          key = studentUrl
          value = StudentUrl
             url = "cacheurl" 
  </code></pre>
  
  <p>I am receiving this error : <code>org.junit.ComparisonFailure: expected:&lt;[cacheurl]&gt; but was:&lt;[]&gt;</code></p>
  
  <p>Any help appreciated. Thanks!</p>