com.google.auto.value.processor.AutoValueProcessor Java Examples

The following examples show how to use com.google.auto.value.processor.AutoValueProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 6 votes vote down vote up
@Test
public void unsupported() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int[] a();\n"
            + "  public abstract String b();\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .failsToCompile()
            .withErrorContaining("Property has type that can't be read from Cursor.");
}
 
Example #2
Source File: PaperParcelAutoValueExtensionTest.java    From paperparcel with Apache License 2.0 6 votes vote down vote up
@Test public void failWhenWriteToParcelAlreadyDefinedTest() throws Exception {
  JavaFileObject source =
      JavaFileObjects.forSourceString("test.Test", Joiner.on('\n').join(
          "package test;",
          "import com.google.auto.value.AutoValue;",
          "import android.os.Parcel;",
          "import android.os.Parcelable;",
          "@AutoValue",
          "public abstract class Test implements Parcelable {",
          "  public abstract int count();",
          "  @Override",
          "  public void writeToParcel(Parcel dest, int flags) {",
          "  }",
          "}"
      ));

  assertAbout(javaSource()).that(source)
      .processedWith(new PaperParcelProcessor(), new AutoValueProcessor())
      .failsToCompile()
      .withErrorContaining(String.format(ErrorMessages.MANUAL_IMPLEMENTATION_OF_WRITE_TO_PARCEL,
          "test.Test"))
      .in(source)
      .onLine(9);
}
 
Example #3
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 6 votes vote down vote up
@Test
public void wrongReturnType() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract String a();\n"
            + "  abstract String withA(String a);\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .failsToCompile()
            .withErrorContaining("Expected test.Test as return type");
}
 
Example #4
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 6 votes vote down vote up
@Test
public void wrongParameterType() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract String a();\n"
            + "  abstract Test withA(int a);\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .failsToCompile()
            .withErrorContaining("Expected type java.lang.String for a");
}
 
Example #5
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 6 votes vote down vote up
@Test
public void wrongParameterName() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract String a();\n"
            + "  abstract Test withA(String b);\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .failsToCompile()
            .withErrorContaining("Property \"b\" not found");
}
 
Example #6
Source File: AutoValueContentValuesExtensionTest.java    From auto-value-cursor with Apache License 2.0 6 votes vote down vote up
@Test
public void unsupported() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.content.ContentValues;\n"
            + "import javax.annotation.Nullable;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  @Nullable public abstract int[] a();\n"
            + "  public abstract String b();\n"
            + "  public abstract ContentValues toContentValues();\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .failsToCompile()
            .withErrorContaining("Property has type that can't be put into ContentValues.");
}
 
Example #7
Source File: MemoizedMethodSubject.java    From auto with Apache License 2.0 6 votes vote down vote up
void hasError(String error) {
  JavaFileObject file =
      JavaFileObjects.forSourceLines(
          "Value",
          "import com.google.auto.value.AutoValue;",
          "import com.google.auto.value.extension.memoized.Memoized;",
          "",
          "@AutoValue abstract class Value {",
          "  abstract String string();",
          actual,
          "}");
  Compilation compilation =
      javac()
          .withProcessors(new AutoValueProcessor(ImmutableList.of(new MemoizeExtension())))
          .compile(file);
  assertThat(compilation)
      .hadErrorContaining(error)
      .inFile(file)
      .onLineContaining(actual);
}
 
Example #8
Source File: EncodableProcessorTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void compile_withAutoValueInSamePackage_shouldRegisterGeneratedSubclass() {
  Compilation result =
      javac()
          .withProcessors(new AutoValueProcessor(), new EncodableProcessor())
          .compile(
              JavaFileObjects.forSourceLines(
                  "Foo",
                  "import com.google.firebase.encoders.annotations.Encodable;",
                  "import com.google.auto.value.AutoValue;",
                  "@Encodable @AutoValue public abstract class Foo {",
                  "public abstract String getField();",
                  "}"));

  assertThat(result).succeededWithoutWarnings();
  assertThat(result)
      .generatedSourceFile("AutoFooEncoder")
      .contentsAsUtf8String()
      .contains("cfg.registerEncoder(AutoValue_Foo.class");
}
 
