|
36 | 36 | import static com.tngtech.archunit.lang.conditions.ArchConditions.containAnyElementThat; |
37 | 37 | import static com.tngtech.archunit.lang.conditions.ArchConditions.containOnlyElementsThat; |
38 | 38 | import static com.tngtech.archunit.lang.conditions.ArchConditions.declareThrowableOfType; |
| 39 | +import static com.tngtech.archunit.lang.conditions.ArchConditions.dependOnClassesThat; |
39 | 40 | import static com.tngtech.archunit.lang.conditions.ArchConditions.have; |
| 41 | +import static com.tngtech.archunit.lang.conditions.ArchConditions.haveDependenciesThat; |
40 | 42 | import static com.tngtech.archunit.lang.conditions.ArchConditions.never; |
41 | 43 | import static com.tngtech.archunit.lang.conditions.ArchConditions.not; |
42 | 44 | import static com.tngtech.archunit.lang.conditions.ArchConditions.onlyBeAccessedByAnyPackage; |
@@ -164,6 +166,38 @@ public void only_have_dependents_where() { |
164 | 166 | .containNoViolation(); |
165 | 167 | } |
166 | 168 |
|
| 169 | + @Test |
| 170 | + public void depend_on_classes_that() { |
| 171 | + JavaClasses classes = importClasses(CallingClass.class, SomeClass.class); |
| 172 | + JavaClass callingClass = classes.get(CallingClass.class); |
| 173 | + |
| 174 | + assertThat(dependOnClassesThat(alwaysFalse())) |
| 175 | + .checking(callingClass) |
| 176 | + .haveAtLeastOneViolationMessageMatching(String.format(".*%s.*%s.*", |
| 177 | + quote(CallingClass.class.getName()), quote(SomeClass.class.getName()))); |
| 178 | + |
| 179 | + assertThat(dependOnClassesThat(DescribedPredicate.<JavaClass>alwaysTrue().as("custom"))) |
| 180 | + .hasDescription("depend on classes that custom") |
| 181 | + .checking(callingClass) |
| 182 | + .containNoViolation(); |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + public void have_dependencies_that() { |
| 187 | + JavaClasses classes = importClasses(CallingClass.class, SomeClass.class); |
| 188 | + JavaClass callingClass = classes.get(CallingClass.class); |
| 189 | + |
| 190 | + assertThat(haveDependenciesThat(alwaysFalse())) |
| 191 | + .checking(callingClass) |
| 192 | + .haveAtLeastOneViolationMessageMatching(String.format(".*%s.*%s.*", |
| 193 | + quote(CallingClass.class.getName()), quote(SomeClass.class.getName()))); |
| 194 | + |
| 195 | + assertThat(haveDependenciesThat(DescribedPredicate.<Dependency>alwaysTrue().as("custom"))) |
| 196 | + .hasDescription("have dependencies that custom") |
| 197 | + .checking(callingClass) |
| 198 | + .containNoViolation(); |
| 199 | + } |
| 200 | + |
167 | 201 | @Test |
168 | 202 | public void declare_throwable_of_type() { |
169 | 203 | class Failure { |
|
0 commit comments