コード例 #1
0
  @Test
  public void nameIsNull() {
    Address a = new Address(null, 34, 28);

    try {
      addressRepo.save(a);
    } catch (ConstraintViolationException cve) {
      assertEquals(1, cve.getConstraintViolations().size());
    }
  }
コード例 #2
0
  @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());
    }
  }