title: How to test only specific http request method available for controller method in Spring MVC?
body: <p>I need to check if only specific http method is available for some url.
  For example, if there is a controller like this</p>
  
  <pre><code>@Controller
  public class FooController {
      @RequestMapping(value = "bar", method = RequestMethod.GET)
      public void bar() {/*do something*/};
      ...
  }
  </code></pre>
  
  <p>For controller test I use junit(4.10), spring-test(3.2.10) and easymock(3.1).
  If I write test like this</p>
  
  <pre><code>@Test
  public void testBar() throws Exception {
      mockMvc.perform(post("bar").session(session))
      .andExpect(/*some application's default error response*/);
  }
  </code></pre>
  
  <p>it will pass (although test calls post-method, not get-method).</p>
  
  <p>So I'm looking for a proper way to make sure, that my rest resources are only avaiable by request methods specified in documentation. Two solutions came to my mind:</p>
  
  <ul>
  <li>write tests with wrong request methods and somehow check resource is not available</li>
  <li>add custom exception resolver to process org.springframework.web.HttpRequestMethodNotSupportedException: Request method '__' not supported and return same application default error response, but with https status 405 Method not allowed.</li>
  </ul>
  
  <p>What would you suggest and how to check in controller test request method?</p>
  
  <p>Thanks in advance.</p>