use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class JavaClassDiagramAssociationTest method class_resides_in_multiple_packages.
@Test
public void class_resides_in_multiple_packages() {
JavaClassDiagramAssociation javaClassDiagramAssociation = createAssociation(TestDiagram.in(temporaryFolder).component("A").withStereoTypes("..foopackage..").component("B").withStereoTypes("..barpackage").write());
JavaClass classContainedInTwoComponents = importClassWithContext(ClassInFooAndBarPackage.class);
thrown.expect(ComponentIntersectionException.class);
thrown.expectMessage(String.format("Class %s may not be contained in more than one component, but is contained in [A, B]", ClassInFooAndBarPackage.class.getName()));
javaClassDiagramAssociation.getTargetPackageIdentifiers(classContainedInTwoComponents);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class JavaClassDiagramAssociationTest method rejects_class_not_contained_in_any_component.
@Test
public void rejects_class_not_contained_in_any_component() {
JavaClassDiagramAssociation javaClassDiagramAssociation = createAssociation(TestDiagram.in(temporaryFolder).component("SomeComponent").withStereoTypes("..someStereotype.").write());
JavaClass classNotContained = importClassWithContext(Object.class);
thrown.expect(IllegalStateException.class);
thrown.expectMessage(String.format("Class %s is not contained in any component", Object.class.getName()));
javaClassDiagramAssociation.getTargetPackageIdentifiers(classNotContained);
}
use of com.tngtech.archunit.core.domain.JavaClass 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.JavaClass in project ArchUnit by TNG.
the class ShouldClassesThatTest method containAnyStaticInitializersThat.
@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void containAnyStaticInitializersThat(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
ArchRule rule = noClassesShouldThatRuleStart.containAnyStaticInitializersThat(have(fullNameMatching(quote(Data_of_containAnyMembersThat.ViolatingTarget.class.getName()) + ".*")));
Set<JavaClass> classes = filterClassesAppearingInFailureReport(rule).on(Data_of_containAnyMembersThat.OkayOrigin.class, Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.OkayTarget.class, Data_of_containAnyMembersThat.ViolatingTarget.class);
assertThatTypes(classes).matchInAnyOrder(Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.ViolatingTarget.class);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ShouldOnlyByClassesThatTest method containAnyStaticInitializersThat.
@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void containAnyStaticInitializersThat(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
ArchRule rule = classesShouldOnlyBeBy.containAnyStaticInitializersThat(have(fullNameMatching(quote(Data_of_containAnyMembersThat.OkayOrigin.class.getName()) + ".*")));
Set<JavaClass> classes = filterClassesAppearingInFailureReport(rule).on(Data_of_containAnyMembersThat.OkayOrigin.class, Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.Target.class);
assertThatTypes(classes).matchInAnyOrder(Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.Target.class);
}
Aggregations