title: Good patterns for unit testing form beans that have annotation-based validation in Spring MVC
body: <p>When using annotation based validation for a form bean, what is the best practice for unit-testing those beans in order to ensure that correct validations annotations are specified for each field?</p>
  
  <p>For example, if you have:</p>
  
  <pre><code>public class MyForm {
      @NotNull
      private String name;
  }
  </code></pre>
  
  <p>What is the best way to verify that <code>@NotNull</code> is applied to it?</p>
  
  <p>One obvious way is to create a validator, throw a null at it and expect it to fail. But in my view this is not the best way as you'll be testing the behaviour and implementation of <code>@NotNull</code> using that rather than trusting the framework.</p>
  
  <p>Ideally I would want to use reflection or a utility that gives me the possibility of just asserting that an <code>@NotNull</code> (and any other) validation is applied to a given field, rather than having to send various combination of values that fail validation.</p>
  
  <p>Is there an elegant way of doing this, or am I on the right track in general?</p>