Example #9
Source File: AutoValueContentValuesExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void columnName() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.gabrielittner.auto.value.cursor.ColumnName;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.content.ContentValues;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract int a();\n"
            + "  @ColumnName(\"column_b\") public abstract String b();\n"
            + "  public abstract ContentValues toContentValues();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.content.ContentValues;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  @Override\n"
            + "  public ContentValues toContentValues() {\n"
            + "    ContentValues values = new ContentValues(2);\n"
            + "    values.put(\"a\", a());\n"
            + "    values.put(\"column_b\", b());\n"
            + "    return values;\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #10
Source File: AutoValueContentValuesExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void simple() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.content.ContentValues;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract int a();\n"
            + "  public abstract String b();\n"
            + "  public abstract ContentValues toContentValues();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.content.ContentValues;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  @Override\n"
            + "  public ContentValues toContentValues() {\n"
            + "    ContentValues values = new ContentValues(2);\n"
            + "    values.put(\"a\", a());\n"
            + "    values.put(\"b\", b());\n"
            + "    return values;\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #11
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
// don't generate anything RxJava specific just because it's on the classpath
public void rxjava() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    String b = cursor.getString(cursor.getColumnIndexOrThrow(\"b\"));\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Arrays.asList(func1(), source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #12
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
// don't generate anything RxJava specific just because it's on the classpath
public void rxjava2() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    String b = cursor.getString(cursor.getColumnIndexOrThrow(\"b\"));\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Arrays.asList(function(), source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #13
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void unsupportedWithNullable() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "import javax.annotation.Nullable;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  @Nullable public abstract int[] a();\n"
            + "  public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int[] a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int[] a = null; // can't be read from cursor\n"
            + "    String b = cursor.getString(cursor.getColumnIndexOrThrow(\"b\"));\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #14
Source File: EncodableProcessorTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void compile_withAutoValueInDifferentPackage_shouldRegisterGeneratedSubclass() {
  Compilation result =
      javac()
          .withProcessors(new AutoValueProcessor(), new EncodableProcessor())
          .compile(
              JavaFileObjects.forSourceLines(
                  "com.example.Foo",
                  "package com.example;",
                  "import com.google.firebase.encoders.annotations.Encodable;",
                  "@Encodable public class Foo {",
                  "public com.example.sub.Member getField() { return null; }",
                  "}"),
              JavaFileObjects.forSourceLines(
                  "com.example.sub.Member",
                  "package com.example.sub;",
                  "import com.google.auto.value.AutoValue;",
                  "@AutoValue public abstract class Member {",
                  "public abstract String getField();",
                  "}"));

  assertThat(result).succeededWithoutWarnings();
  assertThat(result)
      .generatedSourceFile("com/example/AutoFooEncoder")
      .contentsAsUtf8String()
      .contains(
          "cfg.registerEncoder("
              + "com.example.sub.EncodableComExampleFooMemberAutoValueSupport.TYPE,"
              + " MemberEncoder.INSTANCE)");
  assertThat(result)
      .generatedSourceFile("com/example/sub/EncodableComExampleFooMemberAutoValueSupport")
      .contentsAsUtf8String()
      .contains("Class<? extends Member> TYPE = AutoValue_Member.class");
}
 
Example #15
Source File: AutoValueContentValuesExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void prefixedMethods() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.content.ContentValues;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract int getA();\n"
            + "  public abstract String getB();\n"
            + "  public abstract ContentValues toContentValues();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.content.ContentValues;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  @Override\n"
            + "  public ContentValues toContentValues() {\n"
            + "    ContentValues values = new ContentValues(2);\n"
            + "    values.put(\"a\", getA());\n"
            + "    values.put(\"b\", getB());\n"
            + "    return values;\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #16
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void nullableColumnName() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.gabrielittner.auto.value.cursor.ColumnName;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "import javax.annotation.Nullable;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  @Nullable @ColumnName(\"column_b\") public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    int bColumnIndex = cursor.getColumnIndex(\"column_b\");"
            + "    String b = (bColumnIndex == -1 || cursor.isNull(bColumnIndex)) ? null : cursor.getString(bColumnIndex);\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #17
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void nullable() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "import javax.annotation.Nullable;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  @Nullable public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    int bColumnIndex = cursor.getColumnIndex(\"b\");"
            + "    String b = (bColumnIndex == -1 || cursor.isNull(bColumnIndex)) ? null : cursor.getString(bColumnIndex);\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #18
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void columnName() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.gabrielittner.auto.value.cursor.ColumnName;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  @ColumnName(\"column_b\") public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    String b = cursor.getString(cursor.getColumnIndexOrThrow(\"column_b\"));\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #19
Source File: AutoValueCursorExtensionTest.java    From auto-value-cursor with Apache License 2.0 5 votes vote down vote up
@Test
public void simple() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "import android.database.Cursor;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public static Test blah(Cursor cursor) { return null; }\n"
            + "  public abstract int a();\n"
            + "  public abstract String b();\n"
            + "}\n");

    JavaFileObject expected = JavaFileObjects.forSourceString("test.AutoValue_Test", ""
            + "package test;\n"
            + "import android.database.Cursor;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, String b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  static AutoValue_Test createFromCursor(Cursor cursor) {\n"
            + "    int a = cursor.getInt(cursor.getColumnIndexOrThrow(\"a\"));\n"
            + "    String b = cursor.getString(cursor.getColumnIndexOrThrow(\"b\"));\n"
            + "    return new AutoValue_Test(a, b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expected);
}
 
Example #20
Source File: PaperParcelAutoValueExtensionTest.java    From paperparcel with Apache License 2.0 5 votes vote down vote up
@Test public void failWhenCreatorAlreadyDefinedTest() throws Exception {
  JavaFileObject source =
      JavaFileObjects.forSourceString("test.Test", Joiner.on('\n').join(
          "package test;",
          "import com.google.auto.value.AutoValue;",
          "import android.os.Parcel;",
          "import android.os.Parcelable;",
          "@AutoValue",
          "public abstract class Test implements Parcelable {",
          "  public abstract int count();",
          "  public static final Parcelable.Creator<Test> CREATOR = ",
          "      new Parcelable.Creator<Test>() {",
          "    @Override public Test createFromParcel(Parcel in) {",
          "      return null;",
          "    }",
          "    @Override public Test[] newArray(int size) {",
          "      return new Test[size];",
          "    }",
          "  };",
          "}"
      ));

  assertAbout(javaSource()).that(source)
      .processedWith(new PaperParcelProcessor(), new AutoValueProcessor())
      .failsToCompile()
      .withErrorContaining(String.format(ErrorMessages.MANUAL_IMPLEMENTATION_OF_CREATOR,
          "test.Test"))
      .in(source)
      .onLine(8);
}
 
Example #21
Source File: EncodableProcessorTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void compile_withNestedAutoValueInSamePackage_shouldRegisterGeneratedSubclass() {
  Compilation result =
      javac()
          .withProcessors(new AutoValueProcessor(), new EncodableProcessor())
          .compile(
              JavaFileObjects.forSourceLines(
                  "Foo",
                  "import com.google.firebase.encoders.annotations.Encodable;",
                  "import com.google.auto.value.AutoValue;",
                  "@Encodable @AutoValue public abstract class Foo {",
                  "public abstract Bar getBar();",
                  "@AutoValue public abstract static class Bar {",
                  "public abstract Baz getBaz();",
                  "@AutoValue public abstract static class Baz {",
                  "public abstract String getField();",
                  "}",
                  "}",
                  "}"));

  StringSubject compiled =
      assertThat(result).generatedSourceFile("AutoFooEncoder").contentsAsUtf8String();

  compiled.contains("cfg.registerEncoder(AutoValue_Foo.class");
  compiled.contains("cfg.registerEncoder(AutoValue_Foo_Bar.class");
  compiled.contains("cfg.registerEncoder(AutoValue_Foo_Bar_Baz.class");
}
 
Example #22
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 5 votes vote down vote up
@Test
public void generic() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test<T> {\n"
            + "  public abstract T a();\n"
            + "  abstract Test<T> withA(T a);\n"
            + "}\n");

    JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
            + "package test;\n"
            + "import java.lang.Override;\n"
            + "final class AutoValue_Test<T> extends $AutoValue_Test<T> {\n"
            + "  AutoValue_Test(T a) {\n"
            + "    super(a);\n"
            + "  }\n"
            + "  @Override final Test<T> withA(T a) {\n"
            + "    return new AutoValue_Test<>(a);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedSource);
}
 
Example #23
Source File: BundleExtensionTest.java    From auto-value-bundle with MIT License 5 votes vote down vote up
@Test
public void verifyBundledAutoValueClassWhenBundledAndGCM() {
    addResourceToSources("fixtures/TestClassBundledGCM.java");
    JavaFileObject expectedTestOutput = getResourceFile("fixtures/AutoValue_TestClassBundledGCM.java");
    assertAbout(javaSources())
            .that(sources)
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedTestOutput);
}
 
Example #24
Source File: BundleExtensionTest.java    From auto-value-bundle with MIT License 5 votes vote down vote up
@Test
public void verifyBundledAutoValueClassWhenBundled() {
    addResourceToSources("fixtures/TestClassBundled.java");
    JavaFileObject expectedTestOutput = getResourceFile("fixtures/AutoValue_TestClassBundled.java");
    assertAbout(javaSources())
            .that(sources)
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedTestOutput);
}
 
Example #25
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 5 votes vote down vote up
@Test
public void returnsGenericSuperType() {
    JavaFileObject source1 = JavaFileObjects.forSourceString("test.AbstractTest", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "public abstract class AbstractTest<T extends AbstractTest<T>> {\n"
            + "  public abstract String a();\n"
            + "  abstract T withA(String a);\n"
            + "}\n");
    JavaFileObject source2 = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "  @AutoValue public abstract class Test extends AbstractTest<Test> {\n"
            + "}\n");

    JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
            + "package test;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.String;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(String a) {\n"
            + "    super(a);\n"
            + "  }\n"
            + "  @Override final Test withA(String a) {\n"
            + "    return new AutoValue_Test(a);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Arrays.asList(source1, source2))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedSource);
}
 
