diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc index 183431a5a83d..fca360dd4c7e 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc @@ -21,12 +21,16 @@ on GitHub. ==== Deprecations and Breaking Changes -* Field predicates are no longer applied eagerly while searching the type hierarchy. This - reverts changes made in 5.10.1 that affected `findFields(...)` and `streamFields(...)` - in `ReflectionSupport` as well as `findAnnotatedFields(...)` and - `findAnnotatedFieldValues(...)` in `AnnotationSupport`. - - See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and - link:https://github.com/junit-team/junit5/issues/3553[#3553] for details. +* Field predicates are no longer applied eagerly while searching the type hierarchy. + - This reverts changes made in 5.10.1 that affected `findFields(...)` and + `streamFields(...)` in `ReflectionSupport` as well as `findAnnotatedFields(...)` and + `findAnnotatedFieldValues(...)` in `AnnotationSupport`. + - See issue link:https://github.com/junit-team/junit5/issues/3638[#3638] for details. +* Method predicates are no longer applied eagerly while searching the type hierarchy. + - This reverts changes made in 5.10.1 that affected `findMethods(...)` and + `streamMethods(...)` in `ReflectionSupport` as well as `findAnnotatedMethods(...)` in + `AnnotationSupport`. + - See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details. [[release-notes-5.10.2-junit-jupiter]] @@ -34,16 +38,23 @@ on GitHub. ==== Bug Fixes -* ❓ +* JUnit Jupiter once again properly detects when a `@Test` method is overridden in a + subclass. + - See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details. ==== Deprecations and Breaking Changes * A package-private static field annotated with `@TempDir` is once again _shadowed_ by a non-static field annotated with `@TempDir` when the non-static field resides in a - different package and has the same name as the static field. This reverts changes made - in 5.10.1. - - See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and - link:https://github.com/junit-team/junit5/issues/3553[#3553] for details. + different package and has the same name as the static field. + - This reverts changes made in 5.10.1. + - See issue link:https://github.com/junit-team/junit5/issues/3638[#3638] for details. +* A package-private class-level lifecycle method annotated with `@BeforeAll` or + `@AfterAll` is once again _shadowed_ by a method-level lifecycle method annotated with + `@BeforeEach` or `@AfterEach` when the method-level lifecycle method resides in a + different package and has the same name as the class-level lifecycle method. + - This reverts changes made in 5.10.1. + - See issue link:https://github.com/junit-team/junit5/issues/3600[#3600] for details. [[release-notes-5.10.2-junit-vintage]] diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java index 271cdf8da08a..858a0cc543f7 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java @@ -1439,27 +1439,29 @@ public static Stream streamMethods(Class clazz, Predicate pre Preconditions.notNull(predicate, "Predicate must not be null"); Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null"); - return findAllMethodsInHierarchy(clazz, predicate, traversalMode).stream().distinct(); + // @formatter:off + return findAllMethodsInHierarchy(clazz, traversalMode).stream() + .filter(predicate) + .distinct(); + // @formatter:on } /** * Find all non-synthetic methods in the superclass and interface hierarchy, - * excluding Object, that match the specified {@code predicate}. + * excluding Object. */ - private static List findAllMethodsInHierarchy(Class clazz, Predicate predicate, - HierarchyTraversalMode traversalMode) { - + private static List findAllMethodsInHierarchy(Class clazz, HierarchyTraversalMode traversalMode) { Preconditions.notNull(clazz, "Class must not be null"); Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null"); // @formatter:off List localMethods = getDeclaredMethods(clazz, traversalMode).stream() - .filter(predicate.and(method -> !method.isSynthetic())) + .filter(method -> !method.isSynthetic()) .collect(toList()); - List superclassMethods = getSuperclassMethods(clazz, predicate, traversalMode).stream() + List superclassMethods = getSuperclassMethods(clazz, traversalMode).stream() .filter(method -> !isMethodShadowedByLocalMethods(method, localMethods)) .collect(toList()); - List interfaceMethods = getInterfaceMethods(clazz, predicate, traversalMode).stream() + List interfaceMethods = getInterfaceMethods(clazz, traversalMode).stream() .filter(method -> !isMethodShadowedByLocalMethods(method, localMethods)) .collect(toList()); // @formatter:on @@ -1595,18 +1597,16 @@ private static int defaultMethodSorter(Method method1, Method method2) { return comparison; } - private static List getInterfaceMethods(Class clazz, Predicate predicate, - HierarchyTraversalMode traversalMode) { - + private static List getInterfaceMethods(Class clazz, HierarchyTraversalMode traversalMode) { List allInterfaceMethods = new ArrayList<>(); for (Class ifc : clazz.getInterfaces()) { // @formatter:off List localInterfaceMethods = getMethods(ifc).stream() - .filter(predicate.and(method -> !isAbstract(method))) + .filter(m -> !isAbstract(m)) .collect(toList()); - List superinterfaceMethods = getInterfaceMethods(ifc, predicate, traversalMode).stream() + List superinterfaceMethods = getInterfaceMethods(ifc, traversalMode).stream() .filter(method -> !isMethodShadowedByLocalMethods(method, localInterfaceMethods)) .collect(toList()); // @formatter:on @@ -1656,14 +1656,12 @@ private static boolean isFieldShadowedByLocalFields(Field field, List loc return localFields.stream().anyMatch(local -> local.getName().equals(field.getName())); } - private static List getSuperclassMethods(Class clazz, Predicate predicate, - HierarchyTraversalMode traversalMode) { - + private static List getSuperclassMethods(Class clazz, HierarchyTraversalMode traversalMode) { Class superclass = clazz.getSuperclass(); if (!isSearchable(superclass)) { return Collections.emptyList(); } - return findAllMethodsInHierarchy(superclass, predicate, traversalMode); + return findAllMethodsInHierarchy(superclass, traversalMode); } private static boolean isMethodShadowedByLocalMethods(Method method, List localMethods) { diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java index 07c9936e4ddb..c1f131daf007 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java @@ -391,10 +391,11 @@ void findAnnotatedMethodsForAnnotationUsedInClassAndSuperclassHierarchyDown() th } /** - * @see https://github.com/junit-team/junit5/issues/3498 + * @see https://github.com/junit-team/junit5/issues/3553 */ + @Disabled("Until #3553 is resolved") @Test - void findAnnotatedMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception { + void findAnnotatedMethodsDoesNotAllowInstanceMethodToHideStaticMethod() throws Exception { final String BEFORE = "before"; Class superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class; Method beforeAllMethod = superclass.getDeclaredMethod(BEFORE); diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java index fc6aa4512b7c..bf44c6969887 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java @@ -1326,10 +1326,11 @@ void findMethodsIgnoresBridgeMethods() throws Exception { } /** - * @see https://github.com/junit-team/junit5/issues/3498 + * @see https://github.com/junit-team/junit5/issues/3553 */ + @Disabled("Until #3553 is resolved") @Test - void findMethodsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception { + void findMethodsDoesNotAllowInstanceMethodToHideStaticMethod() throws Exception { final String BEFORE = "before"; Class superclass = SuperclassWithStaticPackagePrivateBeforeMethod.class; Method staticMethod = superclass.getDeclaredMethod(BEFORE); diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateBeforeMethod.java b/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateBeforeMethod.java index ef3cb454b679..493a8a2bbc24 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateBeforeMethod.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateBeforeMethod.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.BeforeAll; /** - * @see https://github.com/junit-team/junit5/issues/3498 + * @see https://github.com/junit-team/junit5/issues/3553 */ public class SuperclassWithStaticPackagePrivateBeforeMethod { diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateBeforeMethod.java b/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateBeforeMethod.java index b4187b07e73d..0cc671a42b28 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateBeforeMethod.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateBeforeMethod.java @@ -14,7 +14,7 @@ import org.junit.platform.commons.util.pkg1.SuperclassWithStaticPackagePrivateBeforeMethod; /** - * @see https://github.com/junit-team/junit5/issues/3498 + * @see https://github.com/junit-team/junit5/issues/3553 */ public class SubclassWithNonStaticPackagePrivateBeforeMethod extends SuperclassWithStaticPackagePrivateBeforeMethod {