Search in sources :

Example 56 with JavaClasses

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");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 57 with JavaClasses

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");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 58 with JavaClasses

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));
}
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 59 with JavaClasses

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);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 60 with JavaClasses

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();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ImportOptions(com.tngtech.archunit.core.importer.ImportOptions) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)248 Test (org.junit.Test)184 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)98 JavaClass (com.tngtech.archunit.core.domain.JavaClass)72 Test (org.junit.jupiter.api.Test)54 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)19 ArchRule (com.tngtech.archunit.lang.ArchRule)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)15 MethodCallTarget (com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 JavaConstructorCall (com.tngtech.archunit.core.domain.JavaConstructorCall)12 Set (java.util.Set)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10