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);
}
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));
}
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);
}
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());
}
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);
}
Aggregations