author.setFirstName("Gavin");
author.setLastName("King");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals(1, constraintViolations.size());
assertEquals("may not be empty", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
assertEquals("title", constraintViolation.getPropertyPath().toString());
book.setTitle("My fault");
book.setSubtitle("confessions of a president - a book for a nice price");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
assertEquals(1, constraintViolations.size());
constraintViolation = constraintViolations.iterator().next();
assertEquals("size must be between 0 and 30", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(book.getSubtitle(), constraintViolation.getInvalidValue());
assertEquals("subtitle", constraintViolation.getPropertyPath().toString());
book.setSubtitle("Capitalism in crisis");
author.setCompany("1234567890ß9876543212578909876542245678987432");
constraintViolations = validator.validate(book);
constraintViolation = constraintViolations.iterator().next();
assertEquals(1, constraintViolations.size());
assertEquals("size must be between 0 and 40", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(author.getCompany(), constraintViolation.getInvalidValue());
assertEquals("author.company", constraintViolation.getPropertyPath().toString());
author.setCompany("apache");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
assertEquals(0, constraintViolations.size());