public String generateRedirectUrl(String artifact, String transactionId, String sessionId, BvdStatus status) throws SamlSessionException, UnsupportedEncodingException {
        final var samlSession = findSamlSessionByArtifactOrTransactionId(artifact, transactionId);

        if (CANCELLED.equals(status))
            samlSession.setBvdStatus(AdAuthenticationStatus.STATUS_CANCELED.label);
        if (ERROR.equals(status))
            samlSession.setBvdStatus(AdAuthenticationStatus.STATUS_FAILED.label);

        if (artifact == null)
            artifact = samlSession.getArtifact();

        if (sessionId == null || !sessionId.equals(samlSession.getHttpSessionId()))
            throw new SamlSessionException("Saml session found with invalid sessionId for redirect_with_artifact");

        var url = new StringBuilder(samlSession.getAssertionConsumerServiceURL() + "?SAMLart=" + URLEncoder.encode(artifact, "UTF-8"));

        // append relay-state
        if (samlSession.getRelayState() != null)
            url.append("&RelayState=" + URLEncoder.encode(samlSession.getRelayState(), "UTF-8"));

        samlSession.setResolveBeforeTime(System.currentTimeMillis() + 1000 * 60 * minutesToResolve);
        samlSessionRepository.save(samlSession);
        return url.toString();
    }
@Test
    void redirectWithWrongArtifact() {
        when(samlSessionRepositoryMock.findByArtifact(anyString())).thenReturn(Optional.empty());

        Exception exception = assertThrows(SamlSessionException.class,
                () -> assertionConsumerServiceUrlService.generateRedirectUrl("IncorrectArtifact", null, "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", null));

        assertEquals("Saml session not found by artifact/transactionid for redirect_with_artifact", exception.getMessage());

    }