Skip to content

Commit

Permalink
Add UseCase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa authored and albin-mullvad committed Jun 18, 2024
1 parent ba23a45 commit 42c63d7
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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..") }
}

0 comments on commit 42c63d7

Please sign in to comment.