public static String resolveUrl(String genericUrl, MessageParameters parameters) {
        Preconditions.checkState(
                parameters.isResolved(), "Not all mandatory message parameters were resolved.");
        StringBuilder path = new StringBuilder(genericUrl);
        StringBuilder queryParameters = new StringBuilder();

        for (MessageParameter<?> pathParameter : parameters.getPathParameters()) {
            if (pathParameter.isResolved()) {
                int start = path.indexOf(':' + pathParameter.getKey());

                final String pathValue =
                        Preconditions.checkNotNull(pathParameter.getValueAsString());

                // only replace path parameters if they are present
                if (start != -1) {
                    path.replace(start, start + pathParameter.getKey().length() + 1, pathValue);
                }
            }
        }
        boolean isFirstQueryParameter = true;
        for (MessageQueryParameter<?> queryParameter : parameters.getQueryParameters()) {
            if (queryParameter.isResolved()) {
                if (isFirstQueryParameter) {
                    queryParameters.append('?');
                    isFirstQueryParameter = false;
                } else {
                    queryParameters.append('&');
                }
                queryParameters.append(queryParameter.getKey());
                queryParameters.append('=');
                queryParameters.append(queryParameter.getValueAsString());
            }
        }
        path.append(queryParameters);

        return path.toString();
    }
@Test
    void testResolveUrl() {
        String genericUrl = "/jobs/:jobid/state";
        TestMessageParameters parameters = new TestMessageParameters();
        JobID pathJobID = new JobID();
        JobID queryJobID = new JobID();
        parameters.pathParameter.resolve(pathJobID);
        parameters.queryParameter.resolve(Collections.singletonList(queryJobID));

        String resolvedUrl = MessageParameters.resolveUrl(genericUrl, parameters);

        assertThat("/jobs/" + pathJobID + "/state?jobid=" + queryJobID).isEqualTo(resolvedUrl);
    }