Package Dependency Checks

diagram

noClasses().that().resideInAPackage("..source..")
    .should().dependOnClassesThat().resideInAPackage("..foo..")

diagram

classes().that().resideInAPackage("..foo..")
    .should().onlyHaveDependentClassesThat().resideInAnyPackage("..source.one..", "..foo..")

Class Dependency Checks

diagram

classes().that().haveNameMatching(".*Bar")
    .should().onlyHaveDependentClassesThat().haveSimpleName("Bar")

Class and Package Containment Checks

diagram

classes().that().haveSimpleNameStartingWith("Foo")
    .should().resideInAPackage("com.foo")

Inheritance Checks

diagram

classes().that().implement(Connection.class)
    .should().haveSimpleNameEndingWith("Connection")

diagram

classes().that().areAssignableTo(EntityManager.class)
    .should().onlyHaveDependentClassesThat().resideInAnyPackage("..persistence..")

Annotation Checks

diagram

classes().that().areAssignableTo(EntityManager.class)
    .should().onlyHaveDependentClassesThat().areAnnotatedWith(Transactional.class)

Layer Checks

diagram

layeredArchitecture()
    .layer("Controller").definedBy("..controller..")
    .layer("Service").definedBy("..service..")
    .layer("Persistence").definedBy("..persistence..")

    .whereLayer("Controller").mayNotBeAccessedByAnyLayer()
    .whereLayer("Service").mayOnlyBeAccessedByLayers("Controller")
    .whereLayer("Persistence").mayOnlyBeAccessedByLayers("Service")

Cycle Checks

diagram

slices().matching("com.myapp.(*)..").should().beFreeOfCycles()