Skip to content

Commit 3da3b31

Browse files
authored
#28: Change Priotities of implemented Rules (#45)
1 parent 1b5ce5b commit 3da3b31

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

src/test/java/com/devonfw/sample/archunit/AvoidCyclicDependenciesTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.tngtech.archunit.junit.AnalyzeClasses;
44
import com.tngtech.archunit.junit.ArchTest;
55
import com.tngtech.archunit.lang.ArchRule;
6+
import com.tngtech.archunit.lang.CompositeArchRule;
7+
import com.tngtech.archunit.lang.Priority;
68

79
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
810

@@ -11,13 +13,13 @@
1113
@AnalyzeClasses(packages = "com.devonfw.sample.archunit", importOptions = ImportOption.DoNotIncludeTests.class)
1214
public class AvoidCyclicDependenciesTest {
1315
@ArchTest
14-
static final ArchRule no_cyclic_dependencies_are_allowed =
15-
slices()
16-
.matching("..(*).(common|service|logic|dataaccess|batch|client)..")
17-
.namingSlices("$1 slice")
18-
.should()
19-
.beFreeOfCycles()
20-
//.ignoreDependency(alwaysTrue(), simpleNameEndingWith("Repository"))
21-
.because("Cyclic dependencies should be prevented.");
16+
static final ArchRule no_cyclic_dependencies_are_allowed = CompositeArchRule.priority(Priority.HIGH).of(
17+
slices()
18+
.matching("..(*).(common|service|logic|dataaccess|batch|client)..")
19+
.namingSlices("$1 slice")
20+
.should()
21+
.beFreeOfCycles()
22+
// .ignoreDependency(alwaysTrue(), simpleNameEndingWith("Repository"))
23+
.because("Cyclic dependencies should be prevented."));
2224

2325
}

src/test/java/com/devonfw/sample/archunit/ComponentRuleTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devonfw.sample.archunit;
22

33
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
4+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.priority;
45

56
import com.tngtech.archunit.base.DescribedPredicate;
67
import com.tngtech.archunit.core.domain.Dependency;
@@ -11,6 +12,7 @@
1112
import com.tngtech.archunit.lang.ArchCondition;
1213
import com.tngtech.archunit.lang.ArchRule;
1314
import com.tngtech.archunit.lang.ConditionEvents;
15+
import com.tngtech.archunit.lang.Priority;
1416
import com.tngtech.archunit.lang.SimpleConditionEvent;
1517

1618
@AnalyzeClasses(packages = "com.devonfw.sample.archunit", importOptions = ImportOption.DoNotIncludeTests.class)
@@ -186,7 +188,7 @@ public void check(JavaClass sourceClass, ConditionEvents events) {
186188
* verifying that the logic layer of a component may not depend on the dataaccess layer of another component.
187189
*/
188190
@ArchTest
189-
public static final ArchRule noComponentsLogicLayerDependsOnTheDataaccessLayerOfAnotherComponent = noClasses()
191+
public static final ArchRule noComponentsLogicLayerDependsOnTheDataaccessLayerOfAnotherComponent = priority(Priority.HIGH).noClasses()
190192
.that(resideInLogicLayerOfAComponent).should(dependOnDiffComponentsDataaccessLayer)
191193
.as("Code from logic layer of a component shall not depend on dataaccess layer of a different component.")
192194
.allowEmptyShould(true);

src/test/java/com/devonfw/sample/archunit/PackageRuleTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.devonfw.sample.archunit;
2-
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
2+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.priority;
33

44
import com.tngtech.archunit.core.domain.JavaClass;
55
import com.tngtech.archunit.core.importer.ImportOption;
@@ -8,6 +8,7 @@
88
import com.tngtech.archunit.lang.ArchCondition;
99
import com.tngtech.archunit.lang.ArchRule;
1010
import com.tngtech.archunit.lang.ConditionEvents;
11+
import com.tngtech.archunit.lang.Priority;
1112
import com.tngtech.archunit.lang.SimpleConditionEvent;
1213

1314
/**
@@ -18,7 +19,7 @@ public class PackageRuleTest {
1819

1920
/* ArchRule and Condition */
2021
@ArchTest
21-
public ArchRule shouldHaveValidLayers = classes().should(containsValidPackageStructureCondition());
22+
public ArchRule shouldHaveValidLayers = priority(Priority.HIGH).classes().should(containsValidPackageStructureCondition());
2223

2324
private static ArchCondition<JavaClass> containsValidPackageStructureCondition() {
2425

src/test/java/com/devonfw/sample/archunit/ThirdPartyRulesTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devonfw.sample.archunit;
22

33
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
4+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.priority;
45

56
import java.util.Arrays;
67
import java.util.HashSet;
@@ -14,6 +15,7 @@
1415
import com.tngtech.archunit.lang.ArchCondition;
1516
import com.tngtech.archunit.lang.ArchRule;
1617
import com.tngtech.archunit.lang.ConditionEvents;
18+
import com.tngtech.archunit.lang.Priority;
1719
import com.tngtech.archunit.lang.SimpleConditionEvent;
1820

1921
@AnalyzeClasses(packages = "com.devonfw.sample.archunit", importOptions = ImportOption.DoNotIncludeTests.class)
@@ -39,7 +41,7 @@ public class ThirdPartyRulesTest {
3941
+ " which implements the javax.persistence.AttributeConverter instead of the 'javax.persistance.Convert' annotation");
4042

4143
@ArchTest
42-
public static ArchRule check_mysema_dependency = noClasses().should().dependOnClassesThat()
44+
public static ArchRule check_mysema_dependency = priority(Priority.HIGH).noClasses().should().dependOnClassesThat()
4345
.resideInAPackage("com.mysema.query..")
4446
.because("Use official QueryDSL (com.querydsl.* e.g. from com.querydsl:querydsl-jpa).");
4547

@@ -62,7 +64,8 @@ public void check(JavaClass source, ConditionEvents events) {
6264
String targetFullName = dependency.getTargetClass().getFullName();
6365
String targetClassDescription = dependency.getDescription();
6466
/*
65-
* In case the project has a classic architecture using scopes, check that no API scoped class is using
67+
* In case the project has a classic architecture using scopes, check that no
68+
* API scoped class is using
6669
* 'javax.transaction.Transactional'
6770
*/
6871
if (isApiScopedClassUsingTransactional(source, targetFullName) == true) {
@@ -204,8 +207,10 @@ public void check(JavaClass source, ConditionEvents events) {
204207
events.add(new SimpleConditionEvent(source, true, message));
205208
}
206209
/*
207-
* In case the project has a classic architecture that uses scopes, check that Hibernate.Envers are only
208-
* utilized inside the impl scope of the dataaccess layer. In addition, Hibernate internals also need to be
210+
* In case the project has a classic architecture that uses scopes, check that
211+
* Hibernate.Envers are only
212+
* utilized inside the impl scope of the dataaccess layer. In addition,
213+
* Hibernate internals also need to be
209214
* used inside the impl scope of the dataaccess layer.
210215
*/
211216
if (isNotImplementingHibernateEnversInImplScope(source, targetClass) == true) {

0 commit comments

Comments
 (0)