Skip to content

Commit 3e36bda

Browse files
committed
Align with releases/5.14.x branch
(cherry picked from commit 07807e5)
1 parent f942f12 commit 3e36bda

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/MethodSegmentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package org.junit.jupiter.engine.discovery;
1212

13+
import static org.junit.platform.commons.util.ReflectionUtils.isDeclaredInSamePackage;
1314
import static org.junit.platform.commons.util.ReflectionUtils.isPackagePrivate;
1415

1516
import java.lang.reflect.Method;
@@ -40,8 +41,7 @@ class MethodSegmentResolver {
4041
*/
4142
String formatMethodSpecPart(Method method, Class<?> testClass) {
4243
var parameterTypes = ClassUtils.nullSafeToString(method.getParameterTypes());
43-
if (isPackagePrivate(method)
44-
&& !method.getDeclaringClass().getPackageName().equals(testClass.getPackageName())) {
44+
if (isPackagePrivate(method) && !isDeclaredInSamePackage(method.getDeclaringClass(), testClass)) {
4545
return "%s#%s(%s)".formatted(method.getDeclaringClass().getName(), method.getName(), parameterTypes);
4646
}
4747
return "%s(%s)".formatted(method.getName(), parameterTypes);

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ private static boolean isMethodOverriddenBy(Method upper, Method lower) {
18411841
}
18421842

18431843
// Cannot override a package-private method in another package.
1844-
if (isPackagePrivate(upper) && !declaredInSamePackage(upper, lower)) {
1844+
if (isPackagePrivate(upper) && !isDeclaredInSamePackage(upper, lower)) {
18451845
return false;
18461846
}
18471847

@@ -1857,8 +1857,16 @@ public static boolean isPackagePrivate(Member member) {
18571857
return !(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers));
18581858
}
18591859

1860-
private static boolean declaredInSamePackage(Method m1, Method m2) {
1861-
return m1.getDeclaringClass().getPackageName().equals(m2.getDeclaringClass().getPackageName());
1860+
private static boolean isDeclaredInSamePackage(Method m1, Method m2) {
1861+
return isDeclaredInSamePackage(m1.getDeclaringClass(), m2.getDeclaringClass());
1862+
}
1863+
1864+
/**
1865+
* @since 6.0.1
1866+
*/
1867+
@API(status = INTERNAL, since = "6.0.1")
1868+
public static boolean isDeclaredInSamePackage(Class<?> c1, Class<?> c2) {
1869+
return c1.getPackageName().equals(c2.getPackageName());
18621870
}
18631871

18641872
/**

0 commit comments

Comments
 (0)