From 5d3a86ddcd8629308f8675ba4ef94944d0ddc83c Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 20 Feb 2024 12:31:14 +0100 Subject: [PATCH] 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() + ) + } +}