Last active
October 29, 2022 23:43
-
-
Save gbzarelli/cd083edc4506b5388a02899f508d25bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.tngtech.archunit.junit.AnalyzeClasses; | |
import com.tngtech.archunit.junit.ArchTest; | |
import com.tngtech.archunit.lang.ArchRule; | |
import static com.tngtech.archunit.library.Architectures.layeredArchitecture; | |
@AnalyzeClasses(packages = "br.com.helpdev.myapp") | |
class ArchitectureTest { | |
@ArchTest | |
static final ArchRule layer_dependencies_are_respected = layeredArchitecture() | |
.consideringAllDependencies() | |
.layer("Controller").definedBy("..controller..") | |
.layer("Service").definedBy("..service..") | |
.layer("Persistence").definedBy("..persistence..") | |
.whereLayer("Controller").mayNotBeAccessedByAnyLayer() | |
.whereLayer("Service").mayOnlyBeAccessedByLayers("Controller") | |
.whereLayer("Persistence").mayOnlyBeAccessedByLayers("Service") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ArchTest | |
static ArchRule app_class_name_should_be_app = | |
classes().that() | |
.areAnnotatedWith(SpringBootApplication.class) | |
.should().haveSimpleName("MainApplication"); | |
@ArchTest | |
static ArchRule controllers_should_be_suffixed = | |
classes().that() | |
.resideInAPackage("..controller..") | |
.or().areAnnotatedWith(RestController.class) | |
.should().haveSimpleNameEndingWith("Controller") | |
//Note that the allowEmptyShould(true) option allows tests to fail if the given project contains no controllers. | |
.allowEmptyShould(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment