DAFileWriter implements DAWriter { public DAFileWriter appendImports(@Nonnull Collection<DAImport> mapperImports) throws IOException { checkNotNull(mapperImports, "Collection of imports can not be null"); if (mapperImports.isEmpty()) { return this; } List<DAName> imports = removeDuplicatesFilterJavaLangAndSortImports(mapperImports); if (imports.isEmpty()) { this.importQualifiedNames = Collections.emptySet(); this.importSimpleNames = Collections.emptySet(); return this; } this.importQualifiedNames = from(mapperImports) .transform(DAImportFunctions.toQualifiedName()) .filter(notNull()) .toSet(); this.importSimpleNames = from(mapperImports).transform(DAImportFunctions.toSimpleName()) .filter(notNull()) .toSet(); for (DAName name : imports) { writer.append("import ").append(name).append(";"); writer.newLine(); } writer.newLine(); return this; } DAFileWriter(BufferedWriter writer); DAFileWriter appendPackage(@Nonnull DAName packageName); DAFileWriter appendImports(@Nonnull Collection<DAImport> mapperImports); DAFileWriter appendGeneratedAnnotation(@Nonnull Class<? extends Processor> processClass); DAFileWriter appendGeneratedAnnotation(@Nonnull String annotationProcessorQualifiedName); DAClassWriter<DAFileWriter> newClass(DAType classType); DAInterfaceWriter<DAFileWriter> newInterface(String name); void end();  }
@Test public void appendImports_emptyCollection_prints_nothing() throws Exception { FileContextTestImpl fileContext = new FileContextTestImpl(); new DAFileWriter(fileContext.getWriter()).appendImports(Collections.<DAImport>emptyList()); assertThat(fileContext.getRes()).isEqualTo(""); }
@Test public void appendImports_emptyCollection_after_filtering_prints_nothing() throws Exception { FileContextTestImpl fileContext = new FileContextTestImpl(); new DAFileWriter(fileContext.getWriter()).appendImports( ImmutableList.of(DAImportImpl.from(DANameFactory.from(String.class.getName()))) ); assertThat(fileContext.getRes()).isEqualTo(""); }
@Test public void appendImports_filters_out_null_DAName_when_no_package_is_specified() throws Exception { FileContextTestImpl fileContext = new FileContextTestImpl(); new DAFileWriter(fileContext.getWriter()) .appendImports(Collections.singletonList((DAImport) null)); assertThat(fileContext.getRes()).isEqualTo(""); }