### Question:
ResponseAssertionsFromIdpValidator { public void validate(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions) { validatedAssertions.getAssertions().forEach( assertion -> identityProviderAssertionValidator.validate(assertion, validatedResponse.getInResponseTo(), hubEntityId) ); if (!validatedResponse.isSuccess()) return; Assertion matchingDatasetAssertion = getMatchingDatasetAssertion(validatedAssertions); Assertion authnStatementAssertion = getAuthnStatementAssertion(validatedAssertions); if (authnStatementAssertion.getAuthnStatements().size() > 1) { throw new SamlValidationException(multipleAuthnStatements()); } matchingDatasetAssertionValidator.validate(matchingDatasetAssertion, validatedResponse.getIssuer().getValue()); authnStatementAssertionValidator.validate(authnStatementAssertion); identityProviderAssertionValidator.validateConsistency(authnStatementAssertion, matchingDatasetAssertion); ipAddressValidator.validate(authnStatementAssertion); } ResponseAssertionsFromIdpValidator(IdentityProviderAssertionValidator assertionValidator,
                                              MatchingDatasetAssertionValidator matchingDatasetAssertionValidator,
                                              AuthnStatementAssertionValidator authnStatementAssertionValidator,
                                              IPAddressValidator ipAddressValidator,
                                              String hubEntityId); void validate(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions);  }### Answer:
@Test public void validate_shouldDelegateAuthnStatementAssertionValidation() throws Exception { Response response = aResponse() .addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()) .addEncryptedAssertion(anAssertion().build()) .build(); Assertion authNAssertion = anAssertion().buildUnencrypted(); Assertion mdsAssertion = anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted(); List<Assertion> assertions = asList(mdsAssertion, authNAssertion); validator.validate(new ValidatedResponse(response), new ValidatedAssertions(assertions)); verify(authnStatementValidator).validate(authNAssertion); }
@Test public void validate_shouldDelegateMatchingDatasetAssertionValidation() throws Exception { Response response = aResponse() .addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()) .addEncryptedAssertion(anAssertion().build()) .build(); Assertion authNAssertion = anAssertion().buildUnencrypted(); Assertion mdsAssertion = anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted(); List<Assertion> assertions = asList(mdsAssertion, authNAssertion); validator.validate(new ValidatedResponse(response), new ValidatedAssertions(assertions)); verify(matchingDatasetAssertionValidator).validate(mdsAssertion, response.getIssuer().getValue()); }
@Test public void validate_shouldDelegateToIpAddressValidator() throws Exception { Assertion authnStatementAssertion = anAssertion().addAuthnStatement(anAuthnStatement().build()).buildUnencrypted(); Response response = aResponse() .addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()) .addEncryptedAssertion(anAssertion().addAuthnStatement(anAuthnStatement().build()).build()) .build(); List<Assertion> assertions = asList(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted(), authnStatementAssertion); validator.validate(new ValidatedResponse(response), new ValidatedAssertions(assertions)); verify(ipAddressValidator).validate(authnStatementAssertion); }