From 05218e8167e6ffb3f666b9ea8b32bdb9c4659526 Mon Sep 17 00:00:00 2001 From: XXNitram Date: Tue, 10 Mar 2020 16:41:05 +0100 Subject: [PATCH] Separate Tests into different classes, starting with ControllerTest --- .../gruppen2/architecture/ControllerTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/mops/gruppen2/architecture/ControllerTest.java diff --git a/src/test/java/mops/gruppen2/architecture/ControllerTest.java b/src/test/java/mops/gruppen2/architecture/ControllerTest.java new file mode 100644 index 0000000..8079fa8 --- /dev/null +++ b/src/test/java/mops/gruppen2/architecture/ControllerTest.java @@ -0,0 +1,53 @@ +package mops.gruppen2.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 org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) +public class ControllerTest { + + @ArchTest + public static final ArchRule controllerClassesShouldBeAnnotatedWithControllerOrRestControllerAnnotation = classes() + .that().haveSimpleNameEndingWith("Controller") + .should().beAnnotatedWith(Controller.class) + .orShould().beAnnotatedWith(RestController.class); + + @ArchTest + public static final ArchRule controllerClassesShouldHaveControllerInName = classes() + .that().areAnnotatedWith(Controller.class) + .or().areAnnotatedWith(RestController.class) + .should().haveSimpleNameEndingWith("Controller"); + + @ArchTest + public static final ArchRule controllerClassesShouldBeInControllerPackage = classes() + .that().areAnnotatedWith(Controller.class) + .or().areAnnotatedWith(RestController.class) + .should().resideInAPackage("..controller.."); + + @ArchTest + public static final ArchRule classesInControllerPackageShouldHaveControllerInName = classes() + .that().resideInAPackage("..controller..") + .should().haveSimpleNameEndingWith("Controller"); + + @ArchTest + public static final ArchRule controllerClassesShouldHaveRequestMappingAnnotation = classes() + .that().resideInAPackage("..controller..") + .and().haveSimpleNameEndingWith("Controller") + .and().areAnnotatedWith(Controller.class) + .or().areAnnotatedWith(RestController.class) + .should().beAnnotatedWith(RequestMapping.class); + + @ArchTest + public static final ArchRule controllerClassesShouldNotDependOnEachOther = noClasses() + .that().haveSimpleNameEndingWith("Controller") + .should().dependOnClassesThat().haveNameMatching("Controller"); + +}