}
public void testGroups() {
Author author = new Author();
author.setCompany("ACME");
Book book = new Book();
book.setTitle("");
book.setAuthor(author);
boolean foundTitleConstraint = false;
Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book, Book.All.class);
assertEquals(1, constraintViolations.size());
// assuming an english locale, the interpolated message is returned
for (ConstraintViolation<Book> constraintViolation : constraintViolations) {
if (constraintViolation.getRootBean().getClass() == Book.class) {
Assert.assertEquals("may not be empty", constraintViolation.getMessage());
Assert.assertTrue(book == constraintViolation.getRootBean());
// the offending property
if (constraintViolation.getPropertyPath().toString().equals("title")) {
foundTitleConstraint = true;
// the offending value
Assert.assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
}
}
}
Assert.assertTrue(foundTitleConstraint);
}