Skip to content

Commit

Permalink
Rule springBootApplicationShouldBeIn should not check for meta annota…
Browse files Browse the repository at this point in the history
…tion

Closes gh-8
  • Loading branch information
mnhock committed Jun 6, 2024
1 parent aa87afc commit 5c12de2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/enofex/taikai/spring/BootConfigurer.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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));
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/enofex/taikai/spring/SpringPredicates.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static DescribedPredicate<CanBeAnnotated> metaAnnotatedWithRepository() {
"annotated with %s".formatted(ANNOTATION_REPOSITORY));
}

static DescribedPredicate<CanBeAnnotated> metaAnnotatedWithSpringBootApplication() {
return metaAnnotatedWith(ANNOTATION_SPRING_BOOT_APPLICATION,
static DescribedPredicate<CanBeAnnotated> annotatedWithSpringBootApplication() {
return annotatedWith(ANNOTATION_SPRING_BOOT_APPLICATION,
"annotated with %s".formatted(ANNOTATION_SPRING_BOOT_APPLICATION));
}

Expand All @@ -61,6 +61,16 @@ static DescribedPredicate<CanBeAnnotated> metaAnnotatedAutowired() {
"annotated with %s".formatted(ANNOTATION_AUTOWIRED));
}

private static DescribedPredicate<CanBeAnnotated> annotatedWith(String annotation,
String description) {
return new DescribedPredicate<>(description) {
@Override
public boolean test(CanBeAnnotated canBeAnnotated) {
return canBeAnnotated.isMetaAnnotatedWith(annotation);
}
};
}

private static DescribedPredicate<CanBeAnnotated> metaAnnotatedWith(String annotation,
String description) {
return new DescribedPredicate<>(description) {
Expand Down

0 comments on commit 5c12de2

Please sign in to comment.