Skip to content

Commit cd1b3b0

Browse files
committed
Polish contribution
See #3292 See #3279 See #3280
1 parent ebe7a02 commit cd1b3b0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.10.0-M1.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ repository on GitHub.
1515

1616
==== Bug Fixes
1717

18-
* Use a test class's own classloader to search for `@MethodSource` and `MethodBasedCondition` methods.
19-
This allows these features to work correctly inside an OSGi framework.
18+
* ❓
2019

2120
==== Deprecations and Breaking Changes
2221

@@ -75,6 +74,10 @@ repository on GitHub.
7574

7675
==== Bug Fixes
7776

77+
* The extensions supporting `@MethodSource`, `@EnabledIf`, and `@DisabledIf` now load
78+
classes by fully-qualified class name using the `ClassLoader` obtained from the test
79+
class when possible. This allows classes to be resolved with custom `ClassLoader`
80+
arrangements (such as OSGi).
7881
* When converting an argument for a `@ParameterizedTest` method from a fully-qualified
7982
class name (`String`) to a `Class`, the `ClassLoader` of the class in which the
8083
`@ParameterizedTest` method is declared is now used to resolve the `Class` instead of

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/MethodBasedCondition.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.extension.ExecutionCondition;
2626
import org.junit.jupiter.api.extension.ExtensionContext;
2727
import org.junit.platform.commons.JUnitException;
28+
import org.junit.platform.commons.util.ClassLoaderUtils;
2829
import org.junit.platform.commons.util.Preconditions;
2930
import org.junit.platform.commons.util.ReflectionUtils;
3031
import org.junit.platform.commons.util.StringUtils;
@@ -57,14 +58,18 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
5758
}
5859

5960
private Method getConditionMethod(String fullyQualifiedMethodName, ExtensionContext context) {
60-
final Class<?> testClass = context.getRequiredTestClass();
61+
Class<?> testClass = context.getRequiredTestClass();
6162
if (!fullyQualifiedMethodName.contains("#")) {
6263
return findMethod(testClass, fullyQualifiedMethodName);
6364
}
6465
String[] methodParts = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName);
6566
String className = methodParts[0];
6667
String methodName = methodParts[1];
67-
Class<?> clazz = ReflectionUtils.tryToLoadClass(className, testClass.getClassLoader()).getOrThrow(
68+
ClassLoader classLoader = testClass.getClassLoader();
69+
if (classLoader == null) {
70+
classLoader = ClassLoaderUtils.getDefaultClassLoader();
71+
}
72+
Class<?> clazz = ReflectionUtils.tryToLoadClass(className, classLoader).getOrThrow(
6873
cause -> new JUnitException(format("Could not load class [%s]", className), cause));
6974
return findMethod(clazz, methodName);
7075
}

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/MethodArgumentsProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.junit.jupiter.api.extension.ExtensionContext;
2929
import org.junit.platform.commons.JUnitException;
3030
import org.junit.platform.commons.PreconditionViolationException;
31+
import org.junit.platform.commons.util.ClassLoaderUtils;
3132
import org.junit.platform.commons.util.CollectionUtils;
3233
import org.junit.platform.commons.util.Preconditions;
3334
import org.junit.platform.commons.util.ReflectionUtils;
@@ -109,7 +110,11 @@ private static Method findFactoryMethodByFullyQualifiedName(Class<?> testClass,
109110
String className = methodParts[0];
110111
String methodName = methodParts[1];
111112
String methodParameters = methodParts[2];
112-
Class<?> clazz = loadRequiredClass(className, testClass.getClassLoader());
113+
ClassLoader classLoader = testClass.getClassLoader();
114+
if (classLoader == null) {
115+
classLoader = ClassLoaderUtils.getDefaultClassLoader();
116+
}
117+
Class<?> clazz = loadRequiredClass(className, classLoader);
113118

114119
// Attempt to find an exact match first.
115120
Method factoryMethod = ReflectionUtils.findMethod(clazz, methodName, methodParameters).orElse(null);

0 commit comments

Comments
 (0)