### Question:
ImportStatements { @Override public String toString() { if (importStrings.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); if (!hasExistingImports) { result.append('\n'); } List<ImportOrganizer.Import> imports = importStrings.stream().map(ImportOrganizer.Import::importOf).collect(Collectors.toList()); ImportOrganizer.OrganizedImports organizedImports = importOrganizer.organizeImports(imports); int expectedImportCount = imports.size(); int importCount = organizedImports.getImportCount(); if (importCount != expectedImportCount) { throw new IllegalStateException( String.format( "Expected %d import(s) in the organized imports but it contained %d", expectedImportCount, importCount)); } result.append(organizedImports.asImportBlock()); String replacementString = result.toString(); if (!hasExistingImports) { return replacementString; } else { return CharMatcher.whitespace().trimTrailingFrom(replacementString); } } ImportStatements(
      JCExpression packageTree,
      List<JCImport> importTrees,
      EndPosTable endPositions,
      ImportOrganizer importOrganizer); static ImportStatements create(JCCompilationUnit compilationUnit); static ImportStatements create(
      JCCompilationUnit compilationUnit, ImportOrganizer importOrganizer); int getStartPos(); int getEndPos(); boolean add(String importToAdd); boolean addAll(Collection<String> importsToAdd); boolean remove(String importToRemove); boolean removeAll(Collection<String> importsToRemove); boolean importsHaveChanged(); @Override String toString();  }### Answer:
@Test public void shouldSortImports() { ImportStatements imports = createImportStatements(basePackage, baseImportList); assertThat(imports.toString()) .isEqualTo( "import static com.google.ads.pebl.AdGroupCriterionPredicate.PAUSED;\n" + "import static com.google.common.base.Preconditions.checkNotNull;\n" + "\n" + "import com.google.common.collect.ImmutableList;\n" + "import com.google.common.collect.ImmutableMap;\n" + "import com.sun.source.tree.CompilationUnitTree;\n" + "import com.sun.source.tree.ImportTree;\n" + "import com.sun.tools.javac.tree.JCTree;\n" + "import com.sun.tools.javac.tree.JCTree.JCExpression;\n" + "import java.io.File;\n" + "import java.io.IOException;\n" + "import java.util.Iterator;\n" + "import javax.tools.JavaCompiler;\n" + "import javax.tools.JavaFileObject;\n" + "import javax.tools.StandardJavaFileManager;\n" + "import javax.tools.ToolProvider;\n" + "import org.joda.time.DateTime;\n" + "import org.joda.time.DateTimeZone;\n" + "import org.joda.time.Interval;"); }