Customer { public void setName(String name) { this.name = name; } Customer();  Customer(String name); Long getId(); String getName(); void setName(String name); boolean isArchived(); void setArchived(boolean archived); final static String FIND_ALL_CUSTOMERS; }
@Test public void nameTooShortOnUpdate() { try { Customer customer = new Customer("Bob"); em.persist(customer); em.flush(); em.detach(customer); customer.setName("Bo"); em.merge(customer); em.flush(); fail("Expected ConstraintViolationException wasn't thrown."); } catch (ConstraintViolationException e) { assertEquals(1, e.getConstraintViolations().size()); ConstraintViolation<?> violation = e.getConstraintViolations() .iterator().next(); assertEquals("name", violation.getPropertyPath().toString()); assertEquals(Size.class, violation.getConstraintDescriptor() .getAnnotation().annotationType()); } }