Skip to content

Commit c2f49f6

Browse files
committed
Revert "Apply method predicate before searching type hierarchy"
This commit reverts the functional changes from commit 64ed21a and disables the associated tests for the time being. See #3498 See #3500 See #3553 Closes #3600
1 parent 2f05a7c commit c2f49f6

File tree

6 files changed

+45
-34
lines changed

6 files changed

+45
-34
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc

+22-11
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,40 @@ on GitHub.
2121

2222
==== Deprecations and Breaking Changes
2323

24-
* Field predicates are no longer applied eagerly while searching the type hierarchy. This
25-
reverts changes made in 5.10.1 that affected `findFields(...)` and `streamFields(...)`
26-
in `ReflectionSupport` as well as `findAnnotatedFields(...)` and
27-
`findAnnotatedFieldValues(...)` in `AnnotationSupport`.
28-
- See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and
29-
link:https://github.com/junit-team/junit5/issues/3553[#3553] for details.
24+
* Field predicates are no longer applied eagerly while searching the type hierarchy.
25+
- This reverts changes made in 5.10.1 that affected `findFields(...)` and
26+
`streamFields(...)` in `ReflectionSupport` as well as `findAnnotatedFields(...)` and
27+
`findAnnotatedFieldValues(...)` in `AnnotationSupport`.
28+
- See issue link:https://github.com/junit-team/junit5/issues/3638[#3638] for details.
29+
* Method predicates are no longer applied eagerly while searching the type hierarchy.
30+
- This reverts changes made in 5.10.1 that affected `findMethods(...)` and
31+
`streamMethods(...)` in `ReflectionSupport` as well as `findAnnotatedMethods(...)` in
32+
`AnnotationSupport`.
33+
- See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details.
3034

3135

3236
[[release-notes-5.10.2-junit-jupiter]]
3337
=== JUnit Jupiter
3438

3539
==== Bug Fixes
3640

37-
* ❓
41+
* JUnit Jupiter once again properly detects when a `@Test` method is overridden in a
42+
subclass.
43+
- See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details.
3844

3945
==== Deprecations and Breaking Changes
4046

4147
* A package-private static field annotated with `@TempDir` is once again _shadowed_ by a
4248
non-static field annotated with `@TempDir` when the non-static field resides in a
43-
different package and has the same name as the static field. This reverts changes made
44-
in 5.10.1.
45-
- See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and
46-
link:https://github.com/junit-team/junit5/issues/3553[#3553] for details.
49+
different package and has the same name as the static field.
50+
- This reverts changes made in 5.10.1.
51+
- See issue link:https://github.com/junit-team/junit5/issues/3638[#3638] for details.
52+
* A package-private class-level lifecycle method annotated with `@BeforeAll` or
53+
`@AfterAll` is once again _shadowed_ by a method-level lifecycle method annotated with
54+
`@BeforeEach` or `@AfterEach` when the method-level lifecycle method resides in a
55+
different package and has the same name as the class-level lifecycle method.
56+
- This reverts changes made in 5.10.1.
57+
- See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details.
4758

4859

4960
[[release-notes-5.10.2-junit-vintage]]

junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java

+15-17
Original file line numberDiff line numberDiff line change
@@ -1439,27 +1439,29 @@ public static Stream<Method> streamMethods(Class<?> clazz, Predicate<Method> pre
14391439
Preconditions.notNull(predicate, "Predicate must not be null");
14401440
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
14411441

1442-
return findAllMethodsInHierarchy(clazz, predicate, traversalMode).stream().distinct();
1442+
// @formatter:off
1443+
return findAllMethodsInHierarchy(clazz, traversalMode).stream()
1444+
.filter(predicate)
1445+
.distinct();
1446+
// @formatter:on
14431447
}
14441448

