Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ public static ArchCondition<JavaClass> dependOnClassesThat(DescribedPredicate<?
GET_DIRECT_DEPENDENCIES_FROM_SELF);
}

@PublicAPI(usage = ACCESS)
public static ArchCondition<JavaClass> haveAnyDependenciesThat(DescribedPredicate<? super Dependency> predicate) {
return new AnyDependencyCondition(
"have any dependencies that " + predicate.getDescription(),
predicate,
GET_DIRECT_DEPENDENCIES_FROM_SELF);
}

@PublicAPI(usage = ACCESS)
public static ArchCondition<JavaClass> transitivelyDependOnClassesThat(DescribedPredicate<? super JavaClass> predicate) {
return new TransitiveDependencyCondition(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import static com.tngtech.archunit.lang.conditions.ArchConditions.containAnyElementThat;
import static com.tngtech.archunit.lang.conditions.ArchConditions.containOnlyElementsThat;
import static com.tngtech.archunit.lang.conditions.ArchConditions.declareThrowableOfType;
import static com.tngtech.archunit.lang.conditions.ArchConditions.dependOnClassesThat;
import static com.tngtech.archunit.lang.conditions.ArchConditions.have;
import static com.tngtech.archunit.lang.conditions.ArchConditions.haveAnyDependenciesThat;
import static com.tngtech.archunit.lang.conditions.ArchConditions.never;
import static com.tngtech.archunit.lang.conditions.ArchConditions.not;
import static com.tngtech.archunit.lang.conditions.ArchConditions.onlyBeAccessedByAnyPackage;
Expand Down Expand Up @@ -164,6 +166,38 @@ public void only_have_dependents_where() {
.containNoViolation();
}

@Test
public void depend_on_classes_that() {
JavaClasses classes = importClasses(CallingClass.class, SomeClass.class);
JavaClass callingClass = classes.get(CallingClass.class);

assertThat(dependOnClassesThat(alwaysFalse()))
.checking(callingClass)
.haveAtLeastOneViolationMessageMatching(String.format(".*%s.*%s.*",
quote(CallingClass.class.getName()), quote(SomeClass.class.getName())));

assertThat(dependOnClassesThat(DescribedPredicate.<JavaClass>alwaysTrue().as("custom")))
.hasDescription("depend on classes that custom")
.checking(callingClass)
.containNoViolation();
}

@Test
public void have_any_dependencies_that() {
JavaClasses classes = importClasses(CallingClass.class, SomeClass.class);
JavaClass callingClass = classes.get(CallingClass.class);

assertThat(haveAnyDependenciesThat(alwaysFalse()))
.checking(callingClass)
.haveAtLeastOneViolationMessageMatching(String.format(".*%s.*%s.*",
quote(CallingClass.class.getName()), quote(SomeClass.class.getName())));

assertThat(haveAnyDependenciesThat(DescribedPredicate.<Dependency>alwaysTrue().as("custom")))
.hasDescription("have dependencies that custom")
.checking(callingClass)
.containNoViolation();
}

@Test
public void declare_throwable_of_type() {
class Failure {
Expand Down