Search in sources :

Example 6 with JavaPackage

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

the class LakosMetricsTest method lakos_metrics_of_packages.

@Test
public void lakos_metrics_of_packages() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(SomeTestClass1.class, SomeTestClass2.class);
    Set<JavaPackage> packages = ImmutableSet.of(classes.get(SomeTestClass1.class).getPackage(), classes.get(SomeTestClass2.class).getPackage());
    LakosMetrics metrics = ArchitectureMetrics.lakosMetrics(MetricsComponents.fromPackages(packages));
    assertMetrics(metrics, ExpectedMetrics.ccd(3).acd(1.5).racd(0.75).nccd(1.0));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 7 with JavaPackage

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

the class MetricsComponentsTest method creates_components_from_Java_packages.

@Test
public void creates_components_from_Java_packages() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(SomeTestClass1.class, SomeTestClass2.class);
    Set<JavaPackage> packages = ImmutableSet.of(classes.get(SomeTestClass1.class).getPackage(), classes.get(SomeTestClass2.class).getPackage());
    MetricsComponents<JavaClass> components = MetricsComponents.fromPackages(packages);
    assertThat(components).as("components").hasSize(2);
    MetricsComponent<JavaClass> component = components.tryGetComponent(SomeTestClass1.class.getPackage().getName()).get();
    assertThatTypes(component).as("elements of component " + component.getIdentifier()).matchInAnyOrder(SomeTestClass1.class, SomeSubTestClass.class);
    component = components.tryGetComponent(SomeTestClass2.class.getPackage().getName()).get();
    assertThatTypes(component).as("elements of component " + component.getIdentifier()).matchInAnyOrder(SomeTestClass2.class);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SomeTestClass1(com.tngtech.archunit.library.metrics.testobjects.lakos.pkg1.SomeTestClass1) JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Aggregations

JavaPackage (com.tngtech.archunit.core.domain.JavaPackage)7 Test (org.junit.Test)6 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)5 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)5 JavaClass (com.tngtech.archunit.core.domain.JavaClass)2 SomeClass (com.tngtech.archunit.core.importer.testexamples.SomeClass)1 SomeEnum (com.tngtech.archunit.core.importer.testexamples.SomeEnum)1 SimpleWithoutDependencies (com.tngtech.archunit.library.metrics.testobjects.componentdependency.simple.SimpleWithoutDependencies)1 SomeTestClass1 (com.tngtech.archunit.library.metrics.testobjects.lakos.pkg1.SomeTestClass1)1