View ArchUnitTest.java
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
@AnalyzeClasses(packages = "org.mypackage", importOptions = {ArchUnitTest.ExcludeControllerImportOption.class, ImportOption.DoNotIncludeTests.class}) | |
public class ArchUnitTest { | |
static class ExcludeControllerImportOption implements com.tngtech.archunit.core.importer.ImportOption { | |
@Override | |
public boolean includes(Location location) { | |
return !location.contains("SomeControllerClassThatNeedsToBeExcluded"); | |
} | |
} |
View ArchUnitTest.java
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
@AnalyzeClasses(packages = "org.mypackage", importOptions = ImportOption.DoNotIncludeTests.class) |
View ArchUnitTest.java
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 final ArchRule onion_architecture_is_respected = onionArchitecture() | |
.domainModels("..domain.model..") | |
.domainServices("..domain.service..") | |
.applicationServices("..application..") | |
.adapter("cli", "..adapter.cli..") | |
.adapter("persistence", "..adapter.persistence..") | |
.adapter("rest", "..adapter.rest.."); |
View ArchUnitTest.java
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 configs_should_be_annotated = | |
classes() | |
.that().resideInAPackage("..config..") | |
.and().areNotNestedClasses() | |
.should().beAnnotatedWith(Configuration.class) | |
.orShould().beAnnotatedWith(ConfigurationProperties.class); |
View MyArchUnitTest.java
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 final ArchRule xml_requests_must_reside_in_request_package = | |
classes().that().areAssignableTo(SoapRequest.class) | |
.should().resideInAPackage("..request..") | |
.as("Xmls requests should reside in a package '..request..'"); |
View ArchUnitTest.java
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 final ArchRule configs_must_reside_in_a_config_package = | |
classes().that().areAnnotatedWith(Configuration.class) | |
.or().areNotNestedClasses().and().areAnnotatedWith(ConfigurationProperties.class) | |
.should().resideInAPackage("..config..") | |
.as("Configs should reside in a package '..config..'"); |
View ArchUnitTest.java
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 final ArchRule entities_must_reside_in_a_model_package = | |
classes().that().areAnnotatedWith(Entity.class) | |
.should().resideInAPackage("..model..") | |
.as("Entities should reside in a package '..model..'") | |
.allowEmptyShould(true); |
View ArchUnitTest.java
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 controllers_should_be_suffixed = | |
classes() | |
.that().resideInAPackage("..controller..") | |
.or().areAnnotatedWith(RestController.class) | |
.should().haveSimpleNameEndingWith("Controller") | |
.allowEmptyShould(true); |
View ArchUnitTest.java
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
@AnalyzeClasses(packages = "org.mypackage") | |
@ArchTest | |
static ArchRule app_class_name_should_be_app = | |
classes().that().areAnnotatedWith(SpringBootApplication.class) | |
.should().haveSimpleName("MainApp"); |
View LayeredArchitecture.java
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 final ArchRule layer_dependencies_are_respected = layeredArchitecture() | |
.layer("Controllers").definedBy("com.tngtech.archunit.example.layers.controller..") | |
.layer("Services").definedBy("com.tngtech.archunit.example.layers.service..") | |
.layer("Persistence").definedBy("com.tngtech.archunit.example.layers.persistence..") | |
.whereLayer("Controllers").mayNotBeAccessedByAnyLayer() | |
.whereLayer("Services").mayOnlyBeAccessedByLayers("Controllers") | |
.whereLayer("Persistence").mayOnlyBeAccessedByLayers("Services"); |
NewerOlder