person.setHomeless(false);
person.setAddress(new Address(null, "Amsterdam")); // (all contexts)
person.setNullableInteger(new Integer(3)); // invalid (ctx2) - min value is 10
AnnotationBeanValidationConfigurationLoader loader = new AnnotationBeanValidationConfigurationLoader();
BeanValidator validator = new BeanValidator(loader);
BindException errors = new BindException(person, "person");
setContext("ctx1");
validator.validate(person, errors);
assertTrue(errors.hasGlobalErrors());
assertEquals(2, errors.getGlobalErrorCount());
assertTrue(errors.hasFieldErrors());
assertTrue(errors.hasFieldErrors("firstName"));
assertTrue(errors.hasFieldErrors("lastName"));
assertEquals(1, errors.getFieldErrorCount("lastName"));
assertFalse(errors.hasFieldErrors("birthday"));
assertEquals(0, errors.getFieldErrorCount("age"));
assertTrue(errors.hasFieldErrors("father"));
assertTrue(errors.hasFieldErrors("mother.*"));
assertTrue(errors.hasFieldErrors("friends"));
assertTrue(errors.hasFieldErrors("address.street"));
assertFalse(errors.hasFieldErrors("nullableString"));
assertFalse(errors.hasFieldErrors("nullableInteger"));
assertEquals("Address.street[not.null]", errors.getFieldError("address.street").getCode());
clearContext();
setContext("ctx2");
errors = new BindException(person, "person");
validator.validate(person, errors);
assertFalse(errors.hasGlobalErrors());
assertTrue(errors.hasFieldErrors());
assertFalse(errors.hasFieldErrors("firstName"));
assertFalse(errors.hasFieldErrors("lastName"));