@Test
  public void testBuildersAndGenerics() {
    JavaFileObject javaFileObject =
        JavaFileObjects.forSourceLines(
            "foo.bar.Baz",
            "package foo.bar;",
            "",
            "import com.google.auto.value.AutoValue;",
            "import com.google.annotations.GwtCompatible;",
            "import com.google.common.collect.ImmutableMap;",
            "import java.util.Map;",
            "",
            "@AutoValue",
            "@GwtCompatible(serializable = true)",
            "public abstract class Baz<K extends Comparable<K>, V extends K> {",
            "  public abstract Map<K, V> map();",
            "  public abstract ImmutableMap<K, V> immutableMap();",
            "",
            "  public static <K extends Comparable<K>, V extends K> Builder<K, V> builder() {",
            "    return new AutoValue_Baz.Builder<K, V>();",
            "  }",
            "",
            "  @AutoValue.Builder",
            "  public interface Builder<K extends Comparable<K>, V extends K> {",
            "    Builder<K, V> map(Map<K, V> map);",
            "    ImmutableMap.Builder<K, V> immutableMapBuilder();",
            "    Baz<K, V> build();",
            "  }",
            "}");
    JavaFileObject expectedOutput =
        JavaFileObjects.forSourceLines(
            "foo.bar.AutoValue_Baz_CustomFieldSerializer",
            "package foo.bar;",
            "",
            "import com.google.common.collect.ImmutableMap;",
            "import com.google.gwt.user.client.rpc.CustomFieldSerializer;",
            "import com.google.gwt.user.client.rpc.SerializationException;",
            "import com.google.gwt.user.client.rpc.SerializationStreamReader;",
            "import com.google.gwt.user.client.rpc.SerializationStreamWriter;",
            "import java.util.Map;",
            "import " + generatedAnnotationType() + ";",
            "",
            "@Generated(\"com.google.auto.value.processor.AutoValueProcessor\")",
            "public final class AutoValue_Baz_CustomFieldSerializer"
                + "<K extends Comparable<K>, V extends K>"
                + " extends CustomFieldSerializer<AutoValue_Baz<K, V>> {",
            "",
            "  public static <K extends Comparable<K>, V extends K> AutoValue_Baz<K, V>"
                + " instantiate(",
            "      SerializationStreamReader streamReader) throws SerializationException {",
            "    @SuppressWarnings(\"unchecked\")",
            "    Map<K, V> map = (Map<K, V>) streamReader.readObject();",
            "    @SuppressWarnings(\"unchecked\")",
            "    ImmutableMap<K, V> immutableMap = (ImmutableMap<K, V>) streamReader.readObject();",
            "    AutoValue_Baz.Builder<K, V> builder$ = new AutoValue_Baz.Builder<K, V>();",
            "    builder$.map(map);",
            "    builder$.immutableMapBuilder().putAll(immutableMap);",
            "    return (AutoValue_Baz<K, V>) builder$.build();",
            "  }",
            "",
            "  public static <K extends Comparable<K>, V extends K> void serialize(",
            "      SerializationStreamWriter streamWriter,",
            "      AutoValue_Baz<K, V> instance) throws SerializationException {",
            "    streamWriter.writeObject(instance.map());",
            "    streamWriter.writeObject(instance.immutableMap());",
            "  }",
            "",
            "  public static <K extends Comparable<K>, V extends K> void deserialize(",
            "      @SuppressWarnings(\"unused\") SerializationStreamReader streamReader,",
            "      @SuppressWarnings(\"unused\") AutoValue_Baz<K, V> instance) {",
            "  }",
            "",
            "  @SuppressWarnings(\"unused\")",
            "  private int dummy_2865d9ec;",
            "",
            "  @Override",
            "  public void deserializeInstance(",
            "      SerializationStreamReader streamReader,",
            "      AutoValue_Baz<K, V> instance) {",
            "    deserialize(streamReader, instance);",
            "  }",
            "",
            "  @Override",
            "  public boolean hasCustomInstantiateInstance() {",
            "    return true;",
            "  }",
            "",
            "  @Override",
            "  public AutoValue_Baz<K, V> instantiateInstance(",
            "      SerializationStreamReader streamReader) throws SerializationException {",
            "    return instantiate(streamReader);",
            "  }",
            "",
            "  @Override",
            "  public void serializeInstance(",
            "    SerializationStreamWriter streamWriter,",
            "    AutoValue_Baz<K, V> instance) throws SerializationException {",
            "    serialize(streamWriter, instance);",
            "  }",
            "}");
    Compilation compilation =
        javac().withProcessors(new AutoValueProcessor()).compile(javaFileObject, GWT_COMPATIBLE);
    assertThat(compilation).succeededWithoutWarnings();
    assertThat(compilation)
        .generatedSourceFile("foo.bar.AutoValue_Baz_CustomFieldSerializer")
        .hasSourceEquivalentTo(expectedOutput);
  }
Test builders and classes that are generic (as opposed to just containing properties with
generics).
value/src/it/functional/src/test/java/com/google/auto/value/gwt/GwtCompilationTest.java