Android Snippets

Konsist can be used to guard the consistency of the Android project.

The android-showcase project contains set of Konsist tests.

1. Classes Extending ViewModel Should Have ViewModel Suffix

@Test
fun `classes extending 'ViewModel' should have 'ViewModel' suffix`() {
    Konsist
        .scopeFromProject()
        .classes()
        .withParentClassOf(ViewModel::class)
        .assertTrue { it.name.endsWith("ViewModel") }
}

2. Every ViewModel Public Property Has Flow Type

@Test
fun `Every 'ViewModel' public property has 'Flow' type`() {
    Konsist
        .scopeFromProject()
        .classes()
        .withParentClassOf(ViewModel::class)
        .properties()
        .assertTrue {
            it.hasPublicOrDefaultModifier && it.hasType { type -> type.name == "kotlinx.coroutines.flow.Flow" }
        }
}

3. Repository Classes Should Reside In repository Package

4. No Class Should Use Android Util Logging

5. All JetPack Compose Previews Contain Preview In Method Name

6. Every Class With Serializable Must Have Its Properties Serializable

Last updated