-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20213 from wordpress-mobile/processor_unit_tests
Add `:libs:processors` unit tests
- Loading branch information
Showing
10 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...c/test/kotlin/org/wordpress/android/processor/FeaturesInDevelopmentDefaultsBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 the correct list`() { | ||
// 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 | ||
public object FeaturesInDevelopment { | ||
public val featuresInDevelopment: List<String> = listOf( | ||
"$featureA", | ||
"$featureB" | ||
) | ||
} | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
@Test | ||
fun `given an empty list of features in development, when building the object, then generate empty list`() { | ||
// given | ||
val features = emptyList<String>() | ||
|
||
// 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 | ||
public object FeaturesInDevelopment { | ||
public val featuresInDevelopment: List<String> = listOf( | ||
) | ||
} | ||
""".trimIndent() | ||
) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...rs/src/test/kotlin/org/wordpress/android/processor/RemoteFeatureConfigCheckBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 | ||
public class RemoteFeatureConfigCheck( | ||
public val appConfig: AppConfig, | ||
) { | ||
public val $classA: $classA = $classA(appConfig) | ||
public val $classB: $classB = $classB(appConfig) | ||
public 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() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...s/src/test/kotlin/org/wordpress/android/processor/RemoteFieldConfigDefaultsBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.wordpress.android.processor | ||
|
||
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 | ||
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 | ||
public object RemoteFieldConfigDefaults { | ||
public val remoteFieldConfigDefaults: Map<String, Any> = 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<String, String>() | ||
|
||
// 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 | ||
public object RemoteFieldConfigDefaults { | ||
public val remoteFieldConfigDefaults: Map<String, Any> = mapOf( | ||
) | ||
} | ||
""".trimIndent(), sut.getContent().toString() | ||
) | ||
} | ||
} |