title: How to test validation annotations of a class using JUnit?
body: <p>I need to test the <a href="http://docs.oracle.com/cd/E19798-01/821-1841/gkahq/index.html" rel="noreferrer">validation annotations</a> but it looks like they do not work. I am not sure if the JUnit is also correct. Currently, the test will be passed but as you can see the specified email address is wrong.</p>
  
  <p><strong>JUnit</strong></p>
  
  <pre><code>public static void testContactSuccess() {
          Contact contact = new Contact();
          contact.setEmail("Jackyahoo.com");
          contact.setName("Jack");
          System.err.println(contact);
      }
  </code></pre>
  
  <p><strong>Class to be tested</strong></p>
  
  <pre><code>public class Contact {
  
      @NotNull
      @Size(min = 1, max = 10)
      String name;
  
      @NotNull
      @Pattern(regexp="[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+(?:\\."
              +"[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*@"
              +"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
                   message="{invalid.email}")
      String email;
  
      @Digits(fraction = 0, integer = 10)
      @Size(min = 10, max = 10)
      String phone;
  
      getters and setters
  
  }
  </code></pre>