### Question:
Escape { static String escape(String original) { final var sb = new StringBuilder(original); final var output = new StringBuilder(); final var ignored = new StringBuilder(); while (sb.length() > 0) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output, ignored); } else { output.append(ch); sb.deleteCharAt(0); } } return output.toString(); }    }### Answer:
@Test @DisplayName("Method escape replaces the usual escape sequences to their corresponding character") void testUsualEscape() { assertThat(Escape.escape("new line\\nline feed\\rtab-character\\t" + "backspace\\bform-feed\\fbackslash\\\\" + "apostrophe\\'quote\\\"")) .isEqualTo("new line\nline feed\rtab-character\t" + "backspace\bform-feed\fbackslash\\" + "apostrophe'quote\""); }
@Test @DisplayName("Method escape replaces the ocatal escape sequences to their corresponding character") void testOctalEscape() { for (int i = 1; i < 256; i++) { int k = i; String oct = ""; while (k > 0) { oct = "" + k % 8 + oct; k /= 8; } assertThat(Escape.escape("this is a \\" + oct + " octal char")) .isEqualTo("this is a " + Character.toString((char)i) + " octal char"); } }
@Test @DisplayName("Method escape throws an exception when escape sequence is invalid") void testInvalidEscape() { assertThatThrownBy(() -> Escape.escape("wuff \\k invalid")) .isInstanceOf(IllegalArgumentException.class); }
@Test @DisplayName("Method escape throws an exception when escape char is at the last position") void testEscapeAtLastPosition() { assertThatThrownBy(() -> Escape.escape("wuff \\")) .isInstanceOf(IllegalArgumentException.class); }