SE450: Patterns: Composite Example [9/22] ![]() ![]() ![]() |
Participants and Collaborators
public interface Test {
/**
* Runs a test and collects its result in a TestResult instance.
*/
public abstract void run(TestResult result);
}
public abstract class TestCase extends Assert implements Test {
/**
* Runs the test case and collects the results in TestResult.
*/
public void run(TestResult result) {
result.run(this);
}
}
public class TestSuite implements Test {
/**
* Adds a test to the suite.
*/
public void addTest(Test test) {
fTests.addElement(test);
}
/**
* Runs the tests and collects their result in a TestResult.
*/
public void run(TestResult result) {
for (Enumeration e= tests(); e.hasMoreElements(); ) {
if (result.shouldStop() )
break;
Test test= (Test)e.nextElement();
runTest(test, result);
}
}
}