-
-
Save andres-sacco/6429fc96d58b43244b1e9bfb78be4433 to your computer and use it in GitHub Desktop.
Layer architecture
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 static com.tngtech.archunit.library.Architectures.layeredArchitecture; | |
import com.tngtech.archunit.core.importer.ImportOption; | |
import com.tngtech.archunit.junit.AnalyzeClasses; | |
import com.tngtech.archunit.junit.ArchTest; | |
import com.tngtech.archunit.lang.ArchRule; | |
@AnalyzeClasses(packages = "com.example.archunit", importOptions = ImportOption.DoNotIncludeTests.class) | |
class LayeredArchitectureTest { | |
private static final String CONTROLLER = "Controller"; | |
private static final String REPOSITORY = "Repository"; | |
private static final String SERVICE = "Service"; | |
@ArchTest | |
static final ArchRule layer_dependencies_are_respected = layeredArchitecture() | |
.layer(CONTROLLER).definedBy("..controller..") | |
.layer(SERVICE).definedBy("..service..") | |
.layer(REPOSITORY).definedBy("..repository..") | |
.whereLayer("Controllers").mayNotBeAccessedByAnyLayer() | |
.whereLayer(SERVICE).mayOnlyBeAccessedByLayers(CONTROLLER) | |
.whereLayer(REPOSITORY).mayOnlyBeAccessedByLayers(SERVICE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment