use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class SlicesTest method name_parts_are_resolved_correctly.
@Test
public void name_parts_are_resolved_correctly() {
JavaClasses classes = importClassesWithContext(Object.class);
DescribedIterable<Slice> slices = Slices.matching("(*).(*)..").transform(classes);
assertThat(getOnlyElement(slices).getNamePart(1)).isEqualTo("java");
assertThat(getOnlyElement(slices).getNamePart(2)).isEqualTo("lang");
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class SlicesTest method matching_description.
@Test
public void matching_description() {
JavaClasses classes = importClassesWithContext(Object.class);
Slices.Transformer transformer = Slices.matching("java.(*)..");
assertThat(transformer.getDescription()).isEqualTo("slices matching 'java.(*)..'");
Slices slices = transformer.transform(classes);
assertThat(slices.getDescription()).isEqualTo("slices matching 'java.(*)..'");
slices = transformer.that(DescribedPredicate.<Slice>alwaysTrue().as("changed")).transform(classes);
assertThat(slices.getDescription()).isEqualTo("slices matching 'java.(*)..' that changed");
}
use of com.tngtech.archunit.core.domain.JavaClasses 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.JavaClasses in project ArchUnit by TNG.
the class ClassCacheTest method distinguishes_import_option_when_caching.
@Test
public void distinguishes_import_option_when_caching() {
JavaClasses importingWholeClasspathWithFilter = cache.getClassesToAnalyzeFor(TestClass.class, new TestAnalysisRequest().withImportOptions(TestFilterForJUnitJars.class));
JavaClasses importingWholeClasspathWithEquivalentButDifferentFilter = cache.getClassesToAnalyzeFor(EquivalentTestClass.class, new TestAnalysisRequest().withImportOptions(AnotherTestFilterForJUnitJars.class));
assertThat(importingWholeClasspathWithFilter).as("number of classes imported").hasSameSizeAs(importingWholeClasspathWithEquivalentButDifferentFilter);
verifyNumberOfImports(2);
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassCacheTest method when_there_are_only_nonexisting_sources_nothing_is_imported.
@Test
@UseDataProvider("test_classes_without_any_imported_classes")
public void when_there_are_only_nonexisting_sources_nothing_is_imported(TestAnalysisRequest analysisRequest) {
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, analysisRequest);
assertThat(classes).isEmpty();
verify(cacheClassFileImporter).importClasses(any(ImportOptions.class), locationCaptor.capture());
assertThat(locationCaptor.getValue()).isEmpty();
}
Aggregations