Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule springBootApplicationShouldBeIn should not check for meta annota… #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading