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

The following examples show how to use com.google.auto.value.processor.AutoValueProcessor. These examples are extracted from open source projects. 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 Project: firebase-android-sdk   Author: firebase   File: EncodableProcessorTest.java    License: 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 #2
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #3
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #4
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #5
Source Project: paperparcel   Author: grandstaish   File: PaperParcelAutoValueExtensionTest.java    License: 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 #6
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #7
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueContentValuesExtensionTest.java    License: 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 #8
Source Project: auto   Author: google   File: MemoizedMethodSubject.java    License: 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 #9
Source Project: firebase-android-sdk   Author: firebase   File: EncodableProcessorTest.java    License: 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 #10
Source Project: firebase-android-sdk   Author: firebase   File: EncodableProcessorTest.java    License: 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 #11
Source Project: firebase-android-sdk   Author: firebase   File: EncodableProcessorTest.java    License: 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 #12
Source Project: auto-value-bundle   Author: uber   File: BundleExtensionTest.java    License: 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 #13
Source Project: auto-value-bundle   Author: uber   File: BundleExtensionTest.java    License: 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 #14
Source Project: auto-value-bundle   Author: uber   File: BundleExtensionTest.java    License: 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 #15
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #16
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #17
Source Project: auto-value-with   Author: gabrielittner   File: AutoValueWithExtensionTest.java    License: 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 #18
Source Project: auto-value-redacted   Author: square   File: AutoValueRedactedExtensionTest.java    License: 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 #19
Source Project: auto-value-redacted   Author: square   File: AutoValueRedactedExtensionTest.java    License: 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);
}
 
Example #20
Source Project: auto-value-redacted   Author: square   File: AutoValueRedactedExtensionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void generics() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
      + "package test;\n"
      + "import com.google.auto.value.AutoValue;\n"
      + "@AutoValue public abstract class Test<T extends String & Runnable, U extends T> {\n"
      + "@Redacted public abstract T tee();\n"
      + "public abstract U you();\n"
      + "}\n"
  );

  JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
      + "package test;\n"
      + "import java.lang.Override;\n"
      + "import java.lang.Runnable;\n"
      + "import java.lang.String;\n"
      + "final class AutoValue_Test<T extends String & Runnable, U extends T> extends $AutoValue_Test<T, U> {\n"
      + "  AutoValue_Test(T tee, U you) {\n"
      + "    super(tee, you);\n"
      + "  }\n"
      + "  @Override public final String toString() {\n"
      + "    return \"Test{\"\n"
      + "        + \"tee=██, \"\n"
      + "        + \"you=\" + you()\n"
      + "        + '}';\n"
      + "  }\n"
      + "}\n"
  );

  assertAbout(javaSources())
      .that(Arrays.asList(redacted, nullable, source))
      .processedWith(new AutoValueProcessor())
      .compilesWithoutError()
      .and()
      .generatesSources(expectedSource);
}
 
Example #21
Source Project: paperparcel   Author: grandstaish   File: PaperParcelAutoValueExtensionTest.java    License: 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 #22
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #23
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #24
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #25
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #26
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #27
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #28
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueCursorExtensionTest.java    License: 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 #29
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueContentValuesExtensionTest.java    License: 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 #30
Source Project: auto-value-cursor   Author: gabrielittner   File: AutoValueContentValuesExtensionTest.java    License: 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);
}