static String getErrorKey(Sample sample) {
        if (sample.getSuccess()) {
            return "";
        }
        String responseCode = sample.getResponseCode();
        String responseMessage = sample.getResponseMessage();
        String key = responseCode + (!StringUtils.isEmpty(responseMessage) ?
                 "/" + escapeJson(responseMessage) : "");

        if (MetricUtils.isSuccessCode(responseCode) ||
                (StringUtils.isEmpty(responseCode) &&
                   StringUtils.isNotBlank(sample.getFailureMessage()))) {
            key = MetricUtils.ASSERTION_FAILED;
            if (ASSERTION_RESULTS_FAILURE_MESSAGE) {
                String msg = sample.getFailureMessage();
                if (StringUtils.isNotBlank(msg)) {
                    key = escapeJson(msg);
                }
            }
        }
        return key;
    }
@Test
    public void testGetErrorKey() {
        SampleMetadata metadata = new SampleMetadata(',', new String[] { CSVSaveService.SUCCESSFUL,
                CSVSaveService.RESPONSE_CODE, CSVSaveService.RESPONSE_MESSAGE, CSVSaveService.FAILURE_MESSAGE });
        Sample sample = new Sample(0, metadata, new String[] { "false", "", "", "FailureMessage" });
        assertEquals("FailureMessage", ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "200", "", "FailureMessage" });
        assertEquals("FailureMessage", ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "200", "", "" });
        assertEquals(MetricUtils.ASSERTION_FAILED, ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "200", "",
                "Test failed: text expected to contain /<title>Some html text</title>/" });
        assertEquals("Test failed: text expected to contain /&lt;title&gt;Some html text&lt;/title&gt;/",
                ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "200", "",
                "Test failed: text expected to contain /{\"glossary\": { \"title\": \"example glossary\"}}/" });
        assertEquals("Test failed: text expected to contain /{&quot;glossary&quot;: { &quot;title&quot;: &quot;example glossary&quot;}}/",
                ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "true", "200", "", "" });
        assertEquals("", ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "403", "", "" });
        assertEquals("403", ErrorsSummaryConsumer.getErrorKey(sample));

        sample = new Sample(0, metadata, new String[] { "false", "500", "Server Error", "" });
        assertEquals("500/Server Error", ErrorsSummaryConsumer.getErrorKey(sample));
    }