14451449
/**
14461450
* Find all non-synthetic methods in the superclass and interface hierarchy,
1447-
* excluding Object, that match the specified {@code predicate}.
1451+
* excluding Object.
14481452
*/
1449-
private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, Predicate<Method> predicate,
1450-
HierarchyTraversalMode traversalMode) {
1451-
1453+
private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, HierarchyTraversalMode traversalMode) {
14521454
Preconditions.notNull(clazz, "Class must not be null");
14531455
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
14541456

14551457
// @formatter:off
14561458
List<Method> localMethods = getDeclaredMethods(clazz, traversalMode).stream()
1457-
.filter(predicate.and(method -> !method.isSynthetic()))
1459+
.filter(method -> !method.isSynthetic())
14581460
.collect(toList());
1459-
List<Method> superclassMethods = getSuperclassMethods(clazz, predicate, traversalMode).stream()
1461+
List<Method> superclassMethods = getSuperclassMethods(clazz, traversalMode).stream()
14601462
.filter(method -> !isMethodShadowedByLocalMethods(method, localMethods))
14611463
.collect(toList());
1462-
List<Method> interfaceMethods = getInterfaceMethods(clazz, predicate, traversalMode).stream()
1464+
List<Method> interfaceMethods = getInterfaceMethods(clazz, traversalMode).stream()
14631465
.filter(method -> !isMethodShadowedByLocalMethods(method, localMethods))
14641466
.collect(toList());
14651467
// @formatter:on
@@ -1595,18 +1597,16 @@ private static int defaultMethodSorter(Method method1, Method method2) {
15951597
return comparison;
15961598
}
15971599

1598-
private static List<Method> getInterfaceMethods(Class<?> clazz, Predicate<Method> predicate,
1599-
HierarchyTraversalMode traversalMode) {
1600-
1600+
private static List<Method> getInterfaceMethods(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16011601
List<Method> allInterfaceMethods = new ArrayList<>();
16021602
for (Class<?> ifc : clazz.getInterfaces()) {
16031603

16041604
// @formatter:off
16051605
List<Method> localInterfaceMethods = getMethods(ifc).stream()
1606-
.filter(predicate.and(method -> !isAbstract(method)))
1606+
.filter(m -> !isAbstract(m))
16071607
.collect(toList());
16081608

1609-
List<Method> superinterfaceMethods = getInterfaceMethods(ifc, predicate, traversalMode).stream()
1609+
List<Method> superinterfaceMethods = getInterfaceMethods(ifc, traversalMode).stream()
16101610
.filter(method -> !isMethodShadowedByLocalMethods(method, localInterfaceMethods))
16111611
.collect(toList());
16121612
// @formatter:on
@@ -1656,14 +1656,12 @@ private static boolean isFieldShadowedByLocalFields(Field field, List<Field> loc
16561656
return localFields.stream().anyMatch(local -> local.getName().equals(field.getName()));
16571657
}
16581658

1659-
private static List<Method> getSuperclassMethods(Class<?> clazz, Predicate<Method> predicate,
1660-
HierarchyTraversalMode traversalMode) {
1661-
1659+
private static List<Method> getSuperclassMethods(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16621660
Class<?> superclass = clazz.getSuperclass();
16631661
if (!isSearchable(superclass)) {
16641662
return Collections.emptyList();
16651663
}
1666-
return findAllMethodsInHierarchy(superclass, predicate, traversalMode);
1664+
return findAllMethodsInHierarchy(superclass, traversalMode);
16671665
}
16681666

16691667
private static boolean isMethodShadowedByLocalMethods(Method method, List<Method> localMethods) {

platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,11 @@ void findAnnotatedMethodsForAnnotationUsedInClassAndSuperclassHierarchyDown() th
391391
}
392392

393393
/**
394-
* @see https://github.com/junit-team/junit5/issues/3498
394+
* @see https://github.com/junit-team/junit5/issues/3553
395395
*/
396+
@Disabled("Until #3553 is resolved")
396397
@Test
397-
void findAnnotatedMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
398+
void findAnnotatedMethodsDoesNotAllowInstanceMethodToHideStaticMethod() throws Exception {
398399
final String BEFORE = "before";
399400
Class<?> superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class;
400401
Method beforeAllMethod = superclass.getDeclaredMethod(BEFORE);

platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,11 @@ void findMethodsIgnoresBridgeMethods() throws Exception {
13261326
}
13271327

13281328
/**
1329-
* @see https://github.com/junit-team/junit5/issues/3498
1329+
* @see https://github.com/junit-team/junit5/issues/3553
13301330
*/
1331+
@Disabled("Until #3553 is resolved")
13311332
@Test
1332-
void findMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
1333+
void findMethodsDoesNotAllowInstanceMethodToHideStaticMethod() throws Exception {
13331334
final String BEFORE = "before";
13341335
Class<?> superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class;
13351336
Method staticMethod = superclass.getDeclaredMethod(BEFORE);

platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateBeforeMethod.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.junit.jupiter.api.BeforeAll;
1414

1515
/**
16-
* @see https://github.com/junit-team/junit5/issues/3498
16+
* @see https://github.com/junit-team/junit5/issues/3553
1717
*/
1818
public class SuperclassWithStaticPackagePrivateBeforeMethod {
1919

platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateBeforeMethod.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.junit.platform.commons.util.pkg1.SuperclassWithStaticPackagePrivateBeforeMethod;
1515

1616
/**
17-
* @see https://github.com/junit-team/junit5/issues/3498
17+
* @see https://github.com/junit-team/junit5/issues/3553
1818
*/
1919
public class SubclassWithNonStaticPackagePrivateBeforeMethod extends SuperclassWithStaticPackagePrivateBeforeMethod {
2020

0 commit comments

Comments
 (0)