Skip to content

Commit 43c105a

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 (cherry picked from commit c2f49f6)
1 parent 63d464d commit 43c105a

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
@@ -1490,27 +1490,29 @@ public static Stream<Method> streamMethods(Class<?> clazz, Predicate<Method> pre
14901490
Preconditions.notNull(predicate, "Predicate must not be null");
14911491
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
14921492

1493-
return findAllMethodsInHierarchy(clazz, predicate, traversalMode).stream().distinct();
1493+
// @formatter:off
1494+
return findAllMethodsInHierarchy(clazz, traversalMode).stream()
1495+
.filter(predicate)
1496+
.distinct();
1497+
// @formatter:on
14941498
}
14951499

14961500
/**
14971501
* Find all non-synthetic methods in the superclass and interface hierarchy,
1498-
* excluding Object, that match the specified {@code predicate}.
1502+
* excluding Object.
14991503
*/
1500-
private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, Predicate<Method> predicate,
1501-
HierarchyTraversalMode traversalMode) {
1502-
1504+
private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, HierarchyTraversalMode traversalMode) {
15031505
Preconditions.notNull(clazz, "Class must not be null");
15041506
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
15051507

15061508
// @formatter:off
15071509
List<Method> localMethods = getDeclaredMethods(clazz, traversalMode).stream()
1508-
.filter(predicate.and(method -> !method.isSynthetic()))
1510+
.filter(method -> !method.isSynthetic())
15091511
.collect(toList());
1510-
List<Method> superclassMethods = getSuperclassMethods(clazz, predicate, traversalMode).stream()
1512+
List<Method> superclassMethods = getSuperclassMethods(clazz, traversalMode).stream()
15111513
.filter(method -> !isMethodShadowedByLocalMethods(method, localMethods))
15121514
.collect(toList());
1513-
List<Method> interfaceMethods = getInterfaceMethods(clazz, predicate, traversalMode).stream()
1515+
List<Method> interfaceMethods = getInterfaceMethods(clazz, traversalMode).stream()
15141516
.filter(method -> !isMethodShadowedByLocalMethods(method, localMethods))
15151517
.collect(toList());
15161518
// @formatter:on
@@ -1646,18 +1648,16 @@ private static int defaultMethodSorter(Method method1, Method method2) {
16461648
return comparison;
16471649
}
16481650

1649-
private static List<Method> getInterfaceMethods(Class<?> clazz, Predicate<Method> predicate,
1650-
HierarchyTraversalMode traversalMode) {
1651-
1651+
private static List<Method> getInterfaceMethods(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16521652
List<Method> allInterfaceMethods = new ArrayList<>();
16531653
for (Class<?> ifc : clazz.getInterfaces()) {
16541654

16551655
// @formatter:off
16561656
List<Method> localInterfaceMethods = getMethods(ifc).stream()
1657-
.filter(predicate.and(method -> !isAbstract(method)))
1657+
.filter(m -> !isAbstract(m))
16581658
.collect(toList());
16591659

1660-
List<Method> superinterfaceMethods = getInterfaceMethods(ifc, predicate, traversalMode).stream()
1660+
List<Method> superinterfaceMethods = getInterfaceMethods(ifc, traversalMode).stream()
16611661
.filter(method -> !isMethodShadowedByLocalMethods(method, localInterfaceMethods))
16621662
.collect(toList());
16631663
// @formatter:on
@@ -1707,14 +1707,12 @@ private static boolean isFieldShadowedByLocalFields(Field field, List<Field> loc
17071707
return localFields.stream().anyMatch(local -> local.getName().equals(field.getName()));
17081708
}
17091709

1710-
private static List<Method> getSuperclassMethods(Class<?> clazz, Predicate<Method> predicate,
1711-
HierarchyTraversalMode traversalMode) {
1712-
1710+
private static List<Method> getSuperclassMethods(Class<?> clazz, HierarchyTraversalMode traversalMode) {
17131711
Class<?> superclass = clazz.getSuperclass();
17141712
if (!isSearchable(superclass)) {
17151713
return Collections.emptyList();
17161714
}
1717-
return findAllMethodsInHierarchy(superclass, predicate, traversalMode);
1715+
return findAllMethodsInHierarchy(superclass, traversalMode);
17181716
}
17191717

17201718
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
@@ -1352,10 +1352,11 @@ void findMethodsIgnoresBridgeMethods() throws Exception {
13521352
}
13531353

13541354
/**
1355-
* @see https://github.com/junit-team/junit5/issues/3498
1355+
* @see https://github.com/junit-team/junit5/issues/3553
13561356
*/
1357+
@Disabled("Until #3553 is resolved")
13571358
@Test
1358-
void findMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
1359+
void findMethodsDoesNotAllowInstanceMethodToHideStaticMethod() throws Exception {
13591360
final String BEFORE = "before";
13601361
Class<?> superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class;
13611362
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)