title: How to JUnit tests a @PreAuthorize annotation and its spring EL specified by a spring MVC Controller?
body: <p>I've defined this method in my Spring MVC Controller :</p>
  
  <pre><code>@RequestMapping(value = "{id}/content", method=RequestMethod.POST)
  @PreAuthorize("principal.user.userAccount instanceof T(com.anonym.model.identity.PedagoAccount) AND principal.user.userAccount.userId == #object.pedago.userId AND #form.id == #object.id")
  public String modifyContent(@PathVariable("id") Project object, @Valid  @ModelAttribute("form") ProjectContentForm form) {
      ....
  }
  </code></pre>
  
  <p>Then in my JUnit test I'd like to call this method and ensure that the PreAuthorize condition is verified. But when I set the user principal in my JUnit test with a bad account there is no error and the method completes. It seems the annotation is bypassed.<br/>
  But when I call this method in a normal way (not testing), the PreAuthorize is verified.</p>
  
  <p>If it's possible, how to test this annotation in a junit test and how to catch the exception if it throws one ?</p>
  
  <p>Thanks,<br/>
  Nicolas</p>