BusinessObject.class.getResource("test-beanInfos.xml")));
MetaBean info = finder.findForClass(BusinessObject.class);
BusinessObject object = new BusinessObject();
object.setAddress(new BusinessObjectAddress());
object.getAddress().setOwner(object);
BeanValidator<ValidationResults> validator = new BeanValidator();
ValidationResults results = validator.validate(object, info);
assertTrue(results.hasErrorForReason(Reasons.MANDATORY));
assertTrue(results.hasError(object, null));
assertTrue(results.hasError(object.getAddress(), null));
assertTrue(
validator.validateProperty(object, info.getProperty("firstName")).hasError(
object, "firstName"));
object.setUserId(1L);
object.setFirstName("Hans");
object.setLastName("Tester");
object.setAddress(new BusinessObjectAddress());
object.getAddress().setOwner(object);
assertFalse(validator.validate(object, info).isEmpty());
object.getAddress().setCountry("0123456789012345678");
assertFalse(validator.validate(object, info).isEmpty());
object.getAddress().setCountry("Germany");
object.setAddresses(new ArrayList());
object.getAddresses().add(object.getAddress());
object.getAddresses().add(object.getAddress());
object.getAddresses().add(object.getAddress());
assertTrue(validator.validate(object, info).isEmpty());
// 4th address is too much!
object.getAddresses().add(object.getAddress());
assertFalse(
validator.validate(object, info).isEmpty()); // cardinality error found
}