### Question:
AuthnRequestFromRelyingPartyUnmarshaller { public AuthnRequestFromRelyingParty fromSamlMessage(AuthnRequest authnRequest) { final String id = authnRequest.getID(); final String issuerId = authnRequest.getIssuer().getValue(); final DateTime issueInstant = authnRequest.getIssueInstant(); final Boolean forceAuthn = authnRequest.isForceAuthn(); final Optional<String> assertionConsumerServiceURL = Optional.ofNullable(authnRequest.getAssertionConsumerServiceURL()); final Integer assertionConsumerServiceIndex = authnRequest.getAssertionConsumerServiceIndex(); final Signature signature = authnRequest.getSignature(); final Optional<String> verifyServiceProviderVersion = extractVerifyServiceProviderVersion(authnRequest.getExtensions(), issuerId); return new AuthnRequestFromRelyingParty( id, issuerId, issueInstant, URI.create(authnRequest.getDestination()), Optional.ofNullable(forceAuthn), assertionConsumerServiceURL.map(URI::create), ofNullable(assertionConsumerServiceIndex), ofNullable(signature), verifyServiceProviderVersion ); } AuthnRequestFromRelyingPartyUnmarshaller(Decrypter decrypter); AuthnRequestFromRelyingParty fromSamlMessage(AuthnRequest authnRequest);  }### Answer:
@Test public void fromSamlMessage_shouldMapAuthnRequestToAuthnRequestFromRelyingParty() throws Exception { DateTime issueInstant = new DateTime(); SignatureImpl signature = new SignatureBuilder().buildObject(); AuthnRequest authnRequest = new AuthnRequestBuilder().buildObject(); authnRequest.setID("some-id"); Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue("some-service-entity-id"); authnRequest.setIssuer(issuer); authnRequest.setIssueInstant(issueInstant); authnRequest.setDestination("http: authnRequest.setForceAuthn(true); authnRequest.setAssertionConsumerServiceURL("some-url"); authnRequest.setAssertionConsumerServiceIndex(5); authnRequest.setSignature(signature); authnRequest.setExtensions(createApplicationVersionExtensions("some-version")); AuthnRequestFromRelyingParty authnRequestFromRelyingParty = unmarshaller.fromSamlMessage(authnRequest); AuthnRequestFromRelyingParty expected = new AuthnRequestFromRelyingParty( "some-id", "some-service-entity-id", issueInstant, URI.create("http: Optional.of(true), Optional.of(URI.create("some-url")), Optional.of(5), Optional.of(signature), Optional.of("some-version") ); assertThat(authnRequestFromRelyingParty).isEqualTo(expected); }
@Test public void fromSamlMessage_shouldNotComplainWhenThereIsNoExtensionsElement() throws Exception { AuthnRequest authnRequest = new AuthnRequestBuilder().buildObject(); authnRequest.setIssuer(new IssuerBuilder().buildObject()); authnRequest.setDestination("http: AuthnRequestFromRelyingParty authnRequestFromRelyingParty = unmarshaller.fromSamlMessage(authnRequest); assertThat(authnRequestFromRelyingParty.getVerifyServiceProviderVersion()).isEqualTo(Optional.empty()); }
@Test public void fromSamlMessage_shouldNotComplainWhenExceptionDuringDecryption() throws Exception { AuthnRequest authnRequest = new AuthnRequestBuilder().buildObject(); authnRequest.setIssuer(new IssuerBuilder().buildObject()); authnRequest.setDestination("http: authnRequest.setExtensions(createApplicationVersionExtensions(null)); AuthnRequestFromRelyingParty authnRequestFromRelyingParty = unmarshaller.fromSamlMessage(authnRequest); assertThat(authnRequestFromRelyingParty.getVerifyServiceProviderVersion()).isEqualTo(Optional.empty()); }