Example #26
Source File: AutoValueWithExtensionTest.java    From auto-value-with with Apache License 2.0 5 votes vote down vote up
@Test
public void prefixedMethods() {
    JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
            + "package test;\n"
            + "import com.google.auto.value.AutoValue;\n"
            + "@AutoValue public abstract class Test {\n"
            + "  public abstract int getA();\n"
            + "  public abstract boolean isB();\n"
            + "  abstract Test withA(int a);\n"
            + "  abstract Test withB(boolean b);\n"
            + "}\n");

    JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
            + "package test;\n"
            + "import java.lang.Override;\n"
            + "final class AutoValue_Test extends $AutoValue_Test {\n"
            + "  AutoValue_Test(int a, boolean b) {\n"
            + "    super(a, b);\n"
            + "  }\n"
            + "  @Override final Test withA(int a) {\n"
            + "    return new AutoValue_Test(a, isB());\n"
            + "  }\n"
            + "  @Override final Test withB(boolean b) {\n"
            + "    return new AutoValue_Test(getA(), b);\n"
            + "  }\n"
            + "}\n");

    assertAbout(javaSources())
            .that(Collections.singletonList(source))
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedSource);
}
 
Example #27
Source File: BundleExtensionTest.java    From auto-value-bundle with MIT License 5 votes vote down vote up
@Test
public void verifyBaseAutoValueClassWhenNotBundled() {
    addResourceToSources("fixtures/TestClassWithoutBundled.java");
    JavaFileObject expectedTestOutput = getResourceFile("fixtures/AutoValue_TestClassWithoutBundled.java");
    assertAbout(javaSources())
            .that(sources)
            .processedWith(new AutoValueProcessor())
            .compilesWithoutError()
            .and()
            .generatesSources(expectedTestOutput);
}
 
