GH-182 - Use dedicated SliceAssignment to verify modularity.
The previous modularity verification arrangement assumed the default module detection strategy to be used. To properly support alternative implementations during the verification we now use a dedicated SliceAssignment implementation that assigns types to slices identified by the module they are located in.
This commit is contained in:
@@ -48,6 +48,8 @@ import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
import com.tngtech.archunit.lang.EvaluationResult;
|
||||
import com.tngtech.archunit.lang.FailureReport;
|
||||
import com.tngtech.archunit.library.dependencies.SliceAssignment;
|
||||
import com.tngtech.archunit.library.dependencies.SliceIdentifier;
|
||||
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition;
|
||||
|
||||
/**
|
||||
@@ -455,7 +457,7 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
|
||||
private FailureReport assertNoCyclesFor(JavaPackage rootPackage) {
|
||||
|
||||
var result = SlicesRuleDefinition.slices() //
|
||||
.matching(rootPackage.getName().concat(".(*)..")) //
|
||||
.assignedFrom(new ApplicationModulesSliceAssignment())
|
||||
.should().beFreeOfCycles() //
|
||||
.evaluate(allClasses.that(resideInAPackage(rootPackage.getName().concat(".."))));
|
||||
|
||||
@@ -728,4 +730,29 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ApplicationModulesSliceAssignment implements SliceAssignment {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.tngtech.archunit.library.dependencies.SliceAssignment#getIdentifierOf(com.tngtech.archunit.core.domain.JavaClass)
|
||||
*/
|
||||
@Override
|
||||
public SliceIdentifier getIdentifierOf(JavaClass javaClass) {
|
||||
|
||||
return getModuleByType(javaClass)
|
||||
.map(ApplicationModule::getName)
|
||||
.map(SliceIdentifier::of)
|
||||
.orElse(SliceIdentifier.ignore());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.tngtech.archunit.base.HasDescription#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Appliction module slices " + ApplicationModules.this.modules.keySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user