### Question:
AuthnStatementAssertionValidator { public void validate(Assertion assertion) { validateAuthnStatement(assertion.getAuthnStatements().get(0)); duplicateAssertionValidator.validateAuthnStatementAssertion(assertion); } AuthnStatementAssertionValidator(DuplicateAssertionValidator duplicateAssertionValidator); void validate(Assertion assertion);  }### Answer:
@Test public void validate_shouldThrowExceptionIfAuthnContextIsAbsent() throws Exception { AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().withAuthnContext(null).build(); Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted(); validateFail(() -> validator.validate(assertion), authnContextMissingError()); }
@Test public void validate_shouldPassValidation() throws Exception { AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().build(); Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted(); validator.validate(assertion); }
@Test public void validate_shouldThrowExceptionIfAuthnContextClassRefIsAbsent() throws Exception { AuthnContext authnContext = AuthnContextBuilder.anAuthnContext().withAuthnContextClassRef(null).build(); AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().withAuthnContext(authnContext).build(); Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted(); validateFail(() -> validator.validate(assertion), authnContextClassRefMissing()); }
@Test public void validate_shouldThrowExceptionIfAuthnContextClassRefValueIsAbsent() throws Exception { AuthnContextClassRef authnContextClassRef = AuthnContextClassRefBuilder.anAuthnContextClassRef().withAuthnContextClasRefValue(null).build(); AuthnContext authnContext = AuthnContextBuilder.anAuthnContext().withAuthnContextClassRef(authnContextClassRef).build(); AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().withAuthnContext(authnContext).build(); Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted(); validateFail(() -> validator.validate(assertion), authnContextClassRefValueMissing()); }
@Test public void validate_shouldValidateForDuplicateIds() throws Exception { String id = "duplicate-id"; Assertion assertion = AssertionBuilder.anAssertion().withId(id).addAuthnStatement(AuthnStatementBuilder.anAuthnStatement().build()).buildUnencrypted(); validator.validate(assertion); verify(duplicateAssertionValidator, times(1)).validateAuthnStatementAssertion(assertion); }
@Test public void validate_shouldThrowExceptionIfAuthnInstantIsAbsent() throws Exception { AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().withAuthnInstant(null).build(); Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted(); validateFail(() -> validator.validate(assertion), authnInstantMissing()); }