Run Fts3/4 tests with ksp

Bug: 160322705
Test: Fts3TableEntityProcessorTest, Fts4TableEntityProcessorTest
Change-Id: I419ad64e07a0fe08de1304604b46b4f98c2c343e
diff --git a/room/compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt b/room/compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
index 7956c0d..103e28e 100644
--- a/room/compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/processor/FtsTableEntityProcessor.kt
@@ -175,7 +175,9 @@
         if (!contentEntityElement.hasAnnotation(androidx.room.Entity::class)) {
             context.logger.e(
                 contentEntityElement,
-                ProcessorErrors.externalContentNotAnEntity(contentEntityElement.toString())
+                ProcessorErrors.externalContentNotAnEntity(
+                    contentEntityElement.className.canonicalName()
+                )
             )
             return null
         }
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
index 31f63f3..af7987d 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/BaseFtsEntityParserTest.kt
@@ -16,19 +16,12 @@
 
 package androidx.room.processor
 
-import androidx.annotation.NonNull
-import androidx.room.Embedded
-import androidx.room.Fts3
-import androidx.room.Fts4
-import androidx.room.testing.TestInvocation
-import androidx.room.testing.TestProcessor
+import androidx.room.compiler.processing.util.Source
+import androidx.room.compiler.processing.util.XTestInvocation
+import androidx.room.compiler.processing.util.runProcessorTest
+import androidx.room.testing.context
 import androidx.room.vo.FtsEntity
-import com.google.common.truth.Truth
-import com.google.testing.compile.CompileTester
-import com.google.testing.compile.JavaFileObjects
-import com.google.testing.compile.JavaSourcesSubjectFactory
 import java.io.File
-import javax.tools.JavaFileObject
 
 abstract class BaseFtsEntityParserTest {
     companion object {
@@ -49,10 +42,10 @@
         entityAttributes: Map<String, String> = mapOf(),
         ftsAttributes: Map<String, String> = mapOf(),
         baseClass: String = "",
-        jfos: List<JavaFileObject> = emptyList(),
-        classpathFiles: Set<File> = emptySet(),
-        handler: (FtsEntity, TestInvocation) -> Unit
-    ): CompileTester {
+        sources: List<Source> = emptyList(),
+        classpath: List<File> = emptyList(),
+        handler: (FtsEntity, XTestInvocation) -> Unit
+    ) {
         val ftsVersion = getFtsVersion().toString()
         val entityAttributesReplacement = if (entityAttributes.isEmpty()) {
             ""
@@ -69,52 +62,25 @@
         } else {
             " extends $baseClass"
         }
-        return Truth.assertAbout(JavaSourcesSubjectFactory.javaSources())
-            .that(
-                jfos + JavaFileObjects.forSourceString(
-                    "foo.bar.MyEntity",
-                    ENTITY_PREFIX.format(
-                        entityAttributesReplacement, ftsVersion,
-                        ftsAttributesReplacement, baseClassReplacement
-                    ) + input +
-                        ENTITY_SUFFIX
-                )
+        val entitySource = Source.java(
+            "foo.bar.MyEntity",
+            ENTITY_PREFIX.format(
+                entityAttributesReplacement, ftsVersion,
+                ftsAttributesReplacement, baseClassReplacement
+            ) + input + ENTITY_SUFFIX
+        )
+        runProcessorTest(
+            sources = sources + entitySource,
+            classpath = classpath
+        ) { invocation ->
+            val entity = invocation.processingEnv.requireTypeElement("foo.bar.MyEntity")
+            val processor = FtsTableEntityProcessor(
+                invocation.context,
+                entity
             )
-            .apply {
-                if (classpathFiles.isNotEmpty()) {
-                    withClasspath(classpathFiles)
-                }
-            }
-            .processedWith(
-                TestProcessor.builder()
-                    .forAnnotations(
-                        androidx.room.Entity::class,
-                        Fts3::class,
-                        Fts4::class,
-                        androidx.room.PrimaryKey::class,
-                        androidx.room.Ignore::class,
-                        Embedded::class,
-                        androidx.room.ColumnInfo::class,
-                        NonNull::class
-                    )
-                    .nextRunHandler { invocation ->
-                        val fts3AnnotatedElements = invocation.roundEnv
-                            .getTypeElementsAnnotatedWith(Fts3::class.qualifiedName!!)
-                        val fts4AnnotatedElements = invocation.roundEnv
-                            .getTypeElementsAnnotatedWith(Fts4::class.qualifiedName!!)
-                        val entity = (fts3AnnotatedElements + fts4AnnotatedElements).first {
-                            it.toString() == "foo.bar.MyEntity"
-                        }
-                        val processor = FtsTableEntityProcessor(
-                            invocation.context,
-                            entity
-                        )
-                        val processedEntity = processor.process()
-                        handler(processedEntity, invocation)
-                        true
-                    }
-                    .build()
-            )
+            val processedEntity = processor.process()
+            handler(processedEntity, invocation)
+        }
     }
 
     abstract fun getFtsVersion(): Int
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
index 75e3206..14bc1be 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/Fts3TableEntityProcessorTest.kt
@@ -63,7 +63,7 @@
                 public void setRowId(int id) { this.rowId = rowId; }
             """
         ) { entity, invocation ->
-            assertThat(entity.type.toString(), `is`("foo.bar.MyEntity"))
+            assertThat(entity.type.typeName.toString(), `is`("foo.bar.MyEntity"))
             assertThat(entity.fields.size, `is`(1))
             val field = entity.fields.first()
             val intType = invocation.processingEnv.requireType(TypeName.INT)
@@ -84,7 +84,7 @@
             assertThat(entity.primaryKey.fields, `is`(Fields(field)))
             assertThat(entity.shadowTableName, `is`("MyEntity_content"))
             assertThat(entity.ftsVersion, `is`(FtsVersion.FTS3))
-        }.compilesWithoutError()
+        }
     }
 
     @Test
@@ -95,7 +95,7 @@
                 public String getContent() { return content; }
                 public void setContent(String content) { this.content = content; }
             """
-        ) { _, _ -> }.compilesWithoutError()
+        ) { _, _ -> }
     }
 
     @Test
