Skip to content

Commit

Permalink
Merge branch 'AllDynamic'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeust committed Aug 8, 2011
2 parents f38bbfa + ad29ae8 commit b251fce
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 475 deletions.
51 changes: 51 additions & 0 deletions src/main/java/org/testng/DependencyMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.testng;

import org.testng.collections.ListMultiMap;
import org.testng.collections.Maps;

import java.util.List;

/**
* Helper class to keep track of dependencies.
*
* @author Cedric Beust <cedric@beust.com>
*/
public class DependencyMap {
private ListMultiMap<String, ITestNGMethod> m_dependencies = Maps.newListMultiMap();
private ListMultiMap<String, ITestNGMethod> m_groups = Maps.newListMultiMap();

public DependencyMap(ITestNGMethod[] methods) {
for (ITestNGMethod m : methods) {
m_dependencies.put(/* m.getTestClass().getName() + "." + */ m.getMethodName(), m);
for (String g : m.getGroups()) {
m_groups.put(g, m);
}
}
}

public List<ITestNGMethod> getMethodsThatBelongTo(String group, ITestNGMethod fromMethod) {
List<ITestNGMethod> result = m_groups.get(group);
if (result == null) {
throw new TestNGException("Method \"" + fromMethod
+ "\" depends on nonexistent group \"" + group + "\"");
} else {
return result;
}
}

public ITestNGMethod getMethodDependingOn(String methodName, ITestNGMethod fromMethod) {
List<ITestNGMethod> l = m_dependencies.get(methodName);
for (ITestNGMethod m : l) {
// If they are in the same class hierarchy, they must belong to the same instance,
// otherwise, it's a method depending on a method in a different class so we
// don't bother checking the instance
if (fromMethod.getRealClass().isAssignableFrom(m.getRealClass())) {
if (m.getInstance() == fromMethod.getInstance()) return m;
} else {
return m;
}
}
throw new TestNGException("Method \"" + fromMethod
+ "\" depends on nonexistent method \"" + methodName + "\"");
}
}

0 comments on commit b251fce

Please sign in to comment.