Example #28
Source File: AutoValueRedactedExtensionTest.java    From auto-value-redacted with Apache License 2.0 5 votes vote down vote up
@Test public void beanPrefix() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import com.google.auto.value.AutoValue;\n"
      + "@AutoValue public abstract class Test {\n"
      + "@Redacted public abstract String getOne();\n"
      + "public abstract String getTwo();\n"
      + "@Redacted @Nullable public abstract String getThree();\n"
      + "@Nullable public abstract String getFour();\n"
      + "}\n"
  );

  JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
      + "package test;\n"
      + "import java.lang.Override;\n"
      + "import java.lang.String;\n"
      + "final class AutoValue_Test extends $AutoValue_Test {\n"
      + "  AutoValue_Test(String one, String two, String three, String four) {\n"
      + "    super(one, two, three, four);\n"
      + "  }\n"
      + "  @Override public final String toString() {\n"
      + "    return \"Test{\"\n"
      + "        + \"one=██, \"\n"
      + "        + \"two=\" + getTwo() + \", \"\n"
      + "        + \"three=\" + (getThree() != null ? \"██\" : null) + \", \"\n"
      + "        + \"four=\" + (getFour() != null ? getFour() : null)\n"
      + "        + '}';\n"
      + "  }\n"
      + "}\n"
  );

  assertAbout(javaSources())
      .that(Arrays.asList(redacted, nullable, source))
      .processedWith(new AutoValueProcessor())
      .compilesWithoutError()
      .and()
      .generatesSources(expectedSource);
}
 
