Паттерн: Декоратор (Decorator)
Исходник: junit.extensions.TestSetup.java, язык: java [code #462, hits: 8615]
автор: this [добавлен: 18.08.2007]
  1. package junit.extensions;
  2.  
  3. import junit.framework.Protectable;
  4. import junit.framework.Test;
  5. import junit.framework.TestResult;
  6.  
  7. /**
  8. * A Decorator to set up and tear down additional fixture state. Subclass
  9. * TestSetup and insert it into your tests when you want to set up additional
  10. * state once before the tests are run.
  11. */
  12. public class TestSetup extends TestDecorator {
  13.  
  14. public TestSetup(Test test) {
  15. super(test);
  16. }
  17.  
  18. public void run(final TestResult result) {
  19. Protectable p= new Protectable() {
  20. public void protect() throws Exception {
  21. setUp();
  22. basicRun(result);
  23. tearDown();
  24. }
  25. };
  26. result.runProtected(this, p);
  27. }
  28.  
  29. /**
  30. * Sets up the fixture. Override to set up additional fixture state.
  31. */
  32. protected void setUp() throws Exception {
  33. }
  34.  
  35. /**
  36. * Tears down the fixture. Override to tear down the additional fixture
  37. * state.
  38. */
  39. protected void tearDown() throws Exception {
  40. }
  41. }
Сущность ConcreteDecorator

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

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