Is this the right way to check for inheritance or ...
# konsist
c
Is this the right way to check for inheritance or is there an out-of-the-box way using Konsist?
Copy code
@Test
fun `every class with a name ending on FragmentDelegate needs to be (indirectly) derived from BaseFragmentDelegate`() {
    Konsist.scopeFromProduction()
        .classes()
        .withNameEndingWith("FragmentDelegate")
        .takeIf { it.isNotEmpty() }
        ?.assert { klass ->
            val classToCheckForInheritance = Class.forName(klass.fullyQualifiedName)
            BaseFragmentDelegate::class.java.isAssignableFrom(classToCheckForInheritance)
        }
}
i
Copy code
@Test
fun `every class with a name ending on FragmentDelegate needs to be (indirectly) derived from BaseFragmentDelegate`() {
    Konsist.scopeFromProduction()
        .classes()
        .withNameEndingWith("FragmentDelegate")
        ?.assert {
            it.hasParentOf<BaseFragmentDelegate>()
        }
}
BTW
.takeIf { it.isNotEmpty() }
should not be required - please tell me whats happens if this is not present (this may be a bug) 🤔