-
I have normal Maven project with the usual separation between production code below A new rule I have written is always only called with the classes from the production directory: public class EachClassMustHaveACorrespondingTestClass extends ArchCondition<JavaClass> {
public EachClassMustHaveACorrespondingTestClass(String description, Object... args) {
super(description, args);
}
@Override
public void init(Collection<JavaClass> allObjectsToTest) {
allObjectsToTest.forEach((javaClass) -> System.out.println(javaClass.getFullName()));
}
@Override
public void check(JavaClass item, ConditionEvents events) {}
} Any idea why? A custom test, normal method in a JUnit test class, where I use my own importer, is able to find production and test classes: public class EachClassMustHaveCorrespondingTestClass extends ArchCondition<JavaClass> {
private final Set<String> testClassNames;
public static ArchCondition<JavaClass> inPackageOf(Class<?> classInRootPackage) {
Set<String> testClassNames = new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_JARS)
.withImportOption(ImportOption.Predefined.ONLY_INCLUDE_TESTS)
.importPackagesOf(classInRootPackage)
.stream()
.map(JavaClass::getSimpleName)
.collect(Collectors.toSet());
return new EachClassMustHaveCorrespondingTestClass(testClassNames);
}
public EachClassMustHaveCorrespondingTestClass(Set<String> testClassNames) {
super("have corresponding test classes");
this.testClassNames = testClassNames;
}
@Override
public void check(JavaClass item, ConditionEvents events) {
String testClassName = item.getSimpleName() + "Test";
if (!testClassNames.contains(testClassName)) {
String message = String.format("No test class found for %s", item.getFullName());
events.add(SimpleConditionEvent.violated(item, message));
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
obfischer
Sep 15, 2024
Replies: 1 comment 1 reply
-
Ok, I think I have to play around with |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
obfischer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, I think I have to play around with
AnalyzeClasses
for that. I will report the result to this discussion.