use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class SlicesShouldTest method slice_rules_should_ignore_configured_dependencies.
@Test
@UseDataProvider("rules")
public void slice_rules_should_ignore_configured_dependencies(SliceRule rule) {
JavaClasses classes = new ClassFileImporter().importPackages(TEST_CLASSES_PACKAGE);
assertViolations(classes, rule).contain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(classIn(".*\\.first\\.three\\..*"), DescribedPredicate.<JavaClass>alwaysTrue());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(FirstAnyPkgClass.class.getName(), SomePkgSubclass.class.getName());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(SecondAnyClass.class, FirstAnyPkgClass.class);
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(DescribedPredicate.<JavaClass>alwaysTrue(), classIn(".*\\.some\\.pkg\\..*"));
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).doNotContain(SecondThreeAnyClass.class, SomePkgClass.class);
}
use of com.tngtech.archunit.core.importer.ClassFileImporter 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.importer.ClassFileImporter in project ArchUnit by TNG.
the class ClassCacheTest method if_whole_classpath_is_set_true_then_the_whole_classpath_is_imported.
@Test
public void if_whole_classpath_is_set_true_then_the_whole_classpath_is_imported() {
TestAnalysisRequest defaultOptions = new TestAnalysisRequest().withWholeClasspath(true);
Class<?>[] expectedImportResult = new Class[] { getClass() };
doReturn(new ClassFileImporter().importClasses(expectedImportResult)).when(cacheClassFileImporter).importClasses(any(ImportOptions.class), ArgumentMatchers.<Location>anyCollection());
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, defaultOptions);
assertThatTypes(classes).matchExactly(expectedImportResult);
verify(cacheClassFileImporter).importClasses(any(ImportOptions.class), locationCaptor.capture());
assertThat(locationCaptor.getValue()).has(locationContaining("archunit")).has(locationContaining("asm")).has(locationContaining("google")).has(locationContaining("mockito"));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method predicate_containAnyMembersThat.
@Test
public void predicate_containAnyMembersThat() {
@SuppressWarnings("unused")
class Match {
String right;
}
@SuppressWarnings("unused")
class Mismatch {
String wrong;
}
JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
assertThat(containAnyMembersThat(name("right"))).hasDescription("contain any members that name 'right'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaClassTest method erased_type_of_class_is_the_class_itself.
@Test
public void erased_type_of_class_is_the_class_itself() {
class SimpleClass {
}
JavaType type = new ClassFileImporter().importClass(SimpleClass.class);
assertThat(type.toErasure()).isEqualTo(type);
}
Aggregations