Formatter { public String formatSourceAndFixImports(String input) throws FormatterException { input = ImportOrderer.reorderImports(input, options.style()); input = RemoveUnusedImports.removeUnusedImports(input); String formatted = formatSource(input); formatted = StringWrapper.wrap(formatted, this); return formatted; } Formatter();  Formatter(JavaFormatterOptions options); void formatSource(CharSource input, CharSink output); String formatSource(String input); String formatSourceAndFixImports(String input); String formatSource(String input, Collection<Range<Integer>> characterRanges); ImmutableList<Replacement> getFormatReplacements(
      String input, Collection<Range<Integer>> characterRanges); static RangeSet<Integer> lineRangesToCharRanges(
      String input, RangeSet<Integer> lineRanges); static final int MAX_LINE_LENGTH; }
@Test public void importsFixedIfRequested() throws FormatterException { String input = "package com.google.example;\n" + UNORDERED_IMPORTS + "\npublic class ExampleTest {\n" + " @Nullable List<?> xs;\n" + "}\n"; String output = new Formatter().formatSourceAndFixImports(input); String expect = "package com.google.example;\n\n" + "import java.util.List;\n" + "import javax.annotations.Nullable;\n\n" + "public class ExampleTest {\n" + " @Nullable List<?> xs;\n" + "}\n"; assertThat(output).isEqualTo(expect); }
@Test public void throwsFormatterException() throws Exception { try { new Formatter().formatSourceAndFixImports("package foo; public class {"); fail(); } catch (FormatterException expected) { } }