@@ -107,9 +107,13 @@
                 public int getRowId(){ return rowId; }
                 public void setRowId(int rowId) { this.rowId = rowId; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.MISSING_PRIMARY_KEYS_ANNOTATION_IN_ROW_ID)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.MISSING_PRIMARY_KEYS_ANNOTATION_IN_ROW_ID
+                )
+            }
+        }
     }
 
     @Test
@@ -121,9 +125,13 @@
                 public int getId(){ return id; }
                 public void setId(int id) { this.id = id; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_NAME)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_NAME
+                )
+            }
+        }
     }
 
     @Test
@@ -136,9 +144,13 @@
                 public String getRowId(){ return rowId; }
                 public void setRowId(String rowId) { this.rowId = rowId; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_AFFINITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_AFFINITY
+                )
+            }
+        }
     }
 
     @Test
@@ -150,9 +162,13 @@
                 @PrimaryKey
                 public int twoId;
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY
+                )
+            }
+        }
     }
 
     @Test
@@ -168,7 +184,7 @@
             ftsAttributes = hashMapOf("tokenizer" to "FtsOptions.TOKENIZER_PORTER")
         ) { entity, _ ->
             assertThat(entity.ftsOptions.tokenizer, `is`(FtsOptions.TOKENIZER_PORTER))
-        }.compilesWithoutError()
+        }
     }
 
     @Test
@@ -184,6 +200,6 @@
             ftsAttributes = hashMapOf("tokenizer" to "\"customICU\"")
         ) { entity, _ ->
             assertThat(entity.ftsOptions.tokenizer, `is`("customICU"))
-        }.compilesWithoutError()
+        }
     }
 }
\ No newline at end of file
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
index 92b679c..664c8f2 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/Fts4TableEntityProcessorTest.kt
@@ -16,23 +16,23 @@
 
 package androidx.room.processor
 
-import androidx.room.Fts4
 import androidx.room.FtsOptions
+import androidx.room.compiler.processing.util.Source
+import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.parser.FtsVersion
 import androidx.room.parser.SQLTypeAffinity
+import androidx.room.testing.context
 import androidx.room.vo.CallType
 import androidx.room.vo.Field
 import androidx.room.vo.FieldGetter
 import androidx.room.vo.FieldSetter
 import androidx.room.vo.Fields
