Improve test Classes extending 'PreviewParameterProvider' name MUST end with 'Provider' and MUST contain provided class name
This commit is contained in:
parent
44b37587cc
commit
2513ae769f
1 changed files with 13 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ package io.element.android.tests.konsist
|
||||||
|
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
import com.bumble.appyx.core.node.Node
|
import com.bumble.appyx.core.node.Node
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import com.lemonappdev.konsist.api.Konsist
|
import com.lemonappdev.konsist.api.Konsist
|
||||||
import com.lemonappdev.konsist.api.ext.list.withAllParentsOf
|
import com.lemonappdev.konsist.api.ext.list.withAllParentsOf
|
||||||
import com.lemonappdev.konsist.api.ext.list.withAnnotationNamed
|
import com.lemonappdev.konsist.api.ext.list.withAnnotationNamed
|
||||||
|
|
@ -44,19 +45,26 @@ class KonsistClassNameTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Classes extending 'PreviewParameterProvider' name MUST end with 'Provider' and MUST contain provided class name`() {
|
fun `Classes extending 'PreviewParameterProvider' name MUST end with 'Provider' and MUST contain provided class name`() {
|
||||||
Konsist.scopeFromProject()
|
Konsist.scopeFromProduction()
|
||||||
.classes()
|
.classes()
|
||||||
.withAllParentsOf(PreviewParameterProvider::class)
|
.withAllParentsOf(PreviewParameterProvider::class)
|
||||||
.assertTrue {
|
.also {
|
||||||
|
// Check that classes are actually found
|
||||||
|
assertThat(it.size).isGreaterThan(100)
|
||||||
|
}
|
||||||
|
.assertTrue { klass ->
|
||||||
// Cannot find a better way to get the type of the generic
|
// Cannot find a better way to get the type of the generic
|
||||||
val providedType = it.text
|
val providedType = klass.text
|
||||||
|
.substringAfter("PreviewParameterProvider<")
|
||||||
.substringBefore(">")
|
.substringBefore(">")
|
||||||
.substringAfter("<")
|
|
||||||
// Get the substring before the first '<' to remove the generic type
|
// Get the substring before the first '<' to remove the generic type
|
||||||
.substringBefore("<")
|
.substringBefore("<")
|
||||||
.removeSuffix("?")
|
.removeSuffix("?")
|
||||||
.replace(".", "")
|
.replace(".", "")
|
||||||
it.name.endsWith("Provider") && (it.name.contains("IconList") || it.name.contains(providedType))
|
val name = klass.name
|
||||||
|
name.endsWith("Provider") &&
|
||||||
|
name.endsWith("PreviewProvider").not() &&
|
||||||
|
name.contains(providedType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue