Search in sources :

Example 1 with LayeredArchitecture

use of com.tngtech.archunit.library.Architectures.LayeredArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_allows_individual_empty_optionalLayer.

@Test
public void layered_architecture_allows_individual_empty_optionalLayer() {
    LayeredArchitecture architecture = layeredArchitecture().optionalLayer("can be absent").definedBy(absolute("should.not.be.found.."));
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    EvaluationResult result = architecture.evaluate(classes);
    assertThat(result.hasViolation()).as("result of evaluating empty optionalLayer has violation").isFalse();
    assertThat(result.getFailureReport().isEmpty()).as("failure report").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 2 with LayeredArchitecture

use of com.tngtech.archunit.library.Architectures.LayeredArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_allows_empty_layers_if_all_layers_are_optional.

@Test
public void layered_architecture_allows_empty_layers_if_all_layers_are_optional() {
    LayeredArchitecture architecture = aLayeredArchitectureWithEmptyLayers().withOptionalLayers(true);
    assertThat(architecture.getDescription()).startsWith("Layered architecture consisting of (optional)");
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    assertThatRule(architecture).checking(classes).hasNoViolation();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 3 with LayeredArchitecture

use of com.tngtech.archunit.library.Architectures.LayeredArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_combines_multiple_ignores.

@Test
public void layered_architecture_combines_multiple_ignores() {
    JavaClasses classes = new ClassFileImporter().importClasses(FirstAnyPkgClass.class, SomePkgSubclass.class, SecondThreeAnyClass.class, SomePkgClass.class);
    LayeredArchitecture layeredArchitecture = layeredArchitecture().layer("One").definedBy(absolute("some.pkg..")).whereLayer("One").mayNotBeAccessedByAnyLayer().ignoreDependency(FirstAnyPkgClass.class, SomePkgSubclass.class);
    assertThat(layeredArchitecture.evaluate(classes).hasViolation()).as("result has violation").isTrue();
    layeredArchitecture = layeredArchitecture.ignoreDependency(SecondThreeAnyClass.class, SomePkgClass.class);
    assertThat(layeredArchitecture.evaluate(classes).hasViolation()).as("result has violation").isFalse();
}
Also used : SecondThreeAnyClass(com.tngtech.archunit.library.testclasses.second.three.any.SecondThreeAnyClass) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SomePkgClass(com.tngtech.archunit.library.testclasses.some.pkg.SomePkgClass) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 4 with LayeredArchitecture

use of com.tngtech.archunit.library.Architectures.LayeredArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_overridden_description.

@Test
public void layered_architecture_overridden_description() {
    LayeredArchitecture architecture = layeredArchitecture().layer("One").definedBy("some.pkg..").whereLayer("One").mayNotBeAccessedByAnyLayer().as("overridden");
    assertThat(architecture.getDescription()).isEqualTo("overridden");
}
Also used : LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) Test(org.junit.Test)

Example 5 with LayeredArchitecture

use of com.tngtech.archunit.library.Architectures.LayeredArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_rejects_empty_layers_by_default.

@Test
public void layered_architecture_rejects_empty_layers_by_default() {
    LayeredArchitecture architecture = aLayeredArchitectureWithEmptyLayers();
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    EvaluationResult result = architecture.evaluate(classes);
    assertFailureLayeredArchitectureWithEmptyLayers(result);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Aggregations

LayeredArchitecture (com.tngtech.archunit.library.Architectures.LayeredArchitecture)6 Test (org.junit.Test)6 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)5 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)5 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)3 SecondThreeAnyClass (com.tngtech.archunit.library.testclasses.second.three.any.SecondThreeAnyClass)1 SomePkgClass (com.tngtech.archunit.library.testclasses.some.pkg.SomePkgClass)1