https://kotlinlang.org logo
#konsist
Title
# konsist
p

PoisonedYouth

12/14/2023, 10:44 AM
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

Natalia Peterwas

12/15/2023, 7:26 AM
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

PoisonedYouth

12/15/2023, 7:31 AM
Thank you very much. That approach I did not think of. It is working 🙂
❤️ 1
n

Natalia Peterwas

12/15/2023, 7:36 AM
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

PoisonedYouth

12/15/2023, 7:37 AM
In my case I want to check for a specific annotation that I don't want to allow generally
2 Views