Example #29
Source File: EncodableProcessorTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void compile_withNestedAutoValueInDifferentPackage_shouldRegisterGeneratedSubclass() {
  Compilation result =
      javac()
          .withProcessors(new AutoValueProcessor(), new EncodableProcessor())
          .compile(
              JavaFileObjects.forSourceLines(
                  "com.example.Foo",
                  "package com.example;",
                  "import com.google.firebase.encoders.annotations.Encodable;",
                  "@Encodable public class Foo {",
                  "public com.example.sub.Member.SubMember getSubMember() { return null; }",
                  "}"),
              JavaFileObjects.forSourceLines(
                  "com.example.sub.Member",
                  "package com.example.sub;",
                  "import com.google.auto.value.AutoValue;",
                  "@AutoValue public abstract class Member {",
                  "public abstract SubMember getSubMember();",
                  "@AutoValue public abstract static class SubMember {",
                  "public abstract String getField();",
                  "}",
                  "}"));

  assertThat(result).succeededWithoutWarnings();
  assertThat(result)
      .generatedSourceFile("com/example/AutoFooEncoder")
      .contentsAsUtf8String()
      .contains(
          "cfg.registerEncoder("
              + "com.example.sub.EncodableComExampleFooMemberSubMemberAutoValueSupport.TYPE,"
              + " MemberSubMemberEncoder.INSTANCE)");
  assertThat(result)
      .generatedSourceFile(
          "com/example/sub/EncodableComExampleFooMemberSubMemberAutoValueSupport")
      .contentsAsUtf8String()
      .contains("Class<? extends Member.SubMember> TYPE = AutoValue_Member_SubMember.class");
}
 
Example #30
Source File: AutoValueRedactedExtensionTest.java    From auto-value-redacted with Apache License 2.0 5 votes vote down vote up
@Test public void preConcatStrings() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import com.google.auto.value.AutoValue;\n"
      + "@AutoValue public abstract class Test {\n"
      + "@Redacted public abstract String one();\n"
      + "@Redacted public abstract String two();\n"
      + "}\n"
  );

  JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
      + "package test;\n"
      + "import java.lang.Override;\n"
      + "import java.lang.String;\n"
      + "final class AutoValue_Test extends $AutoValue_Test {\n"
      + "  AutoValue_Test(String one, String two) {\n"
      + "    super(one, two);\n"
      + "  }\n"
      + "  @Override public final String toString() {\n"
      + "    return \"Test{\"\n"
      + "        + \"one=██, \"\n"
      + "        + \"two=██\"\n"
      + "        + '}';\n"
      + "  }\n"
      + "}\n"
  );

  assertAbout(javaSources())
      .that(Arrays.asList(redacted, nullable, source))
      .processedWith(new AutoValueProcessor())
      .compilesWithoutError()
      .and()
      .generatesSources(expectedSource);
}