From 5c12de2f9a19f4ff05182c789690dc89e18eb524 Mon Sep 17 00:00:00 2001 From: mnhock Date: Thu, 6 Jun 2024 21:21:29 +0200 Subject: [PATCH] Rule springBootApplicationShouldBeIn should not check for meta annotation Closes gh-8 --- .../com/enofex/taikai/spring/BootConfigurer.java | 4 ++-- .../com/enofex/taikai/spring/SpringPredicates.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/enofex/taikai/spring/BootConfigurer.java b/src/main/java/com/enofex/taikai/spring/BootConfigurer.java index 8655419..996e82b 100644 --- a/src/main/java/com/enofex/taikai/spring/BootConfigurer.java +++ b/src/main/java/com/enofex/taikai/spring/BootConfigurer.java @@ -1,7 +1,7 @@ package com.enofex.taikai.spring; import static com.enofex.taikai.spring.SpringPredicates.ANNOTATION_SPRING_BOOT_APPLICATION; -import static com.enofex.taikai.spring.SpringPredicates.metaAnnotatedWithSpringBootApplication; +import static com.enofex.taikai.spring.SpringPredicates.annotatedWithSpringBootApplication; import static com.tngtech.archunit.lang.conditions.ArchPredicates.are; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; @@ -25,7 +25,7 @@ public BootConfigurer springBootApplicationShouldBeIn(String location) { public BootConfigurer springBootApplicationShouldBeIn(String location, Configuration configuration) { return addRule(TaikaiRule.of(classes() - .that(are(metaAnnotatedWithSpringBootApplication())) + .that(are(annotatedWithSpringBootApplication())) .should().resideInAPackage(location) .as("Classes annotated with %s should be located in %s".formatted( ANNOTATION_SPRING_BOOT_APPLICATION, location)), configuration)); diff --git a/src/main/java/com/enofex/taikai/spring/SpringPredicates.java b/src/main/java/com/enofex/taikai/spring/SpringPredicates.java index d303e1e..bd5fd06 100644 --- a/src/main/java/com/enofex/taikai/spring/SpringPredicates.java +++ b/src/main/java/com/enofex/taikai/spring/SpringPredicates.java @@ -51,8 +51,8 @@ static DescribedPredicate metaAnnotatedWithRepository() { "annotated with %s".formatted(ANNOTATION_REPOSITORY)); } - static DescribedPredicate metaAnnotatedWithSpringBootApplication() { - return metaAnnotatedWith(ANNOTATION_SPRING_BOOT_APPLICATION, + static DescribedPredicate annotatedWithSpringBootApplication() { + return annotatedWith(ANNOTATION_SPRING_BOOT_APPLICATION, "annotated with %s".formatted(ANNOTATION_SPRING_BOOT_APPLICATION)); } @@ -61,6 +61,16 @@ static DescribedPredicate metaAnnotatedAutowired() { "annotated with %s".formatted(ANNOTATION_AUTOWIRED)); } + private static DescribedPredicate annotatedWith(String annotation, + String description) { + return new DescribedPredicate<>(description) { + @Override + public boolean test(CanBeAnnotated canBeAnnotated) { + return canBeAnnotated.isMetaAnnotatedWith(annotation); + } + }; + } + private static DescribedPredicate metaAnnotatedWith(String annotation, String description) { return new DescribedPredicate<>(description) {