-
Notifications
You must be signed in to change notification settings - Fork 333
Layered architecture ignores violations in type parameters #144
Copy link
Copy link
Closed
Description
Given:
- A layered architecture with 2 packages "presentation" and "shared"
- presentation might access shared but not vice versa
- class in shared references class in presentation as type parameter of java.util.list
Expected:
- Error because of layered architecture violation
Actual:
- No error.
package com.archunitbug.presentation;
public class ExceptionDetails {}
package com.archunitbug.shared;
import java.util.List;
import com.archunitbug.presentation.ExceptionDetails;
public class ExceptionWithBackReference extends RuntimeException {
private List<ExceptionDetails> details;
public ExceptionWithBackReference(List<ExceptionDetails> details) {
this.details = details;
}
}
Test:
import static com.tngtech.archunit.library.Architectures.layeredArchitecture;
import org.junit.Test;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.core.importer.ImportOptions;
import com.tngtech.archunit.library.Architectures.LayeredArchitecture;
public class ArchunitLayersException {
@Test
public void enforceAllNcrLayersTopDown() {
JavaClasses classes = new ClassFileImporter(new ImportOptions().with(ImportOption.Predefined.DONT_INCLUDE_TESTS)).importPackages("com.archunitbug");
LayeredArchitecture rule = layeredArchitecture() //
.layer("presentation").definedBy("com.archunitbug.presentation") //
.layer("shared").definedBy("com.archunitbug.shared") //
.whereLayer("presentation").mayNotBeAccessedByAnyLayer()//
.whereLayer("shared").mayOnlyBeAccessedByLayers("presentation");
rule.check(classes);
}
}
Reactions are currently unavailable