From c193cfb1a092db22417ef5e3b3963e2acca4f136 Mon Sep 17 00:00:00 2001 From: Joel Wilcox Date: Thu, 31 Aug 2023 11:51:33 -0700 Subject: [PATCH] Testing changes --- .../internal/testing/SimpleCodeGenerator.kt | 5 ++--- .../ContributesMultibindingGeneratorTest.kt | 19 +++++++------------ .../codegen/ksp/SimpleSymbolProcessor.kt | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/compiler-utils/src/testFixtures/java/com/squareup/anvil/compiler/internal/testing/SimpleCodeGenerator.kt b/compiler-utils/src/testFixtures/java/com/squareup/anvil/compiler/internal/testing/SimpleCodeGenerator.kt index 6473710e7..721779fa4 100644 --- a/compiler-utils/src/testFixtures/java/com/squareup/anvil/compiler/internal/testing/SimpleCodeGenerator.kt +++ b/compiler-utils/src/testFixtures/java/com/squareup/anvil/compiler/internal/testing/SimpleCodeGenerator.kt @@ -9,8 +9,7 @@ import com.squareup.anvil.compiler.internal.reference.classAndInnerClassReferenc import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.psi.KtFile import java.io.File - -private var counter = 0 +import kotlin.random.Random fun simpleCodeGenerator( mapper: CodeGenerator.(clazz: ClassReference.Psi) -> String? @@ -78,7 +77,7 @@ fun parseSimpleFileContents(content: String): SimpleFileContents { ?.trim() ?.substringBefore(" ") } - ?: "NewFile${counter++}" + ?: "NewFile${Random.nextInt()}" return SimpleFileContents( packageName = packageName, diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt index a078acd46..25bbb28da 100644 --- a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt +++ b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt @@ -368,12 +368,9 @@ class ContributesMultibindingGeneratorTest( package com.squareup.test import com.squareup.anvil.annotations.ContributesMultibinding - import dagger.MapKey - import javax.inject.Singleton - @ContributesMultibinding(Any::class) - @BindingKey("abc") - @Singleton + @ContributesMultibinding(scope = Any::class) + @BindingKey(value = "abc") interface ContributingInterface : ParentInterface """.trimIndent() @@ -388,7 +385,7 @@ class ContributesMultibindingGeneratorTest( } is AnvilCompilationMode.Ksp -> { val processor = simpleSymbolProcessor { resolver -> - resolver.getSymbolsWithAnnotation(MergeComponent::class.qualifiedName!!) + resolver.getSymbolsWithAnnotation(mergeComponentFqName.toString(), inDepth = true) .map { stubContentToGenerate } .toList() } @@ -408,7 +405,7 @@ class ContributesMultibindingGeneratorTest( interface ParentInterface - @MergeComponent(Any::class) + @MergeComponent(scope = Any::class) interface ComponentInterface """, mode = localMode @@ -426,16 +423,14 @@ class ContributesMultibindingGeneratorTest( import com.squareup.anvil.annotations.ContributesMultibinding import dagger.MapKey - import javax.inject.Singleton interface ParentInterface @MapKey annotation class BindingKey1(val value: String) - @ContributesMultibinding(Any::class) - @BindingKey1("abc") - @Singleton + @ContributesMultibinding(scope = Any::class) + @BindingKey1(value = "abc") interface ContributingInterface : ParentInterface """.trimIndent() @@ -452,7 +447,7 @@ class ContributesMultibindingGeneratorTest( } is AnvilCompilationMode.Ksp -> { val processor = simpleSymbolProcessor { resolver -> - resolver.getSymbolsWithAnnotation(MergeComponent::class.qualifiedName!!) + resolver.getSymbolsWithAnnotation(mergeComponentFqName.toString(), inDepth = true) .map { stubContentToGenerate } .toList() } diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ksp/SimpleSymbolProcessor.kt b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ksp/SimpleSymbolProcessor.kt index 4d1fa94fe..583e2c4ea 100644 --- a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ksp/SimpleSymbolProcessor.kt +++ b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ksp/SimpleSymbolProcessor.kt @@ -26,7 +26,7 @@ private class SimpleSymbolProcessor( val (packageName, fileName) = parseSimpleFileContents(content) val dependencies = Dependencies(aggregating = false, sources = emptyArray()) - val file = env.codeGenerator.createNewFile(dependencies, packageName, "$fileName.kt") + val file = env.codeGenerator.createNewFile(dependencies, packageName, fileName) // Don't use writeTo(file) because that tries to handle directories under the hood OutputStreamWriter(file, StandardCharsets.UTF_8) .buffered()