Skip to content

Commit 17a1160

Browse files
rhe-bochankem
authored andcommitted
allow explicit priority config in SlicesRuleDefinition
Resolves: #1434 Signed-off-by: riverhe <rhe@bank-banque-canada.ca>
1 parent bb50989 commit 17a1160

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

archunit-example/example-plain/src/test/java/com/tngtech/archunit/exampletest/CyclicDependencyRulesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.tngtech.archunit.core.importer.ClassFileImporter;
66
import com.tngtech.archunit.example.cycles.complexcycles.slice1.SliceOneCallingConstructorInSliceTwoAndMethodInSliceThree;
77
import com.tngtech.archunit.example.cycles.complexcycles.slice3.ClassCallingConstructorInSliceFive;
8+
import com.tngtech.archunit.lang.Priority;
89
import com.tngtech.archunit.library.dependencies.SliceAssignment;
910
import com.tngtech.archunit.library.dependencies.SliceIdentifier;
1011
import org.junit.Test;
@@ -80,7 +81,7 @@ public void no_cycles_in_complex_scenario_with_custom_ignore() {
8081

8182
@Test
8283
public void no_cycles_in_freely_customized_slices() {
83-
slices().assignedFrom(inComplexSliceOneOrTwo())
84+
slices().assignedFrom(inComplexSliceOneOrTwo(), Priority.HIGH)
8485
.namingSlices("$1[$2]")
8586
.should().beFreeOfCycles()
8687
.check(classes);

archunit/src/main/java/com/tngtech/archunit/library/dependencies/SlicesRuleDefinition.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,31 @@ private Creator() {
6464
*/
6565
@PublicAPI(usage = ACCESS)
6666
public GivenSlices matching(String packageIdentifier) {
67-
return new GivenSlicesInternal(Priority.MEDIUM, Slices.matching(packageIdentifier));
67+
return matching(packageIdentifier, Priority.MEDIUM);
68+
}
69+
70+
/**
71+
* @see Slices#matching(String)
72+
*/
73+
@PublicAPI(usage = ACCESS)
74+
public GivenSlices matching(String packageIdentifier, Priority priority) {
75+
return new GivenSlicesInternal(priority, Slices.matching(packageIdentifier));
6876
}
6977

7078
/**
7179
* @see Slices#assignedFrom(SliceAssignment)
7280
*/
7381
@PublicAPI(usage = ACCESS)
7482
public GivenSlices assignedFrom(SliceAssignment assignment) {
75-
return new GivenSlicesInternal(Priority.MEDIUM, Slices.assignedFrom(assignment));
83+
return assignedFrom(assignment, Priority.MEDIUM);
84+
}
85+
86+
/**
87+
* @see Slices#assignedFrom(SliceAssignment)
88+
*/
89+
@PublicAPI(usage = ACCESS)
90+
public GivenSlices assignedFrom(SliceAssignment assignment, Priority priority) {
91+
return new GivenSlicesInternal(priority, Slices.assignedFrom(assignment));
7692
}
7793
}
7894
}

archunit/src/test/java/com/tngtech/archunit/library/dependencies/GivenSlicesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.tngtech.archunit.lang.ArchCondition;
1010
import com.tngtech.archunit.lang.ConditionEvents;
1111
import com.tngtech.archunit.lang.EvaluationResult;
12+
import com.tngtech.archunit.lang.Priority;
1213
import com.tngtech.archunit.lang.syntax.elements.GivenConjunction;
1314
import com.tngtech.archunit.library.LayeredArchitectureTest;
1415
import com.tngtech.archunit.library.dependencies.syntax.GivenSlices;
@@ -72,7 +73,7 @@ public void restricting_slices_that_should_not_depend_on_each_other() {
7273
}
7374

7475
private GivenSlices testSlices() {
75-
return slices().matching(TEST_CLASSES_PACKAGE + ".(*)..");
76+
return slices().matching(TEST_CLASSES_PACKAGE + ".(*)..", Priority.HIGH);
7677
}
7778

7879
private DescribedPredicate<Slice> descriptionMatching(String regex) {

0 commit comments

Comments
 (0)