### Question:
SessionService { public AuthnResponseFromHubContainerDto getRpErrorResponse(SessionId sessionId) { getSessionIfItExists(sessionId); final ResponseFromHub errorResponseFromHub = authnRequestHandler.getErrorResponseFromHub(sessionId); final RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto = new RequestForErrorResponseFromHubDto(errorResponseFromHub.getAuthnRequestIssuerEntityId(), errorResponseFromHub.getResponseId(), errorResponseFromHub.getInResponseTo(), errorResponseFromHub.getAssertionConsumerServiceUri(), errorResponseFromHub.getStatus()); final SamlMessageDto samlMessageDto = samlEngineProxy.generateErrorResponseFromHub(requestForErrorResponseFromHubDto); final AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlMessageDto.getSamlMessage(), errorResponseFromHub.getAssertionConsumerServiceUri(), errorResponseFromHub.getRelayState(), errorResponseFromHub.getResponseId()); return authnResponseFromHubContainerDto; } @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 = ApplicationException.class) public void sendErrorResponseFromHub_shouldErrorWhenSamlEngineProxyReturnsAnError() { SessionId sessionId = createNewSessionId(); when(sessionRepository.sessionExists(sessionId)).thenReturn(true); ResponseFromHub responseFromHub = aResponseFromHubDto().withRelayState("relayState").build(); when(authnRequestHandler.getErrorResponseFromHub(sessionId)).thenReturn(responseFromHub); when(samlEngineProxy.generateErrorResponseFromHub(any())).thenThrow(ApplicationException.createAuditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID())); service.getRpErrorResponse(sessionId); }