AccessLogger { @VisibleForTesting static StringBuilder escapeAndQuote(StringBuilder message, String input) { message.append('"'); boolean isEscaped = false; for (int i = 0; i < input.length(); i++) { final char c = input.charAt(i); if (c == '\\') { isEscaped = true; } else { if (c == '"' && !isEscaped) { message.append('\\'); } isEscaped = false; } message.append(c); } message.append('"'); return message; } private  AccessLogger();   }
@Test void testQuote() { assertThat(escapeAndQuote(new StringBuilder(), "a").toString()) .isEqualTo("\"a\""); assertThat(escapeAndQuote(new StringBuilder(), "\"a\"").toString()) .isEqualTo("\"\\\"a\\\"\""); assertThat(escapeAndQuote(new StringBuilder(), "\\\"a\\\"").toString()) .isEqualTo("\"\\\"a\\\"\""); assertThat(escapeAndQuote(new StringBuilder(), "\\\\\"a\\\\\"").toString()) .isEqualTo("\"\\\\\"a\\\\\"\""); assertThat(escapeAndQuote(new StringBuilder(), "\"\\\"a\\\"\"").toString()) .isEqualTo("\"\\\"\\\"a\\\"\\\"\""); }