Konsist: add test about PreviewParameterProvider class name and fix existing issues.

This commit is contained in:
Benoit Marty 2023-10-11 17:33:56 +02:00 committed by Benoit Marty
parent 3c41158558
commit 8f8a5746e5
5 changed files with 21 additions and 34 deletions

View file

@ -16,6 +16,7 @@
package io.element.android.app
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.bumble.appyx.core.node.Node
import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.withAllParentsOf
@ -43,4 +44,20 @@ class KonsistClassNameTest {
it.name.endsWith("Node")
}
}
@Test
fun `Classes extending 'PreviewParameterProvider' name MUST end with "Provider" and MUST contain provided class name`() {
Konsist.scopeFromProject()
.classes()
.withAllParentsOf(PreviewParameterProvider::class)
.assertTrue {
// Cannot find a better way to get the type of the generic
val providedType = it.text
.substringBefore(">")
.substringAfter("<")
.removeSuffix("?")
.replace(".", "")
it.name.endsWith("Provider") && it.name.contains(providedType)
}
}
}