Skip to content

Commit deb3e7c

Browse files
committed
Avoid reporting discovery warnings for abstract inner classes with tests
While aee7c88 fixed the issue when nested classes were discovered via `NestedClassSelector` or their parent class, passing a `ClassSelector` for them still caused a warning. Fixes #4635. (cherry picked from commit 4305ad8)
1 parent 49e2035 commit deb3e7c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/predicates/TestClassPredicates.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public TestClassPredicates(DiscoveryIssueReporter issueReporter) {
6363
.and(isInner(issueReporter));
6464
this.isValidStandaloneTestClass = isNotPrivateUnlessAbstract("Test", issueReporter) //
6565
.and(isNotLocal(issueReporter)) //
66-
.and(isNotInner(issueReporter)) // or should be annotated with @Nested!
66+
.and(isNotInnerUnlessAbstract(issueReporter)) //
6767
.and(isNotAnonymous(issueReporter));
6868
}
6969

@@ -127,8 +127,8 @@ private static Condition<Class<?>> isInner(DiscoveryIssueReporter issueReporter)
127127
});
128128
}
129129

130-
private static Condition<Class<?>> isNotInner(DiscoveryIssueReporter issueReporter) {
131-
return issueReporter.createReportingCondition(testClass -> !isInnerClass(testClass),
130+
private static Condition<Class<?>> isNotInnerUnlessAbstract(DiscoveryIssueReporter issueReporter) {
131+
return issueReporter.createReportingCondition(testClass -> !isInnerClass(testClass) || isAbstract(testClass),
132132
testClass -> createIssue("Test", testClass, "must not be an inner class unless annotated with @Nested"));
133133
}
134134

jupiter-tests/src/test/java/org/junit/jupiter/engine/NestedTestClassesTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,20 @@ void individualMethodsWithinRecursiveNestedTestClassHierarchiesAreExecuted() {
231231
}
232232

233233
@Test
234-
void doesNotReportDiscoveryIssueForAbstractInnerClass() {
234+
void doesNotReportDiscoveryIssueForClassWithAbstractInnerClass() {
235235
var discoveryIssues = discoverTestsForClass(ConcreteWithExtendedInnerClassTestCase.class).getDiscoveryIssues();
236236

237237
assertThat(discoveryIssues).isEmpty();
238238
}
239239

240+
@Test
241+
void doesNotReportDiscoveryIssueForAbstractInnerClass() {
242+
var discoveryIssues = discoverTestsForClass(
243+
AbstractBaseWithInnerClassTestCase.AbstractInnerClass.class).getDiscoveryIssues();
244+
245+
assertThat(discoveryIssues).isEmpty();
246+
}
247+
240248
private void assertNestedCycle(Class<?> start, Class<?> from, Class<?> to) {
241249
var results = executeTestsForClass(start);
242250
var expectedMessage = String.format(

0 commit comments

Comments
 (0)