@Test public void nameIsNull() { Address a = new Address(null, 34, 28); try { addressRepo.save(a); } catch (ConstraintViolationException cve) { assertEquals(1, cve.getConstraintViolations().size()); } }
@Test public void nameIsTooShort() { Address a = new Address("abc", 45, 37); try { addressRepo.save(a); } catch (ConstraintViolationException cve) { assertEquals(1, cve.getConstraintViolations().size()); assertEquals( "The Field Name must contains almost 4 characters.", cve.getConstraintViolations().iterator().next().getMessage()); } }