:question:How is it possible to assert for classes...
# konsist
p
How is it possible to assert for classes, interfaces and objects in one test? I have a use-case that is relevant for all 3 types and currently I'm duplicating the test to apply it for all types.
👀 1
1
n
The first way might be to create three scopes and add them:
Copy code
val classes = Konsist
            .scopeFromProject()
            .classes()

val interfaces = Konsist
            .scopeFromProject()
            .interfaces()

val objects = Konsist
            .scopeFromProject()
            .objects()

val scope = classes + interfaces + objects

scope
   .withNameEndingWith("Suffix")
   .assertTrue { ... }
p
Thank you very much. That approach I did not think of. It is working 🙂
❤️ 1
n
Great 🙂 Alternatively, the second way could be to use
declarationsOf
, but it will only work if we want to add simple checks:
Copy code
Konsist
    .scopeFromProject()
    .declarationsOf<KoParentProvider>()
    .assertTrue { 
        it.hasParentWithName("SomeName")
    }
p
In my case I want to check for a specific annotation that I don't want to allow generally