DAFileWriter implements DAWriter { public void end() throws IOException { writer.flush(); writer.close(); } 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(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Stream closed") public void end_closes_writer() throws Exception { FileContextTestImpl fileContext = new FileContextTestImpl(); new DAFileWriter(fileContext.getWriter()).end(); fileContext.getWriter().append("toto"); }