Skip to content

Commit

Permalink
fixup! fix fail test run with enabled junit.testFilter option
Browse files Browse the repository at this point in the history
Review: I think this is a safer way to do it. In the end, the error says "can't remove the root of a hierarchy", so it makes sense to exactly guard against this, and also it then only uses the general JUnit Platform API and doesn't rely on ArchUnit specifics (and `AbstractArchUnitTestDescriptor` is more an implementation detail, it's more by accident that the rule descriptors, etc., inherit from this, but the engine descriptor doesn't).
  • Loading branch information
codecholeric committed Nov 10, 2024
1 parent 7e3c820 commit d42985a
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ void filter(TestDescriptor descriptor) {

String testFilterProperty = configuration.getProperty(JUNIT_TEST_FILTER_PROPERTY_NAME);
List<String> memberNames = Splitter.on(",").splitToList(testFilterProperty);
Predicate<TestDescriptor> shouldRunPredicate =
testDescriptor -> !(testDescriptor instanceof AbstractArchUnitTestDescriptor) || memberNameMatches(testDescriptor, memberNames);
Predicate<TestDescriptor> shouldRunPredicate = testDescriptor -> memberNameMatches(testDescriptor, memberNames);
removeNonMatching(descriptor, shouldRunPredicate);
}

private void removeNonMatching(TestDescriptor descriptor, Predicate<TestDescriptor> shouldRunPredicate) {
ImmutableSet.copyOf(descriptor.getChildren())
.forEach(child -> removeNonMatching(child, shouldRunPredicate));

if (descriptor.getChildren().isEmpty() && !shouldRunPredicate.test(descriptor)) {
if (!descriptor.isRoot() && descriptor.getChildren().isEmpty() && !shouldRunPredicate.test(descriptor)) {
descriptor.removeFromHierarchy();
}
}
Expand Down

0 comments on commit d42985a

Please sign in to comment.