-import com.google.testing.compile.JavaFileObjects
 import com.squareup.javapoet.TypeName
 import org.hamcrest.CoreMatchers.`is`
 import org.hamcrest.MatcherAssert.assertThat
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
-import simpleRun
 
 @RunWith(JUnit4::class)
 class Fts4TableEntityProcessorTest : BaseFtsEntityParserTest() {
@@ -50,7 +50,7 @@
                 public void setRowId(int id) { this.rowId = rowId; }
             """
         ) { entity, invocation ->
-            assertThat(entity.type.toString(), `is`("foo.bar.MyEntity"))
+            assertThat(entity.type.typeName.toString(), `is`("foo.bar.MyEntity"))
             assertThat(entity.fields.size, `is`(1))
             val field = entity.fields.first()
             val intType = invocation.processingEnv.requireType(TypeName.INT)
@@ -71,15 +71,16 @@
             assertThat(entity.primaryKey.fields, `is`(Fields(field)))
             assertThat(entity.shadowTableName, `is`("MyEntity_content"))
             assertThat(entity.ftsVersion, `is`(FtsVersion.FTS4))
-        }.compilesWithoutError()
+        }
     }
 
     @Test
     fun missingEntityAnnotation() {
-        simpleRun(
-            JavaFileObjects.forSourceString(
-                "foo.bar.MyEntity",
-                """
+        runProcessorTest(
+            sources = listOf(
+                Source.java(
+                    "foo.bar.MyEntity",
+                    """
                 package foo.bar;
                 import androidx.room.*;
                 @Fts4
@@ -87,16 +88,20 @@
                     public String content;
                 }
                 """
+                )
             )
         ) { invocation ->
-            val entity = invocation.roundEnv
-                .getTypeElementsAnnotatedWith(Fts4::class.qualifiedName!!)
-                .first { it.toString() == "foo.bar.MyEntity" }
+            val entity = invocation.processingEnv.requireTypeElement(
+                "foo.bar.MyEntity"
+            )
             FtsTableEntityProcessor(invocation.context, entity)
                 .process()
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.ENTITY_MUST_BE_ANNOTATED_WITH_ENTITY
+                )
+            }
         }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.ENTITY_MUST_BE_ANNOTATED_WITH_ENTITY)
     }
 
     @Test
@@ -109,12 +114,18 @@
                 public String content;
                 """,
             entityAttributes = mapOf("indices" to "{@Index(\"content\")}")
-        ) { _, _ -> }.failsToCompile().withErrorContaining(ProcessorErrors.INDICES_IN_FTS_ENTITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INDICES_IN_FTS_ENTITY
+                )
+            }
+        }
     }
 
     @Test
     fun notAllowedForeignKeys() {
-        val foreignEntity = JavaFileObjects.forSourceString(
+        val foreignEntity = Source.java(
             "foo.bar.FKEntity",
             """
                 package foo.bar;
@@ -137,9 +148,14 @@
                 "foreignKeys" to "{@ForeignKey(entity=FKEntity.class, " +
                     "parentColumns=\"id\", childColumns=\"rowid\")}"
             ),
-            jfos = listOf(foreignEntity)
-        ) { _, _ -> }.failsToCompile()
-            .withErrorContaining(ProcessorErrors.FOREIGN_KEYS_IN_FTS_ENTITY)
+            sources = listOf(foreignEntity)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.FOREIGN_KEYS_IN_FTS_ENTITY
+                )
+            }
+        }
     }
 
     @Test
@@ -150,7 +166,7 @@
                 public String getContent() { return content; }
                 public void setContent(String content) { this.content = content; }
             """
-        ) { _, _ -> }.compilesWithoutError()
+        ) { _, _ -> }
     }
 
     @Test
@@ -162,7 +178,7 @@
                 public String content;
                 """,
             entityAttributes = mapOf("primaryKeys" to "\"rowid\"")
-        ) { _, _ -> }.compilesWithoutError()
+        ) { _, _ -> }
     }
 
     @Test
@@ -174,9 +190,13 @@
                 public int getRowId(){ return rowId; }
                 public void setRowId(int rowId) { this.rowId = rowId; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.MISSING_PRIMARY_KEYS_ANNOTATION_IN_ROW_ID)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.MISSING_PRIMARY_KEYS_ANNOTATION_IN_ROW_ID
+                )
+            }
+        }
     }
 
     @Test
@@ -188,9 +208,13 @@
                 public int getId(){ return id; }
                 public void setId(int id) { this.id = id; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_NAME)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_NAME
+                )
+            }
+        }
     }
 
     @Test
@@ -203,9 +227,13 @@
                 public String getRowId(){ return rowId; }
                 public void setRowId(String rowId) { this.rowId = rowId; }
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_AFFINITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PRIMARY_KEY_AFFINITY
+                )
+            }
+        }
     }
 
     @Test
