FormatUtils { public static String formatString(Object value) { return "\"" + String.valueOf(value).replaceAll("\\\\", "\\\\\\\\") .replaceAll("\n","\\\\n") .replaceAll("\r","\\\\r") .replaceAll("\t","\\\\t") .replaceAll("\"","\\\\\"") + "\""; }  static String formatNumber(Number value); static String formatString(Object value); static String joinLabels(Node node, String delimiter); static Map<String,Object> toMap(Entity pc); static String toString(Object value); static String formatPoint(Point value); static List<String> getLabelsSorted(Node node);  }
@Test public void formatString() throws Exception { assertEquals("\"\\n\"",FormatUtils.formatString("\n")); assertEquals("\"\\t\"",FormatUtils.formatString("\t")); assertEquals("\"\\\"\"",FormatUtils.formatString("\"")); assertEquals("\"\\\\\"",FormatUtils.formatString("\\")); assertEquals("\"\\n\"",FormatUtils.formatString('\n')); assertEquals("\"\\t\"",FormatUtils.formatString('\t')); assertEquals("\"\\\"\"",FormatUtils.formatString('"')); assertEquals("\"\\\\\"",FormatUtils.formatString('\\')); }