### Question:
MatchingServiceResponseService { public void handleSuccessResponse(SessionId sessionId, SamlResponseDto samlResponse) { getSessionIfItExists(sessionId); SamlResponseContainerDto samlResponseContainer = new SamlResponseContainerDto( samlResponse.getSamlResponse(), sessionRepository.getRequestIssuerEntityId(sessionId) ); try { InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = samlEngineProxy.translateMatchingServiceResponse(samlResponseContainer); updateSessionState(sessionId, inboundResponseFromMatchingServiceDto); } catch(ApplicationException e) { logExceptionAndUpdateState("Error translating matching service response", sessionId, e); } } @Inject  MatchingServiceResponseService(SamlEngineProxy samlEngineProxy,
                                          SessionRepository sessionRepository,
                                          HubEventLogger eventLogger); void handleFailure(SessionId sessionId); void handleSuccessResponse(SessionId sessionId, SamlResponseDto samlResponse);  }### Answer:
@Test(expected = SessionNotFoundException.class) public void handle_shouldThrowExceptionIfSessionDoesNotExist() { when(sessionRepository.sessionExists(sessionId)).thenReturn(false); matchingServiceResponseService.handleSuccessResponse(sessionId, samlResponseDto); }
@Test public void handle_shouldLogToEventSinkAndNotifyPolicyOnRequesterError() { final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(MatchingServiceIdaStatus.RequesterError, inResponseTo, "issuer", Optional.empty(), Optional.empty()); when(samlEngineProxy.translateMatchingServiceResponse(any())).thenReturn(inboundResponseFromMatchingServiceDto); matchingServiceResponseService.handleSuccessResponse(sessionId, samlResponseDto); verify(waitingForMatchingServiceResponseStateController, times(1)).handleRequestFailure(); verify(eventLogger).logErrorEvent(format("Requester error in response from matching service for session {0}", sessionId), sessionId); }
@Test public void handle_shouldUpdateStateWhenSamlProxyCannotProcessSaml() { when(samlEngineProxy.translateMatchingServiceResponse(any())).thenThrow(ApplicationException.createAuditedException(ExceptionType.INVALID_SAML, UUID.randomUUID())); matchingServiceResponseService.handleSuccessResponse(sessionId, samlResponseDto); verify(waitingForMatchingServiceResponseStateController, times(1)).handleRequestFailure(); verify(eventLogger).logErrorEvent("Error translating matching service response", sessionId); }