private static boolean findAndInvokeNearestMethod()

in core/src/main/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtil.java [147:166]


    private static boolean findAndInvokeNearestMethod(Class<?> targetClass, Predicate<Class<?>> fn) {
        boolean found = false;
        do {
            found = fn.test(targetClass);

            if (!found) {
                // not found? check super classes
                Class<?> superClass = targetClass.getSuperclass();
                if (superClass != null && superClass != Object.class) {
                    // make the superClass the next candidate
                    targetClass = superClass;
                } else {
                    // stop walking up
                    targetClass = null;
                }
            }
        } while (!found && targetClass != null);

        return found;
    }