Skip to content

Instantly share code, notes, and snippets.

@BenjaminKlatt
Created October 12, 2020 15:53
Show Gist options
  • Save BenjaminKlatt/4e388c6210fa941fe4a4eca72b8a9398 to your computer and use it in GitHub Desktop.
Save BenjaminKlatt/4e388c6210fa941fe4a4eca72b8a9398 to your computer and use it in GitHub Desktop.
ArchUnit Layer Test
package de.viadee.architecture.archunit.architecture;
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 = "de.viadee.architecture.archunit",
importOptions = {
ImportOption.DoNotIncludeTests.class,
ImportOption.DoNotIncludeJars.class,
ImportOption.DoNotIncludeArchives.class
})
public class LayerDependencyRulesTest {
@ArchTest
public static final ArchRule layer_dependency_rule = layeredArchitecture()
.layer("Controller").definedBy("..controller..")
.layer("Service").definedBy("..service..")
.layer("Adapter").definedBy("..adapter..")
.whereLayer("Controller").mayNotBeAccessedByAnyLayer()
.whereLayer("Service").mayOnlyBeAccessedByLayers("Controller")
.whereLayer("Adapter").mayOnlyBeAccessedByLayers("Service")
.because("Layers must respect a defined dependency hierarchy");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment