Skip to content

Commit

Permalink
Update an AutoValue test to the newer compile-testing API.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 375814417
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed May 25, 2021
1 parent c84e6af commit 54baeb3
Showing 1 changed file with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package com.google.auto.value.processor;

import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
Expand Down Expand Up @@ -272,13 +273,15 @@ private void assertGeneratedMatches(
.addMethodAnnotations(expectedMethodAnnotations)
.build();

assertAbout(javaSource())
.that(javaFileObject)
.withCompilerOptions("-A" + Nullables.NULLABLE_OPTION + "=")
.processedWith(new AutoValueProcessor())
.compilesWithoutError()
.and()
.generatesSources(expectedOutput);
Compilation compilation =
javac()
.withOptions("-A" + Nullables.NULLABLE_OPTION + "=")
.withProcessors(new AutoValueProcessor())
.compile(javaFileObject);
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoValue_Baz")
.hasSourceEquivalentTo(expectedOutput);
}

@Test
Expand Down Expand Up @@ -513,13 +516,15 @@ public void testCopyingMethodAnnotations() {
.addFieldAnnotations("@Deprecated", "@PropertyAnnotationsTest.InheritedAnnotation")
.build();

assertAbout(javaSource())
.that(inputFile)
.withCompilerOptions("-A" + Nullables.NULLABLE_OPTION + "=")
.processedWith(new AutoValueProcessor())
.compilesWithoutError()
.and()
.generatesSources(outputFile);
Compilation compilation =
javac()
.withOptions("-A" + Nullables.NULLABLE_OPTION)
.withProcessors(new AutoValueProcessor())
.compile(inputFile);
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoValue_Baz")
.hasSourceEquivalentTo(outputFile);
}

/**
Expand Down Expand Up @@ -552,12 +557,14 @@ public void testCopyingMethodAnnotationsToGeneratedFields() {
"@Baz.MethodsOnly")
.build();

assertAbout(javaSource())
.that(inputFile)
.withCompilerOptions("-A" + Nullables.NULLABLE_OPTION + "=")
.processedWith(new AutoValueProcessor())
.compilesWithoutError()
.and()
.generatesSources(outputFile);
Compilation compilation =
javac()
.withOptions("-A" + Nullables.NULLABLE_OPTION + "=")
.withProcessors(new AutoValueProcessor())
.compile(inputFile);
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoValue_Baz")
.hasSourceEquivalentTo(outputFile);
}
}

0 comments on commit 54baeb3

Please sign in to comment.