/** * @return An array of all locally declared methods or equivalent thereof * (such as default methods on Java 8 based interfaces that the given class * implements). */ public static Method[] getLocalMethods(Class<?> clazz) { Method[] result; Method[] declaredMethods = excludingMain(clazz); List<Method> defaultMethods = getDefaultMethods(clazz); if (defaultMethods != null) { result = new Method[declaredMethods.length + defaultMethods.size()]; System.arraycopy(declaredMethods, 0, result, 0, declaredMethods.length); int index = declaredMethods.length; for (Method defaultMethod : defaultMethods) { result[index] = defaultMethod; index++; } } else { List<Method> prunedMethods = Lists.newArrayList(); for (Method declaredMethod : declaredMethods) { if (!declaredMethod.isBridge()) { prunedMethods.add(declaredMethod); } } result = prunedMethods.toArray(new Method[prunedMethods.size()]); } return result; }
/** * @return An array of all locally declared methods or equivalent thereof (such as default methods * on Java 8 based interfaces that the given class implements). */ public static Method[] getLocalMethods(Class<?> clazz) { Method[] declaredMethods = excludingMain(clazz); List<Method> defaultMethods = getDefaultMethods(clazz); if (defaultMethods == null) { List<Method> prunedMethods = Lists.newArrayList(); for (Method declaredMethod : declaredMethods) { if (!declaredMethod.isBridge()) { prunedMethods.add(declaredMethod); } } return prunedMethods.toArray(new Method[0]); } Method[] result = new Method[declaredMethods.length + defaultMethods.size()]; System.arraycopy(declaredMethods, 0, result, 0, declaredMethods.length); int index = declaredMethods.length; for (Method defaultMethod : defaultMethods) { result[index] = defaultMethod; index++; } return result; }
private ITestNGMethod[] privateFindTestMethods(INameFilter filter, Class cls) { List<ITestNGMethod> vResult = Lists.newArrayList(); // We do not want to walk up the class hierarchy and accept the // same method twice (e.g. setUp) which would lead to double-invocation. // All relevant JUnit methods are parameter-less so we store accepted // method names in a Set to filter out duplicates. Set<String> acceptedMethodNames = new HashSet<>(); // // Collect all methods that start with test // Class current = cls; while(!(current == Object.class)) { Method[] allMethods = ReflectionHelper.excludingMain(current); for(Method allMethod : allMethods) { ITestNGMethod m = new TestNGMethod(/* allMethods[i].getDeclaringClass(), */ allMethod, m_annotationFinder, null, null); /* @@@ */ ConstructorOrMethod method = m.getConstructorOrMethod(); String methodName = method.getName(); if(filter.accept(method) && !acceptedMethodNames.contains(methodName)) { // if (m.getName().startsWith("test")) { // ppp("Found JUnit test method: " + tm); vResult.add(m); acceptedMethodNames.add(methodName); } } current = current.getSuperclass(); } return vResult.toArray(new ITestNGMethod[vResult.size()]); }
Method[] allMethods = ReflectionHelper.excludingMain(current); for (Method allMethod : allMethods) { ITestNGMethod m =