@Override
  public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements)
      throws IOException {
    return new FormattingJavaFileObject(
        delegate.createSourceFile(name, originatingElements), formatter, messager);
  }
@Test
  public void formatsFile() throws IOException {
    FormattingFiler formattingFiler = new FormattingFiler(new FakeFiler());
    JavaFileObject sourceFile = formattingFiler.createSourceFile("foo.Bar");
    try (Writer writer = sourceFile.openWriter()) {
      writer.write("package foo;class Bar{private String      baz;\n\n\n\n}");
    }

    assertThat(sourceFile.getCharContent(false).toString())
        .isEqualTo(
            Joiner.on('\n')
                .join(
                    "package foo;",
                    "",
                    "class Bar {",
                    "  private String baz;",
                    "}",
                    "")); // trailing newline
  }