package architecturetests;

import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.EvaluationResult;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
import de.accso.flexinale.shared_kernel.DoNotCheckInArchitectureTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class NoDependenciesToSpringTest {

    @Test
    void test_NoDependenciesToSpringInCore() {
        // arrange
        final String applicationPackage = ArchUnitHelper.PACKAGE_PREFIX + ".application..";
        final String      domainPackage = ArchUnitHelper.PACKAGE_PREFIX + ".domain..";

        ArchRule archRule = ArchRuleDefinition.noClasses()
                .that()
                .resideInAnyPackage(applicationPackage, domainPackage)
                .and()
                .areNotAnnotatedWith(DoNotCheckInArchitectureTests.class)
                .should()
                .beAnnotatedWith(ArchUnitHelper.isSpringAnnotation)
                .orShould()
                .dependOnClassesThat(ArchUnitHelper.isSpringClass);

        // act
        EvaluationResult evaluationResult = archRule.evaluate(ArchUnitHelper.allJavaClassesToCheck);

        // assert
        assertThat(evaluationResult.getFailureReport().getDetails()).isEmpty();
    }

    @Test
    void test_NoDependenciesToSpringInSharedKernel() {
        // arrange
        final String PACKAGE_SHARED_KERNEL = ArchUnitHelper.PACKAGE_PREFIX + ".shared_kernel..";

        ArchRule archRule = ArchRuleDefinition.noClasses()
                .that()
                .resideInAnyPackage(PACKAGE_SHARED_KERNEL)
                .should()
                .beAnnotatedWith(ArchUnitHelper.isSpringAnnotation)
                .orShould()
                .dependOnClassesThat(ArchUnitHelper.isSpringClass);

        // act
        EvaluationResult evaluationResult = archRule.evaluate(ArchUnitHelper.allJavaClassesToCheck);

        // assert
        assertThat(evaluationResult.getFailureReport().getDetails()).isEmpty();
    }
}
