2. Classes With UseCase Suffix Should Reside In domain And usecase Package
@Testfun`classes with 'UseCase' suffix should reside in 'domain' and 'usecase' package`() { Konsist .scopeFromProject() .classes() .withNameEndingWith("UseCase") .assertTrue { it.resideInPackage("..domain..usecase..") }}
3. Classes With UseCase Suffix Should Have Single public Operator Method Named invoke
@Testfun`classes with 'UseCase' suffix should have single 'public operator' method named 'invoke'`() { Konsist .scopeFromProject() .classes() .withNameEndingWith("UseCase") .assertTrue {val hasSingleInvokeOperatorMethod = it.hasFunction { function -> function.name =="invoke"&& function.hasPublicOrDefaultModifier && function.hasOperatorModifier } hasSingleInvokeOperatorMethod && it.countFunctions { item -> item.hasPublicOrDefaultModifier } ==1 }}
4. Classes With UseCase Suffix And Parents Should Have Single public Operator Method Named invoke
@Testfun`classes with 'UseCase' suffix and parents should have single 'public operator' method named 'invoke'`() { Konsist .scopeFromProject() .classes() .withNameEndingWith("UseCase") .assertTrue {// Class and it's parentval declarations =listOf(it) + it.parents(true)// Functions from all parents without overridesval uniqueFunctions = declarations .mapNotNull { koParentDeclaration -> koParentDeclaration as? KoFunctionProvider } .flatMap { koFunctionProvider -> koFunctionProvider.functions( includeNested =false, includeLocal =false ) } .filterNot { koFunctionDeclaration -> koFunctionDeclaration.hasOverrideModifier }val hasInvokeOperatorMethod = uniqueFunctions.any { functionDeclaration -> functionDeclaration.name == "invoke" && functionDeclaration.hasPublicOrDefaultModifier && functionDeclaration.hasOperatorModifier
}val numParentPublicFunctions = uniqueFunctions.count { functionDeclaration -> functionDeclaration.hasPublicOrDefaultModifier } hasInvokeOperatorMethod && numParentPublicFunctions ==1 }}
5. Interfaces With Repository Annotation Should Reside In data Package
@Testfun`interfaces with 'Repository' annotation should reside in 'data' package`() { Konsist .scopeFromProject() .interfaces() .withAnnotationOf(Repository::class) .assertTrue { it.resideInPackage("..data..") }}
6. Every UseCase Class Has Test
@Testfun`every UseCase class has test`() { Konsist .scopeFromProduction() .classes() .withNameEndingWith("UseCase") .assertTrue { it.hasTestClasses() }}