From 18f368dd3e07e8ef22b2803d7561d1fc35892fbb Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 10:02:09 +0100 Subject: [PATCH 1/6] tests: add tests for FeaturesInDevelopmentDefaultsBuilder --- ...eaturesInDevelopmentDefaultsBuilderTest.kt | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt new file mode 100644 index 000000000000..3b0169b671de --- /dev/null +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt @@ -0,0 +1,62 @@ +package org.wordpress.android.processor + +import org.assertj.core.api.Assertions +import org.junit.Test + +class FeaturesInDevelopmentDefaultsBuilderTest { + @Test + fun `given a list of features in development, when building the object, then generate list of features in development`() { + // given + val featureA = "valueA" + val featureB = "valueB" + val features = listOf(featureA, featureB) + + // when + val sut = FeaturesInDevelopmentDefaultsBuilder(features) + + // then + Assertions.assertThat(sut.getContent().toString()).isEqualTo( + """ + // Automatically generated file. DO NOT MODIFY + package org.wordpress.android.util.config + + import kotlin.String + import kotlin.collections.List + + object FeaturesInDevelopment { + val featuresInDevelopment: List = listOf( + "$featureA", + "$featureB" + ) + } + + """.trimIndent() + ) + } + + @Test + fun `given an empty list of features in development, when building the object, then generate empty list of features in development`() { + // given + val features = emptyList() + + // when + val sut = FeaturesInDevelopmentDefaultsBuilder(features) + + // then + Assertions.assertThat(sut.getContent().toString()).isEqualTo( + """ + // Automatically generated file. DO NOT MODIFY + package org.wordpress.android.util.config + + import kotlin.String + import kotlin.collections.List + + object FeaturesInDevelopment { + val featuresInDevelopment: List = listOf( + ) + } + + """.trimIndent() + ) + } +} From 5d3a86ddcd8629308f8675ba4ef94944d0ddc83c Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 12:31:14 +0100 Subject: [PATCH 2/6] tests: add tests for RemoteFeatureConfigCheckBuilder --- .../RemoteFeatureConfigCheckBuilderTest.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt new file mode 100644 index 000000000000..6d7f906d8d73 --- /dev/null +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt @@ -0,0 +1,53 @@ +package org.wordpress.android.processor + +import com.squareup.kotlinpoet.ClassName +import org.assertj.core.api.Assertions +import org.junit.Test + +class RemoteFeatureConfigCheckBuilderTest { + + @Test + fun `given feature classes, when building config check, then generate the correct checks`() { + // given + val classA = "customClassA" + val classB = "customClassB" + val features = listOf( + ClassName("org.wordpress", listOf(classA)), + ClassName("org.wordpress", listOf(classB)) + ) + + // when + val sut = RemoteFeatureConfigCheckBuilder(features) + + // then + Assertions.assertThat(sut.getContent().toString()).isEqualTo( + """ + // Automatically generated file. DO NOT MODIFY + package org.wordpress.android.util.config + + import org.wordpress.$classA + import org.wordpress.$classB + + class RemoteFeatureConfigCheck( + val appConfig: AppConfig + ) { + val $classA: $classA = $classA(appConfig) + + val $classB: $classB = $classB(appConfig) + + fun checkRemoteFields() { + if ($classA.remoteField == null) { + throw IllegalArgumentException(""${'"'}org.wordpress.$classA needs to define + remoteField""${'"'}) + } + if ($classB.remoteField == null) { + throw IllegalArgumentException(""${'"'}org.wordpress.$classB needs to define + remoteField""${'"'}) + } + } + } + + """.trimIndent() + ) + } +} From b99f498dad0e58c08e10960bcdddae2194466236 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 12:39:10 +0100 Subject: [PATCH 3/6] tests: add tests for RemoteFieldConfigDefaults --- .../RemoteFieldConfigDefaultsBuilderTest.kt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt new file mode 100644 index 000000000000..a3d0d19dba38 --- /dev/null +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt @@ -0,0 +1,66 @@ +package org.wordpress.android.processor + +import org.junit.Assert.* +import org.junit.Test + +class RemoteFieldConfigDefaultsBuilderTest { + + @Test + fun `given a list of remote fields, when building the object, then generate list of remote fields`() { + // given + val keyA = "keyA" + val valueA = "valueA" + val keyB = "keyB" + val valueB = "valueB" + + // when + val sut = RemoteFieldConfigDefaultsBuilder(mapOf(keyA to valueA, keyB to valueB)) + + // then + assertEquals( + """ + // Automatically generated file. DO NOT MODIFY + package org.wordpress.android.util.config + + import kotlin.Any + import kotlin.String + import kotlin.collections.Map + + object RemoteFieldConfigDefaults { + val remoteFieldConfigDefaults: Map = mapOf( + "$keyA" to "$valueA", + "$keyB" to "$valueB" + ) + } + + """.trimIndent(), sut.getContent().toString() + ) + } + + @Test + fun `given an empty list of remote fields, when building the object, then generate empty list of remote fields`() { + // given + val remoteFields = emptyMap() + + // when + val sut = RemoteFieldConfigDefaultsBuilder(remoteFields) + + // then + assertEquals( + """ + // Automatically generated file. DO NOT MODIFY + package org.wordpress.android.util.config + + import kotlin.Any + import kotlin.String + import kotlin.collections.Map + + object RemoteFieldConfigDefaults { + val remoteFieldConfigDefaults: Map = mapOf( + ) + } + + """.trimIndent(), sut.getContent().toString() + ) + } +} From cf2a4ccd1c4bd0592846cc8d3fb74fddab60ac37 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 12:52:12 +0100 Subject: [PATCH 4/6] build: bump kotlinpoet to 1.16.0 Address breaking changes --- build.gradle | 2 +- .../processor/FeaturesInDevelopmentDefaultsBuilder.kt | 2 +- .../android/processor/RemoteConfigProcessor.kt | 2 ++ .../processor/RemoteFeatureConfigCheckBuilder.kt | 2 +- .../processor/RemoteFeatureConfigDefaultsBuilder.kt | 2 +- .../processor/RemoteFieldConfigDefaultsBuilder.kt | 2 +- .../FeaturesInDevelopmentDefaultsBuilderTest.kt | 8 ++++---- .../processor/RemoteFeatureConfigCheckBuilderTest.kt | 10 +++++----- .../RemoteFeatureConfigDefaultsBuilderTest.kt | 4 ++-- .../processor/RemoteFieldConfigDefaultsBuilderTest.kt | 8 ++++---- 10 files changed, 22 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index c38978d64ec4..eba5484f157b 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,7 @@ ext { kotlinxCoroutinesVersion = '1.7.3' lottieVersion = '6.1.0' philjayMpAndroidChartVersion = 'v3.1.0' - squareupKotlinPoetVersion = '1.6.0' + squareupKotlinPoetVersion = '1.16.0' squareupOkioVersion = '3.6.0' squareupRetrofitVersion = '2.9.0' uCropVersion = '2.2.8' diff --git a/libs/processors/src/main/java/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilder.kt b/libs/processors/src/main/java/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilder.kt index bf4dc5c4fa73..1f326017947d 100644 --- a/libs/processors/src/main/java/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilder.kt +++ b/libs/processors/src/main/java/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilder.kt @@ -28,7 +28,7 @@ class FeaturesInDevelopmentDefaultsBuilder(private val featuresInDevelopment: Li .build() return FileSpec.builder("org.wordpress.android.util.config", "FeaturesInDevelopment") .addType(remoteConfigDefaults) - .addComment("Automatically generated file. DO NOT MODIFY") + .addFileComment("Automatically generated file. DO NOT MODIFY") .indent(" ") .build() } diff --git a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteConfigProcessor.kt b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteConfigProcessor.kt index 225e133791cb..a8217dd7084f 100644 --- a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteConfigProcessor.kt +++ b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteConfigProcessor.kt @@ -1,6 +1,7 @@ package org.wordpress.android.processor import com.google.auto.service.AutoService +import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asTypeName import org.wordpress.android.annotation.Experiment @@ -26,6 +27,7 @@ import javax.tools.Diagnostic.Kind "org.wordpress.android.annotation.RemoteFieldDefaultGenerater" ) class RemoteConfigProcessor : AbstractProcessor() { + @OptIn(DelicateKotlinPoetApi::class) @Suppress("DEPRECATION") override fun process(p0: MutableSet?, roundEnvironment: RoundEnvironment?): Boolean { val experiments = roundEnvironment?.getElementsAnnotatedWith(Experiment::class.java)?.map { element -> diff --git a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilder.kt b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilder.kt index 6bae01db287f..d60995c5586b 100644 --- a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilder.kt +++ b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilder.kt @@ -42,7 +42,7 @@ class RemoteFeatureConfigCheckBuilder(private val remoteFeatures: List .build() return FileSpec.builder("org.wordpress.android.util.config", "RemoteFeatureConfigCheck") .addType(remoteFeatureConfigDefaults) - .addComment("Automatically generated file. DO NOT MODIFY") + .addFileComment("Automatically generated file. DO NOT MODIFY") .indent(" ") .build() } diff --git a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilder.kt b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilder.kt index 04a37de19c2e..63769cc3c254 100644 --- a/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilder.kt +++ b/libs/processors/src/main/java/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilder.kt @@ -31,7 +31,7 @@ class RemoteFeatureConfigDefaultsBuilder(private val defaults: Map .build() return FileSpec.builder("org.wordpress.android.util.config", FILE_NAME) .addType(remoteConfigDefaults) - .addComment("Automatically generated file. DO NOT MODIFY") + .addFileComment("Automatically generated file. DO NOT MODIFY") .indent(" ") .build() } diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt index 3b0169b671de..b36de2efcf86 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt @@ -23,8 +23,8 @@ class FeaturesInDevelopmentDefaultsBuilderTest { import kotlin.String import kotlin.collections.List - object FeaturesInDevelopment { - val featuresInDevelopment: List = listOf( + public object FeaturesInDevelopment { + public val featuresInDevelopment: List = listOf( "$featureA", "$featureB" ) @@ -51,8 +51,8 @@ class FeaturesInDevelopmentDefaultsBuilderTest { import kotlin.String import kotlin.collections.List - object FeaturesInDevelopment { - val featuresInDevelopment: List = listOf( + public object FeaturesInDevelopment { + public val featuresInDevelopment: List = listOf( ) } diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt index 6d7f906d8d73..3167e653310b 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt @@ -28,14 +28,14 @@ class RemoteFeatureConfigCheckBuilderTest { import org.wordpress.$classA import org.wordpress.$classB - class RemoteFeatureConfigCheck( - val appConfig: AppConfig + public class RemoteFeatureConfigCheck( + public val appConfig: AppConfig, ) { - val $classA: $classA = $classA(appConfig) + public val $classA: $classA = $classA(appConfig) - val $classB: $classB = $classB(appConfig) + public val $classB: $classB = $classB(appConfig) - fun checkRemoteFields() { + public fun checkRemoteFields() { if ($classA.remoteField == null) { throw IllegalArgumentException(""${'"'}org.wordpress.$classA needs to define remoteField""${'"'}) diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilderTest.kt index ed1837b1d501..e8c6889aa4e6 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigDefaultsBuilderTest.kt @@ -24,8 +24,8 @@ class RemoteFeatureConfigDefaultsBuilderTest { import kotlin.String import kotlin.collections.Map - object RemoteFeatureConfigDefaults { - val remoteFeatureConfigDefaults: Map = mapOf( + public object RemoteFeatureConfigDefaults { + public val remoteFeatureConfigDefaults: Map = mapOf( "$keyA" to "$valueA", "$keyB" to "$valueB" ) diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt index a3d0d19dba38..74043be5fc51 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt @@ -26,8 +26,8 @@ class RemoteFieldConfigDefaultsBuilderTest { import kotlin.String import kotlin.collections.Map - object RemoteFieldConfigDefaults { - val remoteFieldConfigDefaults: Map = mapOf( + public object RemoteFieldConfigDefaults { + public val remoteFieldConfigDefaults: Map = mapOf( "$keyA" to "$valueA", "$keyB" to "$valueB" ) @@ -55,8 +55,8 @@ class RemoteFieldConfigDefaultsBuilderTest { import kotlin.String import kotlin.collections.Map - object RemoteFieldConfigDefaults { - val remoteFieldConfigDefaults: Map = mapOf( + public object RemoteFieldConfigDefaults { + public val remoteFieldConfigDefaults: Map = mapOf( ) } From b62d1dd9234aaf178446b46663f469f4b16aa2f8 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 13:02:28 +0100 Subject: [PATCH 5/6] style: fix static code analysis --- .../processor/FeaturesInDevelopmentDefaultsBuilderTest.kt | 4 ++-- .../android/processor/RemoteFieldConfigDefaultsBuilderTest.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt index b36de2efcf86..46a4847c3346 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt @@ -5,7 +5,7 @@ import org.junit.Test class FeaturesInDevelopmentDefaultsBuilderTest { @Test - fun `given a list of features in development, when building the object, then generate list of features in development`() { + fun `given a list of features in development, when building the object, then generate the correct list`() { // given val featureA = "valueA" val featureB = "valueB" @@ -35,7 +35,7 @@ class FeaturesInDevelopmentDefaultsBuilderTest { } @Test - fun `given an empty list of features in development, when building the object, then generate empty list of features in development`() { + fun `given an empty list of features in development, when building the object, then generate empty list`() { // given val features = emptyList() diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt index 74043be5fc51..27f9fc6fd39c 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt @@ -1,6 +1,6 @@ package org.wordpress.android.processor -import org.junit.Assert.* +import org.junit.Assert.assertEquals import org.junit.Test class RemoteFieldConfigDefaultsBuilderTest { From ec1baba114bba7d8eb6557fff1f48c581ab8870b Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 13:11:01 +0100 Subject: [PATCH 6/6] style: fix checkstyle --- .../android/processor/RemoteFeatureConfigCheckBuilderTest.kt | 1 - .../android/processor/RemoteFieldConfigDefaultsBuilderTest.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt index 3167e653310b..ac7e2f8cab6e 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt @@ -5,7 +5,6 @@ import org.assertj.core.api.Assertions import org.junit.Test class RemoteFeatureConfigCheckBuilderTest { - @Test fun `given feature classes, when building config check, then generate the correct checks`() { // given diff --git a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt index 27f9fc6fd39c..c173b0900059 100644 --- a/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt +++ b/libs/processors/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt @@ -4,7 +4,6 @@ import org.junit.Assert.assertEquals import org.junit.Test class RemoteFieldConfigDefaultsBuilderTest { - @Test fun `given a list of remote fields, when building the object, then generate list of remote fields`() { // given