1. package junit.extensions;
  2. import junit.framework.*;
  3. /**
  4. * A TestSuite for active Tests. It runs each
  5. * test in a separate thread and waits until all
  6. * threads have terminated.
  7. * -- Aarhus Radisson Scandinavian Center 11th floor
  8. */
  9. public class ActiveTestSuite extends TestSuite {
  10. private volatile int fActiveTestDeathCount;
  11. public ActiveTestSuite() {
  12. }
  13. public ActiveTestSuite(Class theClass) {
  14. super(theClass);
  15. }
  16. public ActiveTestSuite(String name) {
  17. super (name);
  18. }
  19. public ActiveTestSuite(Class theClass, String name) {
  20. super(theClass, name);
  21. }
  22. public void run(TestResult result) {
  23. fActiveTestDeathCount= 0;
  24. super.run(result);
  25. waitUntilFinished();
  26. }
  27. public void runTest(final Test test, final TestResult result) {
  28. Thread t= new Thread() {
  29. public void run() {
  30. try {
  31. // inlined due to limitation in VA/Java
  32. //ActiveTestSuite.super.runTest(test, result);
  33. test.run(result);
  34. } finally {
  35. ActiveTestSuite.this.runFinished(test);
  36. }
  37. }
  38. };
  39. t.start();
  40. }
  41. synchronized void waitUntilFinished() {
  42. while (fActiveTestDeathCount < testCount()) {
  43. try {
  44. wait();
  45. } catch (InterruptedException e) {
  46. return; // ignore
  47. }
  48. }
  49. }
  50. synchronized public void runFinished(Test test) {
  51. fActiveTestDeathCount++;
  52. notifyAll();
  53. }
  54. }