title: Spring Boot mock MVC assertion error:Content type not set
body: <p>I am getting the following error trace, when I run a JUNIT method for HTTP PUT request in Spring boot.</p>
  
  <p>The input JSON value is successfully passed to the service method. However, I am not getting any response in HTTP servlet response.</p>
  
  <p>When I hit the service URL in post man, the input to the request will be JSON and response we get is also JSON.</p>
  
  <p><strong>PUT request</strong></p>
  
  <pre><code>    @Test
       public void updateMilestoneTest() throws Exception {
           Milestone milestone = new Milestone("100","MSJunit2","description","test2","mahi","mahi", null);
           milestone.setCreatedBy("auth");
           milestone.setCreatedDate(null);
           milestone.setUpdatedBy("auth");
           milestone.setLastModifiedDate(null);     
           when(milestoneService.updateMilestone("100",milestone)).thenReturn(milestone);
           String updateMilestoneJSON = "{\"milestoneId\":100,\"milestoneName\":\"MSJunit2\",\"description\":\"description\",\"condition\":\"test2\",\"createdBy\":\"auth\",\"updatedBy\":\"auth\",\"milestoneSynonymMappings\":null}";
           mockMvc.perform(put("/milestone/updateMilestone/100").contentType("application/json;charset=UTF-8").content(updateMilestoneJSON)).andExpect(status().isOk())
           .andExpect(content().contentType("application/json;charset=UTF-8"))
           .andExpect(jsonPath("$.milestoneId").value(100)).andExpect(jsonPath("$.milestoneName").value("MSJunit2"))
           .andExpect(jsonPath("$.description").value("description")).andExpect(jsonPath("$.createdBy").value("auth"));
       }
  
  Below is the error trace. I hope we should set content type as application/json only
  </code></pre>
  
  <p><strong>Error trace</strong></p>
  
  <pre><code>        java.lang.AssertionError: Content type not set
              at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:36)
              at org.springframework.test.util.AssertionErrors.assertTrue(AssertionErrors.java:66)
              at org.springframework.test.web.servlet.result.ContentResultMatchers.lambda$contentType$0(ContentResultMatchers.java:79)
              at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:178)
              at com.controller.MilestoneControllerTest.updateMilestoneTest(MilestoneControllerTest.java:102)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
              at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
              at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
              at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
              at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
              at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
              at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
              at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
              at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
              at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
              at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
              at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
              at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
              at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
              at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
              at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
              at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
              at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
              at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
              at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
              at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
              at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
              at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p>Below is the console log. As we can see here, input json is passed but in response , Body is empty</p>
  
  <h1>Console log</h1>
  
  <pre><code>   MockHttpServletRequest:
        HTTP Method = PUT
        Request URI = /milestone/updateMilestone/100
         Parameters = {}
            Headers = {Content-Type=[application/json;charset=UTF-8]}
               Body = {"milestoneId":100,"milestoneName":"MSJunit2","description":"description","condition":"test2","createdBy":"auth","updatedBy":"auth","milestoneSynonymMappings":null}
      Session Attrs = {}
  
  Handler:
               Type = com.controller.MilestoneController
             Method = public com.domain.Milestone com.controller.MilestoneController.updateMilestone(com.domain.Milestone,java.lang.String) throws com.exception.EntityNotFoundException
  
  Async:
      Async started = false
       Async result = null
  
  Resolved Exception:
               Type = null
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 200
      Error message = null
            Headers = {}
       Content type = null
               Body = 
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  
  Please let me know for further details needed. Thanks in advance.
  </code></pre>