Search in sources :

Example 41 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project auth0-full-stack-java-example by oktadev.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("com.auth0.flickr2");
    noClasses().that().resideInAnyPackage("com.auth0.flickr2.service..").or().resideInAnyPackage("com.auth0.flickr2.repository..").should().dependOnClassesThat().resideInAnyPackage("..com.auth0.flickr2.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 42 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class GivenThatIsTestedConsistentlyTest method classes_that_tests_all_relevant_methods.

@Test
public void classes_that_tests_all_relevant_methods() {
    JavaClasses classes = importClassesWithContext(GivenClassesThatTest.class, ClassesThat.class);
    JavaClass test = classes.get(GivenClassesThatTest.class);
    for (JavaMethod method : classes.get(ClassesThat.class).getMethods()) {
        assertAccessFrom(test, method);
    }
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) Test(org.junit.Test)

Example 43 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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 44 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_rejects_empty_layers_by_default.

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

Example 45 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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)

Aggregations

JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)248 Test (org.junit.Test)184 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)98 JavaClass (com.tngtech.archunit.core.domain.JavaClass)72 Test (org.junit.jupiter.api.Test)54 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)19 ArchRule (com.tngtech.archunit.lang.ArchRule)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)15 MethodCallTarget (com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 JavaConstructorCall (com.tngtech.archunit.core.domain.JavaConstructorCall)12 Set (java.util.Set)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10