title: java.lang.AssertionError: Content type not set while junit Spring MVC Controller?
body: <p>I am using JUnit to test my Spring MVC controller. Below is my method which returns a <code>index.jsp</code> page and shows <code>Hello World</code> on the screen - </p>
  
  <pre><code>@RequestMapping(value = "index", method = RequestMethod.GET)
  public HashMap&lt;String, String&gt; handleRequest() {
      HashMap&lt;String, String&gt; model = new HashMap&lt;String, String&gt;();
  
      String name = "Hello World";
      model.put("greeting", name);
  
      return model;
  }
  </code></pre>
  
  <p>And below is my JUnit test for the above method:</p>
  
  <pre><code>public class ControllerTest {
  
      private MockMvc mockMvc;
  
      @Before
      public void setup() throws Exception {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setPrefix("/WEB-INF/views/");
          viewResolver.setSuffix(".jsp");
  
          this.mockMvc = standaloneSetup(new Controller()).setViewResolvers(viewResolver).build();
      }
  
      @Test
      public void test01_Index() throws Exception {
  
      mockMvc.perform(get("/index")).andExpect(status().isOk()).andExpect(content().contentType("application/json"))
          .andExpect(jsonPath("$.greeting").value("Hello World"));
  
      }
  }
  </code></pre>
  
  <p>Above junit was working fine when I debugged it but when I ran the junit as <code>run as junit</code>, it gave me this error - </p>
  
  <pre><code>MockMvc : Circular view path [view]: would dispatch back to the current handler URL [/view] again
  </code></pre>
  
  <p>So to fix that I followed this <a href="http://myshittycode.com/2014/01/17/mockmvc-circular-view-path-view-would-dispatch-back-to-the-current-handler-url-view-again/" rel="noreferrer">tutorial</a> and after that I am getting this exception - </p>
  
  <pre><code>java.lang.AssertionError: Content type not set
      at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:39)
      at org.springframework.test.util.AssertionErrors.assertTrue(AssertionErrors.java:72)
      at org.springframework.test.web.servlet.result.ContentResultMatchers$1.match(ContentResultMatchers.java:75)
      at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141)
      at com.ebay.personalization.bullseye.zookeeper.test.ZookeeperControllerTest.test01_Index(ZookeeperControllerTest.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:76)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:602)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>
  
  <p>What am I doing wrong here? On the .jsp page it shows <code>Hello World</code>..</p>
  
  <p>I am following up on my previous question <a href="https://stackoverflow.com/questions/22182167/how-to-junit-return-type-of-a-method-in-spring-mvc-controller/22182342?noredirect=1#comment33670375_22182342">here</a></p>