package com.baloise.automagic.architecture

import com.tngtech.archunit.core.importer.ImportOption
import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.junit.ArchUnitRunner
import com.tngtech.archunit.lang.ArchRule
import org.junit.runner.RunWith

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

@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(
        packages = "com.baloise.automagic",
        importOptions =
                ImportOption.DoNotIncludeTests.class
)
class ArchitectureCheck {

    @ArchTest
    private static final ArchRule ALL_INTERNAL_CLASSES_SHOULD_BE_SERIALIZABLE = classes()
            .that()
            .resideInAPackage("..internal..")
			.and()
			.areNotInterfaces()
            .should()
            .implement(Serializable.class)

    @ArchTest
    private static final ArchRule ALL_INTERFACES_SHOULD_BE_NAMED_SERVICE = classes()
            .that()
            .areInterfaces()
			.and()
			.resideOutsideOfPackage("..internal..")
			.and()
			.doNotHaveSimpleName("Constructed")
            .should()
            .haveSimpleNameEndingWith("Service");

    @ArchTest
    private static final ArchRule CLASSES_SHOULD_NOT_END_WITH_SERVICE = classes()
            .that()
            .areNotInterfaces()
            .should()
            .haveSimpleNameNotEndingWith("Service");

}
