### Question:
ValidationChain { public List<AttributeValidationResult> validate(UserProfileContext updateContext, UserProfile updatedProfile) { List<AttributeValidationResult> overallResults = new ArrayList<>(); for (AttributeValidator attribute : attributeValidators) { List<ValidationResult> validationResults = new ArrayList<>(); String attributeKey = attribute.attributeKey; String attributeValue = updatedProfile.getAttributes().getFirstAttribute(attributeKey); boolean attributeChanged = false; if (attributeValue != null) { attributeChanged = updateContext.getCurrentProfile() != null && !attributeValue.equals(updateContext.getCurrentProfile().getAttributes().getFirstAttribute(attributeKey)); for (Validator validator : attribute.validators) { validationResults.add(new ValidationResult(validator.function.apply(attributeValue, updateContext), validator.errorType)); } } overallResults.add(new AttributeValidationResult(attributeKey, attributeChanged, validationResults)); } return overallResults; } ValidationChain(List<AttributeValidator> attributeValidators); List<AttributeValidationResult> validate(UserProfileContext updateContext, UserProfile updatedProfile);  }### Answer:
@Test public void validate() { testchain = builder.build(); UserProfileValidationResult results = new UserProfileValidationResult(testchain.validate(updateContext, new UserRepresentationUserProfile(rep))); Assert.assertEquals(true, results.hasFailureOfErrorType("FAKE_FIELD_ERRORKEY")); Assert.assertEquals(false, results.hasFailureOfErrorType("FIRST_NAME_FIELD_ERRORKEY")); Assert.assertEquals(true, results.getValidationResults().stream().filter(o -> o.getField().equals("firstName")).collect(Collectors.toList()).get(0).isValid()); Assert.assertEquals(2, results.getValidationResults().size()); }
@Test public void mergedConfig() { testchain = builder.addAttributeValidator().forAttribute("FAKE_FIELD") .addValidationFunction("FAKE_FIELD_ERRORKEY_1", (value, updateUserProfileContext) -> false).build() .addAttributeValidator().forAttribute("FAKE_FIELD") .addValidationFunction("FAKE_FIELD_ERRORKEY_2", (value, updateUserProfileContext) -> false).build().build(); UserProfileValidationResult results = new UserProfileValidationResult(testchain.validate(updateContext, new UserRepresentationUserProfile(rep))); Assert.assertEquals(true, results.hasFailureOfErrorType("FAKE_FIELD_ERRORKEY_1")); Assert.assertEquals(true, results.hasFailureOfErrorType("FAKE_FIELD_ERRORKEY_2")); Assert.assertEquals(true, results.getValidationResults().stream().filter(o -> o.getField().equals("firstName")).collect(Collectors.toList()).get(0).isValid()); Assert.assertEquals(false, results.hasAttributeChanged("firstName")); }
@Test public void emptyChain() { UserProfileValidationResult results = new UserProfileValidationResult(ValidationChainBuilder.builder().build().validate(updateContext,new UserRepresentationUserProfile(rep) )); Assert.assertEquals(Collections.emptyList(), results.getValidationResults()); }