diff options
| author | Albin <albin@mullvad.net> | 2023-10-02 11:45:48 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-10-02 11:45:48 +0200 |
| commit | 76a67daefa31e8b6f06b7078f0a6a591318375c8 (patch) | |
| tree | e4e42ff06eea92a1d7cd1972f7d4877c91de3c7e /android/test | |
| parent | 3bf2f5767f9f7c363279be110c215c26bf9446e4 (diff) | |
| parent | 8af8d3c266c032ebb1f7019fa92aec02df9053b8 (diff) | |
| download | mullvadvpn-76a67daefa31e8b6f06b7078f0a6a591318375c8.tar.xz mullvadvpn-76a67daefa31e8b6f06b7078f0a6a591318375c8.zip | |
Merge branch 'add-konsist-vm-checks'
Diffstat (limited to 'android/test')
| -rw-r--r-- | android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt index 35ffe52c31..8347c799d7 100644 --- a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt +++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt @@ -2,15 +2,37 @@ package net.mullvad.mullvadvpn.test.arch import androidx.lifecycle.ViewModel import com.lemonappdev.konsist.api.Konsist +import com.lemonappdev.konsist.api.ext.list.functions +import com.lemonappdev.konsist.api.ext.list.modifierprovider.withPublicOrDefaultModifier +import com.lemonappdev.konsist.api.ext.list.properties import com.lemonappdev.konsist.api.ext.list.withAllParentsOf import com.lemonappdev.konsist.api.verify.assert +import com.lemonappdev.konsist.api.verify.assertNot import org.junit.Test class ViewModelTests { @Test fun ensureViewModelsHaveViewModelSuffix() { - Konsist.scopeFromProject().classes().withAllParentsOf(ViewModel::class).assert { - it.name.endsWith("ViewModel") + allViewModels().assert { it.name.endsWith("ViewModel") } + } + + // The purpose of this check is to both keep the naming consistent and also to avoid exposing + // properties that shouldn't be exposed. + @Test + fun ensurePublicPropertiesUsePermittedNames() { + allViewModels().properties(includeNested = false).withPublicOrDefaultModifier().assert { + property -> + property.name == "uiState" || property.name == "uiSideEffect" + } + } + + @Test + fun ensurePublicFunctionsHaveNoReturnType() { + allViewModels().functions().withPublicOrDefaultModifier().assertNot { function -> + function.hasReturnType() } } + + private fun allViewModels() = + Konsist.scopeFromProject().classes().withAllParentsOf(ViewModel::class) } |