@@ -217,9 +245,13 @@
                 @PrimaryKey
                 public int twoId;
                 """
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY
+                )
+            }
+        }
     }
 
     @Test
@@ -230,9 +262,13 @@
                 public int twoId;
                 """,
             entityAttributes = mapOf("primaryKeys" to "{\"oneId\",\"twoId\"}")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.TOO_MANY_PRIMARY_KEYS_IN_FTS_ENTITY
+                )
+            }
+        }
     }
 
     @Test
@@ -248,7 +284,7 @@
             ftsAttributes = hashMapOf("tokenizer" to "FtsOptions.TOKENIZER_PORTER")
         ) { entity, _ ->
             assertThat(entity.ftsOptions.tokenizer, `is`(FtsOptions.TOKENIZER_PORTER))
-        }.compilesWithoutError()
+        }
     }
 
     @Test
@@ -264,12 +300,12 @@
             ftsAttributes = hashMapOf("tokenizer" to "\"customICU\"")
         ) { entity, _ ->
             assertThat(entity.ftsOptions.tokenizer, `is`("customICU"))
-        }.compilesWithoutError()
+        }
     }
 
     @Test
     fun badExternalContentEntity_notAnEntity() {
-        val contentSrc = JavaFileObjects.forSourceString(
+        val contentSrc = Source.java(
             "foo.bar.Content",
             """
                 package foo.bar;
@@ -288,15 +324,19 @@
                 public String extraData;
                 """,
             ftsAttributes = hashMapOf("contentEntity" to "Content.class"),
-            jfos = listOf(contentSrc)
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.externalContentNotAnEntity("foo.bar.Content"))
+            sources = listOf(contentSrc)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.externalContentNotAnEntity("foo.bar.Content")
+                )
+            }
+        }
     }
 
     @Test
     fun badExternalContentEntity_missingFields() {
-        val contentSrc = JavaFileObjects.forSourceString(
+        val contentSrc = Source.java(
             "foo.bar.Content",
             """
                 package foo.bar;
@@ -318,15 +358,17 @@
                 public String extraData;
                 """,
             ftsAttributes = hashMapOf("contentEntity" to "Content.class"),
-            jfos = listOf(contentSrc)
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(
-                ProcessorErrors.missingFtsContentField(
-                    "foo.bar.MyEntity",
-                    "extraData", "foo.bar.Content"
+            sources = listOf(contentSrc)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.missingFtsContentField(
+                        "foo.bar.MyEntity",
+                        "extraData", "foo.bar.Content"
+                    )
                 )
-            )
+            }
+        }
     }
 
     @Test
@@ -339,9 +381,13 @@
                 public String body;
                 """,
             ftsAttributes = hashMapOf("languageId" to "\"lid\"")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.missingLanguageIdField("lid"))
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.missingLanguageIdField("lid")
+                )
+            }
+        }
     }
 
     @Test
@@ -355,9 +401,13 @@
                 public String lid;
                 """,
             ftsAttributes = hashMapOf("languageId" to "\"lid\"")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_LANGUAGE_ID_AFFINITY)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_LANGUAGE_ID_AFFINITY
+                )
+            }
+        }
     }
 
     @Test
@@ -369,9 +419,13 @@
                 public int rowId;
                 """,
             ftsAttributes = hashMapOf("notIndexed" to "{\"body\"}")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.missingNotIndexedField(listOf("body")))
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.missingNotIndexedField(listOf("body"))
+                )
+            }
+        }
     }
 
     @Test
@@ -384,9 +438,13 @@
                 public String body;
                 """,
             ftsAttributes = hashMapOf("prefix" to "{0,2}")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PREFIX_SIZES)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PREFIX_SIZES
+                )
+            }
+        }
     }
 
     @Test
@@ -399,8 +457,12 @@
                 public String body;
                 """,
             ftsAttributes = hashMapOf("prefix" to "{-2,2}")
-        ) { _, _ -> }
-            .failsToCompile()
-            .withErrorContaining(ProcessorErrors.INVALID_FTS_ENTITY_PREFIX_SIZES)
+        ) { _, invocation ->
+            invocation.assertCompilationResult {
+                hasErrorContaining(
+                    ProcessorErrors.INVALID_FTS_ENTITY_PREFIX_SIZES
+                )
+            }
+        }
     }
 }
\ No newline at end of file