### Question:
LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); }  String escapeForLoadFile(String text);  }### Answer:
@Test public void testEscapeFieldTermination() { String text = "1234\tvalue\t5678\t"; String escaped = escaper.escapeForLoadFile(text); assertEquals("1234" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "value" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "5678" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); }
@Test public void testNoEscapeNeeded() { String text = "Some text with no escape neeed"; String escaped = escaper.escapeForLoadFile(text); assertEquals(text, escaped); }
@Test public void testEscapeEscapedByChar() { String text = "Some text with some \\ escape char \\\\ to change"; String escaped = escaper.escapeForLoadFile(text); assertEquals("Some text with some " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " escape char " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " to change", escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); }
@Test public void testEscapeLineTermination() { String text = "Some text with \nmore than one line\n"; String escaped = escaper.escapeForLoadFile(text); assertEquals("Some text with " + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR + "more than one line" + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); }