### Question:
CountryAuthnRequestGeneratorService { public SamlRequestDto generateSaml(IdaAuthnRequestFromHubDto idaAuthnRequestFromHubDto) { URI ssoUri = idaAuthnRequestFromHubDto.getoverriddenSsoUrl() != null ? idaAuthnRequestFromHubDto.getoverriddenSsoUrl() : countrySingleSignOnServiceHelper.getSingleSignOn(idaAuthnRequestFromHubDto.getIdpEntityId()); EidasAuthnRequestFromHub eidasAuthnRequestFromHub = eidasAuthnRequestTranslator.getEidasAuthnRequestFromHub(idaAuthnRequestFromHubDto, ssoUri, hubEidasEntityId); String request = eidasRequestStringTransformer.apply(eidasAuthnRequestFromHub); return new SamlRequestDto(request, ssoUri); } @Inject  CountryAuthnRequestGeneratorService(CountrySingleSignOnServiceHelper countrySingleSignOnServiceHelper,
                                               Function<EidasAuthnRequestFromHub, String> eidasRequestStringTransformer,
                                               EidasAuthnRequestTranslator eidasAuthnRequestTranslator,
                                               String hubEidasEntityId); SamlRequestDto generateSaml(IdaAuthnRequestFromHubDto idaAuthnRequestFromHubDto);  }### Answer:
@Test public void generateSamlRequest() { String theCountryEntityId = "theCountryEntityId"; IdaAuthnRequestFromHubDto dto = new IdaAuthnRequestFromHubDto("1", null, Optional.of(false), null, theCountryEntityId, false); URI ssoUri = UriBuilder.fromPath("/the-sso-uri").build(); String samlRequest = "samlRequest"; EidasAuthnRequestFromHub eidasAuthnRequestFromHub = new EidasAuthnRequestBuilder().buildFromHub(); when(eidasAuthnRequestFromHubStringTransformer.apply(any())).thenReturn(samlRequest); when(countrySingleSignOnServiceHelper.getSingleSignOn(theCountryEntityId)).thenReturn(ssoUri); when(eidasAuthnRequestTranslator.getEidasAuthnRequestFromHub(dto, ssoUri, HUB_ENTITY_ID)).thenReturn(eidasAuthnRequestFromHub); final SamlRequestDto output = service.generateSaml(dto); assertThat(output.getSamlRequest()).isEqualTo(samlRequest); assertThat(output.getSsoUri()).isEqualTo(ssoUri); verify(countrySingleSignOnServiceHelper).getSingleSignOn(theCountryEntityId); verify(eidasAuthnRequestFromHubStringTransformer).apply(any(EidasAuthnRequestFromHub.class)); verifyNoMoreInteractions(countrySingleSignOnServiceHelper, eidasAuthnRequestFromHubStringTransformer); }
@Test public void generateSamlRequestWithOverriddenSsoUri() { String theCountryEntityId = "theCountryEntityId"; URI overriddenSsoURI = URI.create("http: IdaAuthnRequestFromHubDto dto = new IdaAuthnRequestFromHubDto("1", null, Optional.of(false), null, theCountryEntityId, false, overriddenSsoURI); String samlRequest = "samlRequest"; when(eidasAuthnRequestFromHubStringTransformer.apply(any())).thenReturn(samlRequest); final SamlRequestDto output = service.generateSaml(dto); assertThat(output.getSamlRequest()).isEqualTo(samlRequest); assertThat(output.getSsoUri()).isEqualTo(overriddenSsoURI); verifyNoMoreInteractions(countrySingleSignOnServiceHelper); }