byte[] createErrorContent(String requestUri, int statusCode, String message) {
        String sanitizedString = message != null ? StringUtil.sanitizeXmlString(message) : "";
        String statusCodeString = Integer.toString(statusCode);
        writer.resetWriter();
        try {
            writer.write("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n<title>Error ");
            writer.write(statusCodeString);
            writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: ");
            writer.write(statusCodeString);
            writer.write("</h2>\n<p>Problem accessing ");
            writer.write(StringUtil.sanitizeXmlString(requestUri));
            writer.write(". Reason:\n<pre>    ");
            writer.write(sanitizedString);
            writer.write("</pre></p>\n<hr/>\n</body>\n</html>\n");
        } catch (IOException e) {
            // IOException should not be thrown unless writer is constructed using byte[] parameter
            throw new RuntimeException(e);
        }
        return writer.getByteArray();
    }
@Test
    void response_content_matches_expected_string() {
        String expectedHtml =
                "<html>\n" +
                        "<head>\n" +
                        "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n" +
                        "<title>Error 200</title>\n" +
                        "</head>\n" +
                        "<body>\n" +
                        "<h2>HTTP ERROR: 200</h2>\n" +
                        "<p>Problem accessing http://foo.bar. Reason:\n" +
                        "<pre>    My custom error message</pre></p>\n" +
                        "<hr/>\n" +
                        "</body>\n" +
                        "</html>\n";

        ErrorResponseContentCreator c = new ErrorResponseContentCreator();
        byte[] rawContent = c.createErrorContent(
                "http://foo.bar",
                HttpServletResponse.SC_OK,
                "My custom error message");
        String actualHtml = new String(rawContent, StandardCharsets.ISO_8859_1);
        assertEquals(expectedHtml, actualHtml);
    }