Random Notes by agilob

JavaArchUnit check if abstract classes are abstract

Jump to Section

    @Test
    public void abstractClassesAreAbstract() {
        final JavaClasses importedClasses = new ClassFileImporter()
                .importPackages("net.agilob.project");
        LoggingRulesTest.ABSTRACT_CLASS_MUST_BE_ABSTRACT.check(importedClasses);
    }

    public static final ArchRule ABSTRACT_CLASS_MUST_BE_ABSTRACT =
            classes()
            .that()
            .haveSimpleNameContaining("Abstract").or().haveSimpleNameContaining("abstract")
            .should()
            .haveModifier(JavaModifier.ABSTRACT);