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());
}
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");
}
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");
}
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);
}
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);
}
Aggregations