Yonatan Karp-Rudin
10/06/2023, 4:03 PMController
).
However, for the best of my understanding the assert
extension function expects the list of results to not be empty.
Does it make any sense to either extend the functionality or add additional assertion like assertOrEmpty
as in my specific case I might not have any Repository
or Service
implemented on the template repository yet
I'll add code snippet in the 🧵class AnnotationValidationTest {
@Test
fun `classes with 'RestController' annotation should have 'Controller' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withAnnotationOf(RestController::class)
.assert { it.hasNameEndingWithOrNone("Controller") }
}
@Test
fun `classes with 'Service' annotation should have 'Service' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withAnnotationOf(Service::class)
.assert { it.hasNameEndingWithOrNone("Service") }
}
@Test
fun `classes with 'Repository' annotation should have 'Repository' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withAnnotationOf(Repository::class)
.assert { it.hasNameEndingWithOrNone("Repository") }
}
private fun KoClassDeclaration.hasNameEndingWithOrNone(vararg names: String): Boolean {
if (this.name.isEmpty()) {
return true
}
return names.all { name ->
LocationUtil.resideInLocation("..$name", name)
}
}
}
However the extension function is never called as the list of results is empty.
Also, if the assertion would accept empty as a valid result I could completely remove my extension function 🙂igor.wojda
10/06/2023, 8:19 PMYonatan Karp-Rudin
10/06/2023, 8:21 PM