Search in sources :

Example 1 with JavaPackage

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

the class ComponentDependencyMetricsTest method component_dependency_metrics_of_an_isolated_component.

@Test
public void component_dependency_metrics_of_an_isolated_component() {
    JavaPackage javaPackage = new ClassFileImporter().importPackagesOf(SimpleWithoutDependencies.class).get(SimpleWithoutDependencies.class).getPackage();
    MetricsComponents<JavaClass> components = MetricsComponents.fromPackages(singleton(javaPackage));
    ComponentDependencyMetrics metrics = ArchitectureMetrics.componentDependencyMetrics(components);
    assertThat(metrics.getEfferentCoupling(javaPackage.getName())).as("Efferent Coupling of " + javaPackage.getName()).isEqualTo(0);
    assertThat(metrics.getAfferentCoupling(javaPackage.getName())).as("Afferent Coupling of " + javaPackage.getName()).isEqualTo(0);
    assertThat(metrics.getInstability(javaPackage.getName())).as("Instability of " + javaPackage.getName()).isEqualTo(1);
    assertThat(metrics.getAbstractness(javaPackage.getName())).as("Abstractness of " + javaPackage.getName()).isEqualTo(0);
    assertThat(metrics.getNormalizedDistanceFromMainSequence(javaPackage.getName())).as("Normalized Distance from Main Sequence of " + javaPackage.getName()).isEqualTo(0);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) SimpleWithoutDependencies(com.tngtech.archunit.library.metrics.testobjects.componentdependency.simple.SimpleWithoutDependencies) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 2 with JavaPackage

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

the class VisibilityMetricsTest method calculates_visibility_metrics_for_Java_classes_according_to_their_modifier.

@Test
public void calculates_visibility_metrics_for_Java_classes_according_to_their_modifier() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(VisibleOne.class, VisibleTwo.class);
    JavaPackage packageOne = classes.getPackage(VisibleOne.class.getPackage().getName());
    JavaPackage packageTwo = classes.getPackage(VisibleTwo.class.getPackage().getName());
    VisibilityMetrics metrics = ArchitectureMetrics.visibilityMetrics(MetricsComponents.fromPackages(ImmutableSet.of(packageOne, packageTwo)));
    assertThat(metrics.getRelativeVisibility(packageOne.getName())).isEqualTo(0.5);
    assertThat(metrics.getRelativeVisibility(packageTwo.getName())).isEqualTo(1.0);
    assertThat(metrics.getAverageRelativeVisibility()).isEqualTo(0.75);
    assertThat(metrics.getGlobalRelativeVisibility()).isCloseTo(0.66, offset(0.01));
}
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 3 with JavaPackage

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

the class ClassFileImporterSlowTest method creates_JavaPackages.

@Test
public void creates_JavaPackages() {
    JavaClasses javaClasses = importJavaBase();
    JavaPackage defaultPackage = javaClasses.getDefaultPackage();
    assertThat(defaultPackage.containsPackage("java")).as("Created default package contains 'java'").isTrue();
    JavaPackage javaPackage = defaultPackage.getPackage("java.lang");
    assertThatTypes(javaPackage.getClasses()).contain(Object.class, String.class, Integer.class);
    assertThatTypes(javaPackage.getAllClasses()).contain(Object.class, Annotation.class, Field.class);
    assertThat(javaClasses.containPackage("java.util")).as("Classes contain package 'java.util'").isTrue();
    assertThatTypes(javaClasses.getPackage("java.util").getClasses()).contain(List.class);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) Test(org.junit.Test)

Example 4 with JavaPackage

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

the class ClassFileImporterTest method creates_JavaPackages_for_each_JavaClass.

@Test
public void creates_JavaPackages_for_each_JavaClass() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass());
    JavaPackage javaPackage = classes.get(SomeClass.class).getPackage();
    assertThat(javaPackage.containsClass(SomeEnum.class)).as("Package contains " + SomeEnum.class).isTrue();
    assertThatTypes(javaPackage.getParent().get().getClasses()).contain(getClass());
}
Also used : SomeEnum(com.tngtech.archunit.core.importer.testexamples.SomeEnum) SomeClass(com.tngtech.archunit.core.importer.testexamples.SomeClass) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) Test(org.junit.Test)

Example 5 with JavaPackage

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

the class ComponentDependencyMetricsTest method importTestGraph.

private MetricsComponents<JavaClass> importTestGraph() {
    String graphPackage = testGraphPackageName();
    Set<JavaPackage> packages = new ClassFileImporter().importPackages(graphPackage).getPackage(graphPackage).getSubpackages();
    return MetricsComponents.fromPackages(packages);
}
Also used : JavaPackage(com.tngtech.archunit.core.domain.JavaPackage) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter)

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