Eric
09/05/2023, 8:43 PMRepository
regardless of how high up the tree that is. Right now I have this:
@Test
fun `interfaces that implement 'Repository' should have 'Repository' suffix`() {
Konsist
.scopeFromProject()
.interfaces()
.withAllParentsOf(CoroutineCrudRepository::class)
.assert { it.hasNameEndingWith("Repository") }
}
but would prefer:
@Test
fun `interfaces that implement 'Repository' should have 'Repository' suffix`() {
Konsist
.scopeFromProject()
.interfaces()
.withAllParentsOf(Repository::class)
.assert { it.hasNameEndingWith("Repository") }
}
igor.wojda
09/06/2023, 4:53 AMEric
09/06/2023, 1:13 PM.withAnnotation<RestController>()
or .withParent<Repository>()
. just a little sugar.Eric
09/06/2023, 1:37 PMinline fun <reified A : Any> classesAnnotatedWith() =
Konsist
.scopeFromProject()
.classes()
.withAllAnnotationsOf(A::class)
Then usage is like:
class EntityConsistencyTests {
@Test
fun `classes annotated with @Table should implement AuditedPersistable`() {
classesAnnotatedWith<Table>()
.assert { it.hasParents(AuditedPersistable::class.java.simpleName) }
}
@Test
fun `classes annotated with @Table should be data classes`() {
classesAnnotatedWith<Table>()
.assert { it.hasDataModifier }
}
@Test
fun `classes annotated with @Table should have getId function annotated with @Id`() {
classesAnnotatedWith<Table>()
.assert { it.containsFunction { f -> f.name == "getId" && f.hasAnnotationsOf(Id::class) } }
}
}
Mustafa Ozhan
10/10/2023, 3:33 PMigor.wojda
10/10/2023, 5:09 PMscopeFromProject
.
This discussion is about supporting parent tree that seems unrelated to you message.igor.wojda
10/10/2023, 5:09 PMMustafa Ozhan
10/10/2023, 6:16 PMigor.wojda
10/10/2023, 6:18 PMigor.wojda
10/10/2023, 6:20 PMKonsist.scopeFromProject()
should be a good start, but take a look at docs - there are various ways of creating Konsist scope and scope composition - all of this should be enough to fit your needs https://docs.konsist.lemonappdev.com/writing-tests/koscopeMustafa Ozhan
10/10/2023, 6:20 PMKonsist.scopeFromProject()
.classes()
.withNameEndingWith("Service")
.assert {
println(it.name) // here
}
so i can not get my all classes ends with Service
here, only some of them visible, my project is KMP btw, not sure if it makes differenceigor.wojda
10/10/2023, 6:21 PMMustafa Ozhan
10/10/2023, 6:23 PMigor.wojda
10/10/2023, 6:23 PMNatalia Peterwas
03/11/2024, 5:33 PMKonsist
.scopeFromProject()
.interfaces()
.withAllParentsOf(Repository::class, indirectParents = true)
.assertTrue { it.hasNameEndingWith("Repository") }