Паттерн: Декоратор (Decorator)
Исходник: junit.extensions.RepeatedTest.java, язык: java [code #461, hits: 9222]
автор: this [добавлен: 18.08.2007]
  1. package junit.extensions;
  2.  
  3. import junit.framework.Test;
  4. import junit.framework.TestResult;
  5.  
  6. /**
  7. * A Decorator that runs a test repeatedly.
  8. *
  9. */
  10. public class RepeatedTest extends TestDecorator {
  11. private int fTimesRepeat;
  12.  
  13. public RepeatedTest(Test test, int repeat) {
  14. super(test);
  15. if (repeat < 0)
  16. throw new IllegalArgumentException("Repetition count must be > 0");
  17. fTimesRepeat= repeat;
  18. }
  19.  
  20. public int countTestCases() {
  21. return super.countTestCases() * fTimesRepeat;
  22. }
  23.  
  24. public void run(TestResult result) {
  25. for (int i= 0; i < fTimesRepeat; i++) {
  26. if (result.shouldStop())
  27. break;
  28. super.run(result);
  29. }
  30. }
  31.  
  32. public String toString() {
  33. return super.toString() + "(repeated)";
  34. }
  35. }
Сущность ConcreteDecorator

Декоратор добавляющий возможность многократного повторного выполнения теста.
Тестировалось на: java 1.5.0_04

+добавить реализацию