From ac826a8cd1a1ffa5f68c74365a394cc035475366 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Wed, 24 Jul 2024 16:32:45 +0200 Subject: [PATCH] Add konsist tests for management service to avoid missing Either --- .../test/arch/ManagementServiceTest.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt new file mode 100644 index 000000000000..11999555f0ab --- /dev/null +++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt @@ -0,0 +1,30 @@ +package net.mullvad.mullvadvpn.test.arch + +import com.lemonappdev.konsist.api.Konsist +import com.lemonappdev.konsist.api.ext.list.modifierprovider.withPublicOrDefaultModifier +import com.lemonappdev.konsist.api.verify.assertTrue +import org.junit.jupiter.api.Test + +class ManagementServiceTest { + + @Test + fun `ensure all public functions are returning Either`() { + managementServiceClass() + .functions() + .withPublicOrDefaultModifier() + .filter { excludedFunctions().contains(it.name).not() } + .assertTrue { it.returnType?.name?.startsWith(EITHER_CLASS_NAME) == true } + } + + private fun managementServiceClass() = + Konsist.scopeFromProject().classes().first { it.name == MANAGEMENT_SERVICE_CLASS_NAME } + + private fun excludedFunctions() = setOf(START, STOP) + + companion object { + private const val MANAGEMENT_SERVICE_CLASS_NAME = "ManagementService" + private const val START = "start" + private const val STOP = "stop" + private const val EITHER_CLASS_NAME = "Either" + } +}