in core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java [313:352]
private static Method getMethodWithAnyCombinationArgs(Class clazz, String methodName, Class<?>[] types) {
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if (StringUtils.equals(method.getName(), methodName) && method.getParameterTypes().length > 1) {
boolean foundMismatch = false;
for (Class<?> parameterType : method.getParameterTypes()) {
boolean foundAnyMatch = false;
for (int i=0; i<types.length; i++) {
if (types[i] == Annotation.class) {
if (parameterType.isAnnotation()) {
foundAnyMatch = true;
break;
}
}
else if (types[i] == ComponentContext.class || types[i] == BundleContext.class
|| types[i] == ServiceReference.class || types[i] == ComponentServiceObjects.class
|| types[i] == Map.class || types[i] == int.class || types[i] == Integer.class) {
if (parameterType == types[i]) {
foundAnyMatch = true;
break;
}
}
else if (parameterType.isAssignableFrom(types[i])) {
foundAnyMatch = true;
break;
}
}
if (!foundAnyMatch) {
foundMismatch = true;
break;
}
}
if (!foundMismatch) {
return method;
}
}
}
return null;
}