# konsist


09/20/2023, 11:46 AM
One question. Assuming I would like to check that all classes implementing only one interface should have postfix in name would look like as below
Copy code
fun `classes implementing one interface should have postfix 'X' in name`() {
        .filter { !it.hasDataModifier && !it.hasAbstractModifier && it.parents.size == 1 && !it.hasNameEndingWith("X") }
        .flatMap { it.parents }
        .flatMap {
        .assert { false } // if assertion is invoked then actually such an element exist when for successful test it shouldn't
// Currently in case the check is true and nothing meets criteria then test also will return false
...but in current scenario I don't have proper assertion at the end as you can see. Probably something like
would be needed here or maybe my test is incorrect? What do you think? Current assertion implementations have check
_checkIfLocalListIsEmpty_(this, _getTestMethodNameFromFourthIndex_())
which will produce an error in case there's no items for such an criteria.
I guess this could be partially related -


09/20/2023, 12:22 PM
Few takeaways: 1. Indeed this is the ticket. We will improve asserts with the next release - assert will by default pass on empty lists (new behaviour) and it will have a
parameter to throw an exception (current behaviour) 2. Currently referring to a parent may be a bit tricky. We have a ticket to add a "complex references" - parents will return actual instance of KoDeclaration, not a string. This will give is way to check if given parent is class or an interface. ATM it may be hard to achieve. 3.
refers to the file where declaration is located (not the file path of the parent). 4.
is no required nowadays as a lot of properties can be directly retrieved 5. Consider using
rather than
- idea is to have all methods in the Konsist API and fallback to kotlin collection methods (filter is still fine, but things may be simple with Konsist API):
Copy code
            .withoutModifier(KoModifier.DATA, KoModifier.ABSTRACT)
            .withParents { it.count() == 1 }
            .withParent { it.hasNameEndingWith("X") }


09/20/2023, 12:57 PM
Ad. 1️⃣ It wouldn't be needed if I would rework this to something alike (if 3️⃣ wasn't true of course 😅):
Copy code
    .withoutModifier(KoModifier.DATA, KoModifier.ABSTRACT)
    .withParents { it.count() == 1 }
    .assert {
Ad. 2️⃣ I was thinking about it, that this could be like desired improvement. Ok, so it will solve 3️⃣ too. Ad. 4️⃣ 💯 Ad. 5️⃣ I know, with the API functions code is looking great to me but I just wanted to have single filtering, but with API functions it's definitely much more readable.
Nevertheless, this is a great library, I hope it will become a standard! 🙂
❤️ 1
🙂 1