1

Add tests for Service Architecture in ServiceTest

This commit is contained in:
XXNitram
2020-03-10 16:44:58 +01:00
parent 7dc1414e76
commit 4f619c6963

View File

@ -0,0 +1,39 @@
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.Service;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
public class ServiceTest {
@ArchTest
public static final ArchRule serviceClassesShouldHaveServiceInName = classes()
.that().areAnnotatedWith(Service.class)
.should().haveSimpleNameEndingWith("Service");
@ArchTest
public static final ArchRule serviceClassesShouldBeAnnotatedWithService = classes()
.that().haveSimpleNameEndingWith("Service")
.should().beAnnotatedWith(Service.class);
@ArchTest
public static final ArchRule serviceClassesShouldBeInServicePackage = classes()
.that().areAnnotatedWith(Service.class)
.should().resideInAPackage("..service..");
@ArchTest
public static final ArchRule classesInServicePackageShouldHaveServiceInName = classes()
.that().resideInAPackage("..service..")
.should().haveSimpleNameEndingWith("Service");
@ArchTest
public static final ArchRule serviceClassesShouldOnlyBeAccessedByControllerOrServiceClasses = classes()
.that().resideInAPackage("..service..")
.should().onlyBeAccessed().byAnyPackage("..controller..", "..service..");
}