Skip to content

Commit

Permalink
Fixed issue testng-team#473. Order superclass methods before child ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
enisher committed Apr 25, 2014
1 parent 9bad50d commit 11e787a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/testng/internal/ClassHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.testng.annotations.IAnnotation;
import org.testng.annotations.IFactoryAnnotation;
import org.testng.annotations.IParametersAnnotation;
import org.testng.collections.Lists;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.annotations.Sets;
import org.testng.junit.IJUnitTestRunner;
Expand Down Expand Up @@ -178,13 +179,13 @@ public static ConstructorOrMethod findDeclaredFactoryMethod(Class<?> cls,
* @param clazz
* @return
*/
public static Set<Method> getAvailableMethods(Class<?> clazz) {
Set<Method> methods = Sets.newHashSet();
public static List<Method> getAvailableMethods(Class<?> clazz) {
List<Method> methods = Lists.newArrayList();
methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));

Class<?> parent = clazz.getSuperclass();
while (Object.class != parent) {
methods.addAll(extractMethods(clazz, parent, methods));
methods.addAll(0, extractMethods(clazz, parent, methods));
parent = parent.getSuperclass();
}

Expand Down Expand Up @@ -220,7 +221,7 @@ public static IJUnitTestRunner createTestRunner(TestRunner runner) {
}

private static Set<Method> extractMethods(Class<?> childClass, Class<?> clazz,
Set<Method> collected) {
List<Method> collected) {
Set<Method> methods = Sets.newHashSet();

Method[] declaredMethods = clazz.getDeclaredMethods();
Expand Down Expand Up @@ -249,7 +250,7 @@ private static Set<Method> extractMethods(Class<?> childClass, Class<?> clazz,
return methods;
}

private static boolean isOverridden(Method method, Set<Method> collectedMethods) {
private static boolean isOverridden(Method method, List<Method> collectedMethods) {
Class<?> methodClass = method.getDeclaringClass();
Class<?>[] methodParams = method.getParameterTypes();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/testng/internal/MethodHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ protected static Iterator<Object[]> createArrayIterator(final Object[][] objects
}

protected static String calculateMethodCanonicalName(Class<?> methodClass, String methodName) {
Set<Method> methods = ClassHelper.getAvailableMethods(methodClass); // TESTNG-139
List<Method> methods = ClassHelper.getAvailableMethods(methodClass); // TESTNG-139
Method result = null;
for (Method m : methods) {
if (methodName.equals(m.getName())) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/testng/internal/TestNGMethodFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public ITestNGMethod[] getAfterGroupsConfigurationMethods(Class clazz) {
private ITestNGMethod[] findConfiguration(final Class clazz, final int configurationType) {
List<ITestNGMethod> vResult = Lists.newArrayList();

Set<Method> methods = ClassHelper.getAvailableMethods(clazz);
List<Method> methods = ClassHelper.getAvailableMethods(clazz);

for (Method m : methods) {
IConfigurationAnnotation configuration = AnnotationHelper.findConfiguration(m_annotationFinder, m);
Expand Down

0 comments on commit 11e787a

Please sign in to comment.