From 42c63d707450ccebb04454c8e99b8634be19f979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Fri, 14 Jun 2024 15:00:32 +0200 Subject: [PATCH] Add UseCase tests --- .../mullvadvpn/test/arch/UseCaseTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/UseCaseTest.kt diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/UseCaseTest.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/UseCaseTest.kt new file mode 100644 index 000000000000..305ba7127bc7 --- /dev/null +++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/UseCaseTest.kt @@ -0,0 +1,29 @@ +package net.mullvad.mullvadvpn.test.arch + +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.verify.assertTrue +import org.junit.jupiter.api.Test + +class UseCaseTest { + @Test + fun `ensure all use cases end with UseCase suffix`() = + allUseCasesFiles().assertTrue { it.name.endsWith("UseCase") } + + @Test + fun `ensure every use cases is public`() = + allUseCases().assertTrue { it.hasPublicOrDefaultModifier } + + @Test + fun `ensure every public functions method is named 'invoke' with operator modifier`() = + allUseCases().functions().withPublicOrDefaultModifier().assertTrue { + it.name == "invoke" && it.hasOperatorModifier + } + + private fun allUseCasesFiles() = + Konsist.scopeFromProduction().files.filter { it.resideInPath("..usecase..") } + + private fun allUseCases() = + Konsist.scopeFromProduction().classes().filter { it.resideInPackage("..usecase..") } +}