WroUtil { public static String toJSMultiLineString(final String data) { final StringBuilder result = new StringBuilder("["); if (data != null) { final String[] lines = data.split("\n"); if (lines.length == 0) { result.append("\"\""); } for (int i = 0; i < lines.length; i++) { final String line = lines[i]; result.append("\""); result.append(line.replace(SEPARATOR_WINDOWS, "\\\\").replace("\"", "\\\"").replaceAll("\\r|\\n", "")); if (lines.length == 1) { result.append("\\n"); } result.append("\""); if (i < lines.length - 1) { result.append(","); } } } result.append("].join(\"\\n\")"); return result.toString(); } private  WroUtil(); static ThreadFactory createDaemonThreadFactory(final String name); static String toDateAsString(final long milliseconds); static String getPathInfoFromLocation(final HttpServletRequest request, final String location); static boolean startsWithIgnoreCase(final String str, final String prefix); static String toPackageAsFolder(final Class<?> clazz); static String getServletPathFromLocation(final HttpServletRequest request, final String location); @SuppressWarnings("unchecked") static boolean isGzipSupported(final HttpServletRequest request); static String toJSMultiLineString(final String data); static boolean matchesUrl(final HttpServletRequest request, final String path); static ResourcePostProcessor newResourceProcessor(final Resource resource,
      final ResourcePreProcessor preProcessor); static WroModelFactory factoryFor(final WroModel model); static ObjectFactory<T> simpleObjectFactory(final T object); static String loadRegexpWithKey(final String key); static String getImplementationVersion(); static void safeCopy(final Reader reader, final Writer writer); static File createTempFile(); static File createTempFile(final String extension); static File createTempDirectory(); static String joinPath(final String left, final String right); static final String cleanImageUrl(final String imageUrl); static final String removeQueryString(final String path); static final File getWorkingDirectory(); static final String getFullPath(final String path); static final String normalize(final String path); static final Pattern EMTPY_LINE_PATTERN; static final InputStream EMPTY_STREAM; }
@Test public void testToJsMultilineString() { assertEquals("[\"\\n\"].join(\"\\n\")", WroUtil.toJSMultiLineString("")); assertEquals("[\"alert1\\n\"].join(\"\\n\")", WroUtil.toJSMultiLineString("alert1")); assertEquals("[\"\",\"alert1\",\"alert2\"].join(\"\\n\")", WroUtil.toJSMultiLineString("\nalert1\nalert2")); }
@Test public void shouldCreateMultiLineFromNullString() { assertEquals("[].join(\"\\n\")", WroUtil.toJSMultiLineString(null)); }