public void validate(final Metric metric) {
        if (metric == null) {
            throw new ValidationException("Metric cannot be null");
        }
        if (!isValidFunction(metric.functionName())) {
            throw new ValidationException("Unrecognized metric : " + metric.functionName() + ", valid metrics : " + availableMetricTypes);
        }
        if (!hasFieldIfFunctionNeedsIt(metric)) {
            throw new ValidationException(metric.functionName() + " metric requires field name to be provided after a colon, i.e. " + metric.functionName() + ":http_status_code");
        }
        if (metric.sort() != null && UNSORTABLE_METRICS.contains(metric.functionName())) {
            throw new ValidationException(metric.functionName() + " metric cannot be used to sort aggregations");
        }
    }
@Test
    void throwsExceptionWhenTryingToSortOnUnsortableMetrics() {
        assertThrows(ValidationException.class, () -> toTest.validate(new Metric("latest", "source", SortSpec.Direction.Ascending, null)));
        assertThrows(ValidationException.class, () -> toTest.validate(new Metric("percentile", "source", SortSpec.Direction.Descending, new PercentileConfiguration(25.0d))));
    }