Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions biz.aQute.tester.junit-platform/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ Bundle-Description: \
# The dependency on aQute packages is only for the
# launcher side. When launched, those dependencies
# are not necessary
# Note about the unusually restricted version range for org.junit.platform - refer
# GitHub issue #6651. The original import package directive is here and can be restored
# if/when #6651 is fixed:
# org.junit.platform.*;version="${range;[==,+);${junit.platform.tester.version}}",\
Import-Package: \
aQute.*;resolution:=optional,\
junit.*;version="${range;[==,5);${junit3.version}}";resolution:=optional,\
org.apache.felix.service.command;resolution:=optional,\
org.junit.platform.*;version="[${junit.platform.tester.version},1.13)",\
org.junit.platform.*;version="${range;[==,+);${junit.platform.tester.version}}",\
org.junit.*;version="${range;[==,+);${junit4.tester.version}}";resolution:=optional,\
*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,25 @@ private BundleSelectorResolver(BundleContext context, EngineDiscoveryRequest req

methodSelectors = request.getSelectorsByType(MethodSelector.class)
.stream()
.map(selector -> DiscoverySelectors.selectMethod(selector.getClassName(), selector.getMethodName(),
selector.getMethodParameterTypes()))
.map(selector -> {
// With JUnit Platform 1.13+, MethodSelector no longer has getMethodParameterTypes().
// We need to detect the API version without calling getJavaMethod() which would
// throw PreconditionViolationException if the method doesn't exist.
// We test for the deprecated method's existence using reflection on the class.
try {
// Check if the deprecated method exists (JUnit Platform < 1.13)
selector.getClass().getMethod("getMethodParameterTypes");
// Older JUnit Platform version, normalize using deprecated method
@SuppressWarnings("deprecation")
String paramTypes = selector.getMethodParameterTypes();
return DiscoverySelectors.selectMethod(selector.getClassName(), selector.getMethodName(),
paramTypes);
} catch (NoSuchMethodException e) {
// JUnit Platform 1.13+: just return the selector as-is
// Don't call getJavaMethod() here as it would throw if method doesn't exist
return selector;
}
})
.collect(toList());

bundleSelectors = request.getSelectorsByType(BundleSelector.class);
Expand Down Expand Up @@ -436,8 +453,26 @@ private static Optional<Method> findMethod(Class<?> clazz, String method, String
}

private static MethodSelector selectMethod(Class<?> testClass, MethodSelector selector) {
return findMethod(testClass, selector.getMethodName(), selector.getMethodParameterTypes())
.map(method -> DiscoverySelectors.selectMethod(testClass, method))
// Detect JUnit Platform version by checking if deprecated method exists
Optional<Method> method;
try {
// Check if the deprecated method exists (JUnit Platform < 1.13)
selector.getClass().getMethod("getMethodParameterTypes");
// Older JUnit Platform version, use deprecated method
@SuppressWarnings("deprecation")
String paramTypes = selector.getMethodParameterTypes();
method = findMethod(testClass, selector.getMethodName(), paramTypes);
} catch (NoSuchMethodException e) {
// JUnit Platform 1.13+: try to get the resolved method
// This may throw PreconditionViolationException if method doesn't exist
try {
method = Optional.ofNullable(selector.getJavaMethod());
} catch (Exception ex) {
// Method doesn't exist or can't be resolved
method = Optional.empty();
}
}
return method.map(m -> DiscoverySelectors.selectMethod(testClass, m))
.orElse(null);
}

Expand Down