Search in sources :

Example 96 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class AbstractClassesTransformerTest method transform_javaclasses.

@Test
public void transform_javaclasses() {
    AbstractClassesTransformer<String> transformer = toNameTransformer();
    JavaClasses classes = importClassesWithContext(AbstractClassesTransformer.class, AbstractClassesTransformerTest.class);
    DescribedIterable<String> transformed = transformer.transform(classes);
    assertThat(transformed).containsOnly(AbstractClassesTransformer.class.getName(), AbstractClassesTransformerTest.class.getName());
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 97 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class AbstractClassesTransformerTest method description_is_extended_by_predicate.

@Test
public void description_is_extended_by_predicate() {
    ClassesTransformer<String> transformer = toNameTransformer().as("names").that(endInTest().as("end in Test"));
    JavaClasses classes = importClassesWithContext(AbstractClassesTransformer.class, AbstractClassesTransformerTest.class);
    DescribedIterable<String> transformed = transformer.transform(classes);
    assertThat(transformed.getDescription()).isEqualTo("names that end in Test");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 98 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class AbstractClassesTransformerTest method description_can_be_overwritten.

@Test
public void description_can_be_overwritten() {
    ClassesTransformer<String> transformer = toNameTransformer().as("names").that(endInTest().as("end in Test")).as("override");
    JavaClasses classes = importClassesWithContext(AbstractClassesTransformer.class, AbstractClassesTransformerTest.class);
    DescribedIterable<String> transformed = transformer.transform(classes);
    assertThat(transformed.getDescription()).isEqualTo("override");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 99 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterAccessesTest method dependency_target_classes_are_derived_correctly.

@Test
public void dependency_target_classes_are_derived_correctly() {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/integration"));
    JavaClass javaClass = classes.get(ClassXDependingOnClassesABCD.class);
    Set<JavaClass> expectedTargetClasses = ImmutableSet.of(classes.get(ClassA.class), classes.get(ClassBDependingOnClassA.class), classes.get(ClassCDependingOnClassB_SuperclassOfX.class), classes.get(ClassD.class), classes.get(InterfaceOfClassX.class));
    Set<JavaClass> targetClasses = withoutJavaLangTargets(javaClass.getDirectDependenciesFromSelf()).stream().map(Dependency::getTargetClass).collect(toSet());
    assertThat(targetClasses).isEqualTo(expectedTargetClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassCDependingOnClassB_SuperclassOfX(com.tngtech.archunit.core.importer.testexamples.integration.ClassCDependingOnClassB_SuperclassOfX) JavaClass(com.tngtech.archunit.core.domain.JavaClass) InterfaceOfClassX(com.tngtech.archunit.core.importer.testexamples.integration.InterfaceOfClassX) ClassBDependingOnClassA(com.tngtech.archunit.core.importer.testexamples.integration.ClassBDependingOnClassA) ClassD(com.tngtech.archunit.core.importer.testexamples.integration.ClassD) ClassA(com.tngtech.archunit.core.importer.testexamples.integration.ClassA) ClassBDependingOnClassA(com.tngtech.archunit.core.importer.testexamples.integration.ClassBDependingOnClassA) Test(org.junit.Test)

Example 100 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterAccessesTest method classes_know_method_calls_to_themselves.

@Test
public void classes_know_method_calls_to_themselves() {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/dependents"));
    JavaClass classHoldingDependencies = classes.get(ClassHoldingDependencies.class);
    JavaClass firstClassWithDependency = classes.get(FirstClassWithDependency.class);
    JavaClass secondClassWithDependency = classes.get(SecondClassWithDependency.class);
    Set<JavaMethodCall> calls = classHoldingDependencies.getMethodCallsToSelf();
    Set<JavaMethodCall> expected = ImmutableSet.<JavaMethodCall>builder().addAll(classHoldingDependencies.getMethodCallsFromSelf()).addAll(getByTargetOwner(firstClassWithDependency.getMethodCallsFromSelf(), classHoldingDependencies)).addAll(getByTargetOwner(secondClassWithDependency.getMethodCallsFromSelf(), classHoldingDependencies)).build();
    assertThat(calls).as("Method calls to class").isEqualTo(expected);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaMethodCall(com.tngtech.archunit.core.domain.JavaMethodCall) Test(org.junit.Test)

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