Skip to content

Commit

Permalink
add more rules for architecture testing
Browse files Browse the repository at this point in the history
  • Loading branch information
WeRockStar committed Mar 20, 2024
1 parent 0d32c1e commit ae66c41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.kampus.kbazaar.architecture;

import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_USE_FIELD_INJECTION;

@AnalyzeClasses(
packages = "com.kampus.kbazaar",
importOptions = ImportOption.DoNotIncludeTests.class)
public class CodingRuleTest {

@ArchTest
private final ArchRule no_field_injection = NO_CLASSES_SHOULD_USE_FIELD_INJECTION;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kampus.kbazaar.architecture;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;

import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
Expand Down Expand Up @@ -36,4 +37,23 @@ public class DependencyRuleTest {
.byClassesThat()
.areAnnotatedWith(Service.class)
.allowEmptyShould(true);

@ArchTest
static final ArchRule repository_should_not_access_services =
noClasses()
.that()
.haveSimpleNameEndingWith("Repository")
.should()
.accessClassesThat()
.haveSimpleNameEndingWith("Service");

@ArchTest
static final ArchRule service_should_not_access_controller =
noClasses()
.that()
.haveSimpleNameEndingWith("Service")
.should()
.accessClassesThat()
.haveSimpleNameEndingWith("Controller")
.allowEmptyShould(true);
}

0 comments on commit ae66c41

Please sign in to comment.