EclipseJdtFormatterStepImpl { public String format(String raw) throws Exception { TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, raw, 0, raw.length(), 0, SpotlessEclipseFramework.LINE_DELIMITER); if (edit == null) { throw new IllegalArgumentException("Invalid java syntax for formatting."); } else { IDocument doc = new Document(raw); edit.apply(doc); return doc.get(); } } EclipseJdtFormatterStepImpl(Properties settings); String format(String raw);  }
@Test public void defaultFormat() throws Throwable { String output = format(UNFORMATTED, config -> {}); assertEquals("Unexpected formatting with default preferences.", FORMATTED, output); }
@Test public void invalidCharater() throws Throwable { String output = format(FORMATTED.replace("void hello() {", "void hello()" + ILLEGAL_CHAR + " {"), config -> {}); assertTrue("Invalid charater not formatted on best effort basis.", output.contains("void hello()" + ILLEGAL_CHAR + " {" + LINE_DELIMITER)); }
@Test public void invalidConfiguration() throws Throwable { String output = format(FORMATTED, config -> { config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "noInteger"); }); assertEquals("Invalid indentation configuration not replaced by default value (4 spaces)", FORMATTED.replace("\t", " "), output); }
@Test public void internalCodeFormatter() throws Throwable { String output = format(PRE_UNFORMATTED + UNFORMATTED, config -> { config.setProperty( DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.TRUE); }); assertEquals("Code within HTML <pre> tag not formatted.", PRE_FORMATTED + FORMATTED, output); }