/** * Tests if the test is a leaf. */ public boolean isLeaf(Object node) { return isTestSuite(node) == null; } /**
/** * Tests if the node is a TestSuite. */ TestSuite isTestSuite(Object node) { if (node instanceof TestSuite) return (TestSuite)node; if (node instanceof TestDecorator) { Test baseTest= ((TestDecorator)node).getTest(); return isTestSuite(baseTest); } return null; }
/** * Gets the test at the given index */ public Object getChild(Object parent, int index) { TestSuite suite= isTestSuite(parent); if (suite != null) return suite.testAt(index); return null; } /**
/** * Gets the number of tests. */ public int getChildCount(Object parent) { TestSuite suite= isTestSuite(parent); if (suite != null) return suite.testCount(); return 0; } /**
/** * Gets the index of a test in a test suite */ public int getIndexOfChild(Object parent, Object child) { TestSuite suite= isTestSuite(parent); if (suite != null) { int i= 0; for (Enumeration e= suite.tests(); e.hasMoreElements(); i++) { if (child.equals(e.nextElement())) return i; } } return -1; } /**
/** * Finds the path to a test. Returns the index of the test in its * parent test suite. */ public int findTest(Test target, Test node, Vector path) { if (target.equals(node)) return 0; TestSuite suite= isTestSuite(node); for (int i= 0; i < getChildCount(node); i++) { Test t= suite.testAt(i); int index= findTest(target, t, path); if (index >= 0) { path.insertElementAt(node, 0); if (path.size() == 1) return i; return index; } } return -1; } /**