title: Spring MVC Unit Test - how to use hamcrest matcher
body: <p>I'm trying to write a simple test case for an MVC controller method.</p>
  
  <p>I want to test the view name contains a string.</p>
  
  <p>I think I need this version of the name matcher:</p>
  
  <p><code>public ResultMatcher name(org.hamcrest.Matcher&lt;? super String&gt; matcher)</code>
  Taken from here:
  <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/web/servlet/result/ViewResultMatchers.html#name-org.hamcrest.Matcher-" rel="nofollow">http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/web/servlet/result/ViewResultMatchers.html#name-org.hamcrest.Matcher-</a></p>
  
  <p>But how do I use it? I can't work out the right syntax...</p>
  
  <p>(syntax error on the Matchers.contains("web_tmpl") part of this expression:</p>
  
  <pre><code>this.mockMvc.perform(MockMvcRequestBuilders.get("/content/2"))
                  .andExpect(MockMvcResultMatchers.status().isOk())
                  .andExpect(MockMvcResultMatchers.view().name(Matchers.contains("web_tmpl")))
              ;
  </code></pre>