title: Testing Spring MVC annotation mappings
body: <p>With Spring MVC, you can specify that a particular URL will handled by a particular method, and you can specify that particular parameters will map to particular arguments, like so:</p>
  
  <pre><code>@Controller
  public class ImageController {
  
     @RequestMapping("/getImage")
     public String getImage( @RequestParam("imageId") int imageId, Map&lt;String,Object&gt; model ) {
        model.put("image",ImageService.getImage(imageId));
     }
  
  }
  </code></pre>
  
  <p>This is all well and good, but now I want to test that an http request with an imageId parameter will invoke this method correctly.  In other words, I want a test that will break if I remove or change any of the annotations.  Is there a way to do this?</p>
  
  <p>It is easy to test that getImage works correctly.  I could just create an ImageController and invoke getImage with appropriate arguments.  However, this is only one half of the test.  The other half of the test must be whether getImage() will be invoked by the Spring framework when an appropriate HTTP request comes in.  I feel like I also need a test for this part, especially as my <code>@RequestMapping</code> annotations become more complex and invoke complex parameter conditions.</p>
  
  <p>Could you show me a test that will break if I remove line 4, <code>@RequestMapping("getImage")</code>?</p>