### Question:
IdaResponseFromIdpUnmarshaller { public InboundResponseFromIdp fromSaml(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions) { Optional<PassthroughAssertion> matchingDatasetAssertion = validatedAssertions.getMatchingDatasetAssertion() .map(passthroughAssertionUnmarshaller::fromAssertion); Optional<PassthroughAssertion> authnStatementAssertion = validatedAssertions.getAuthnStatementAssertion() .map(passthroughAssertionUnmarshaller::fromAssertion); IdpIdaStatus transformedStatus = statusUnmarshaller.fromSaml(validatedResponse.getStatus()); URI destination = URI.create(validatedResponse.getDestination()); Optional<DateTime> notOnOrAfter = validatedAssertions.getMatchingDatasetAssertion() .flatMap(a -> Optional.ofNullable(a.getSubject())) .flatMap(s -> Optional.ofNullable(s.getSubjectConfirmations().get(0).getSubjectConfirmationData().getNotOnOrAfter())); return new InboundResponseFromIdp( validatedResponse.getID(), validatedResponse.getInResponseTo(), validatedResponse.getIssuer().getValue(), validatedResponse.getIssueInstant(), notOnOrAfter, transformedStatus, Optional.ofNullable(validatedResponse.getSignature()), matchingDatasetAssertion, destination, authnStatementAssertion); } IdaResponseFromIdpUnmarshaller(
            IdpIdaStatusUnmarshaller statusUnmarshaller,
            PassthroughAssertionUnmarshaller passthroughAssertionUnmarshaller); InboundResponseFromIdp fromSaml(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions);  }### Answer:
@Test public void transform_shouldTransformTheSamlResponseToIdaResponseByIdp() throws Exception { Assertion mdsAssertion = anAssertion().addAttributeStatement(anAttributeStatement().build()).buildUnencrypted(); Assertion authnStatementAssertion = anAssertion().addAuthnStatement(anAuthnStatement().build()).buildUnencrypted(); when(response.getAssertions()).thenReturn(List.of(mdsAssertion, authnStatementAssertion)); PassthroughAssertion passthroughMdsAssertion = aPassthroughAssertion().buildMatchingDatasetAssertion(); when(passthroughAssertionUnmarshaller.fromAssertion(mdsAssertion)).thenReturn(passthroughMdsAssertion); PassthroughAssertion passthroughAuthnAssertion = aPassthroughAssertion().buildAuthnStatementAssertion(); when(passthroughAssertionUnmarshaller.fromAssertion(authnStatementAssertion)).thenReturn(passthroughAuthnAssertion); InboundResponseFromIdp inboundResponseFromIdp = unmarshaller.fromSaml(new ValidatedResponse(response), new ValidatedAssertions(response.getAssertions())); assertThat(inboundResponseFromIdp.getSignature().isPresent()).isEqualTo(true); assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().isPresent()).isEqualTo(true); assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().isPresent()).isEqualTo(true); assertThat(inboundResponseFromIdp.getSignature().get()).isEqualTo(signature); assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().get()).isEqualTo(passthroughAuthnAssertion); assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().get()).isEqualTo(passthroughMdsAssertion); }