EclipseJsFormatterStepImpl { public String format(String raw) throws Exception { raw = formatComments(raw); IDocument doc = new Document(raw); TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, LINE_DELIMITER); if (edit == null) { throw new IllegalArgumentException("Invalid JavaScript syntax for formatting."); } else { edit.apply(doc); } return doc.get(); } EclipseJsFormatterStepImpl(Properties properties); String format(String raw);  }
@Test(expected = IllegalArgumentException.class) public void invalidSyntax() throws Exception { try { formatter.format(UNFORMATTED.replace("()", "")); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("Exception has no hint about invalid syntax.").contains(Arrays.asList("Invalid", "syntax")); throw e; } }
@Test public void illegalCharacter() throws Exception { String output = formatter.format(UNFORMATTED.replace("function", "function" + ILLEGAL_CHAR)); assertThat(output).as("Illegal ASCII charactes are not treated on best effort basis.").contains("function" + ILLEGAL_CHAR); }
@Test public void nominal() throws Exception { String output = formatter.format(UNFORMATTED); assertEquals("User configuration ignored by formatter.", FORMATTED, output); }