Паттерн: Декоратор (Decorator)
Исходник: junit.extensions.TestDecorator.java, язык: java [code #460, hits: 9222]
автор: this [добавлен: 18.08.2007]
  1. package junit.extensions;
  2.  
  3. import junit.framework.Assert;
  4. import junit.framework.Test;
  5. import junit.framework.TestResult;
  6.  
  7. /**
  8. * A Decorator for Tests. Use TestDecorator as the base class for defining new
  9. * test decorators. Test decorator subclasses can be introduced to add behaviour
  10. * before or after a test is run.
  11. *
  12. */
  13. public class TestDecorator extends Assert implements Test {
  14. protected Test fTest;
  15.  
  16. public TestDecorator(Test test) {
  17. fTest= test;
  18. }
  19.  
  20. /**
  21. * The basic run behaviour.
  22. */
  23. public void basicRun(TestResult result) {
  24. fTest.run(result);
  25. }
  26.  
  27. public int countTestCases() {
  28. return fTest.countTestCases();
  29. }
  30.  
  31. public void run(TestResult result) {
  32. basicRun(result);
  33. }
  34.  
  35. public String toString() {
  36. return fTest.toString();
  37. }
  38.  
  39. public Test getTest() {
  40. return fTest;
  41. }
  42. }
Сущность Decorator

Декоратор вводящий функцию подсчета количества тестируемых случаев.
Тестировалось на: java 1.5.0_04

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