### Question:
SessionService { public AuthnResponseFromHubContainerDto getRpAuthnResponse(SessionId sessionId) { getSessionIfItExists(sessionId); if (authnRequestHandler.isResponseFromCountryWithUnsignedAssertions(sessionId)) { AuthnResponseFromCountryContainerDto authResponseFromCountryContainerDto = authnRequestHandler.getAuthnResponseFromCountryContainerDto(sessionId); return samlEngineProxy.generateRpAuthnResponseWrappingCountrySaml(authResponseFromCountryContainerDto); } ResponseFromHub responseFromHub = authnRequestHandler.getResponseFromHub(sessionId); return samlEngineProxy.generateRpAuthnResponse(responseFromHub); } @Inject  SessionService(SamlEngineProxy samlEngineProxy,
                          TransactionsConfigProxy configProxy,
                          AuthnRequestFromTransactionHandler authnRequestHandler,
                          SessionRepository sessionRepository); SessionId create(final SamlAuthnRequestContainerDto requestDto); SessionId getSessionIfItExists(SessionId sessionId); Optional<LevelOfAssurance> getLevelOfAssurance(SessionId sessionId); AuthnRequestFromHubContainerDto getIdpAuthnRequest(SessionId sessionId); AuthnResponseFromHubContainerDto getRpAuthnResponse(SessionId sessionId); AuthnResponseFromHubContainerDto getRpErrorResponse(SessionId sessionId);  }### Answer:
@Test(expected = SessionNotFoundException.class) public void shouldThrowSessionNotFoundWhenSessionDoesNotExistAndAResponseFromHubIsRequested() { SessionId sessionId = createNewSessionId(); when(sessionRepository.sessionExists(sessionId)).thenReturn(false); service.getRpAuthnResponse(sessionId); }
@Test public void shouldUpdateSessionStateAndCallSamlEngineWhenResponseFromHubIsRequested() { SessionId sessionId = createNewSessionId(); when(sessionRepository.sessionExists(sessionId)).thenReturn(true); ResponseFromHub responseFromHub = aResponseFromHubDto().build(); when(authnRequestHandler.getResponseFromHub(sessionId)).thenReturn(responseFromHub); AuthnResponseFromHubContainerDto expected = anAuthnResponseFromHubContainerDto().build(); when(samlEngineProxy.generateRpAuthnResponse(responseFromHub)).thenReturn(expected); AuthnResponseFromHubContainerDto actual = service.getRpAuthnResponse(sessionId); assertThat(actual).isEqualTo(expected); }
@Test public void shouldCallSamlEngineCountrySamlAuthnResponseGenerationEndpointIfIsResponseFromCountry() { ArgumentCaptor<AuthnResponseFromCountryContainerDto> capturedDto = ArgumentCaptor.forClass(AuthnResponseFromCountryContainerDto.class); AuthnResponseFromCountryContainerDto authnResponseFromCountryContainerDto = anAuthnResponseFromCountryContainerDto().build(); SessionId sessionId = createNewSessionId(); when(sessionRepository.sessionExists(sessionId)).thenReturn(true); when(authnRequestHandler.isResponseFromCountryWithUnsignedAssertions(sessionId)).thenReturn(true); when(authnRequestHandler.getAuthnResponseFromCountryContainerDto(sessionId)).thenReturn(authnResponseFromCountryContainerDto); service.getRpAuthnResponse(sessionId); verify(samlEngineProxy).generateRpAuthnResponseWrappingCountrySaml(capturedDto.capture()); assertThat(capturedDto.getValue()).isEqualTo(authnResponseFromCountryContainerDto); }