use of com.tngtech.archunit.core.domain.Dependency in project ArchUnit by TNG.
the class ExpectedDependency method correspondsTo.
@Override
public boolean correspondsTo(Object object) {
if (!(object instanceof Dependency)) {
return false;
}
Dependency dependency = (Dependency) object;
boolean originMatches = dependency.getOriginClass().isEquivalentTo(origin);
boolean targetMatches = dependency.getTargetClass().isEquivalentTo(target);
boolean descriptionMatches = dependency.getDescription().matches(dependencyPattern);
return originMatches && targetMatches && descriptionMatches;
}
use of com.tngtech.archunit.core.domain.Dependency in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method getDirectDependencies_does_not_return_transitive_dependencies.
@Test
public void getDirectDependencies_does_not_return_transitive_dependencies() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/integration"));
JavaClass javaClass = classes.get(ClassCDependingOnClassB_SuperclassOfX.class);
JavaClass expectedTargetClass = classes.get(ClassBDependingOnClassA.class);
Set<JavaClass> targetClasses = javaClass.getDirectDependenciesFromSelf().stream().map(Dependency::getTargetClass).filter(targetClass -> targetClass.getPackageName().contains("testexamples")).collect(toSet());
assertThat(targetClasses).containsOnly(expectedTargetClass);
}
use of com.tngtech.archunit.core.domain.Dependency in project ArchUnit by TNG.
the class SlicesTest method slices_of_dependencies.
@Test
public void slices_of_dependencies() {
JavaMethod methodThatCallsJavaUtil = TestUtils.importClassWithContext(Object.class).getMethod("toString");
JavaMethod methodThatCallsJavaLang = TestUtils.importClassWithContext(Map.class).getMethod("put", Object.class, Object.class);
simulateCall().from(methodThatCallsJavaUtil, 5).to(methodThatCallsJavaLang);
simulateCall().from(methodThatCallsJavaLang, 1).to(methodThatCallsJavaUtil);
Dependency first = dependencyFrom(getOnlyElement(methodThatCallsJavaUtil.getMethodCallsFromSelf()));
Dependency second = dependencyFrom(getOnlyElement(methodThatCallsJavaLang.getMethodCallsFromSelf()));
Slices slices = Slices.matching("java.(*)..").transform(ImmutableSet.of(first, second));
assertThat(slices).extractingResultOf("getDescription").containsOnly("Slice lang", "Slice util");
}
use of com.tngtech.archunit.core.domain.Dependency in project ArchUnit by TNG.
the class ArchConditionsTest method only_have_dependents_where.
@Test
public void only_have_dependents_where() {
JavaClasses classes = importClasses(CallingClass.class, SomeClass.class);
JavaClass accessedClass = classes.get(SomeClass.class);
assertThat(onlyHaveDependentsWhere(DescribedPredicate.<Dependency>alwaysFalse())).checking(accessedClass).haveAtLeastOneViolationMessageMatching(String.format(".*%s.*%s.*", quote(CallingClass.class.getName()), quote(SomeClass.class.getName())));
assertThat(onlyHaveDependentsWhere(DescribedPredicate.<Dependency>alwaysTrue().as("custom"))).hasDescription("only have dependents where custom").checking(accessedClass).containNoViolation();
}
Aggregations