-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add konsist tests for management service to avoid missing Either
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |