1. package junit.extensions;
  2. import junit.framework.*;
  3. /**
  4. * A Decorator to set up and tear down additional fixture state.
  5. * Subclass TestSetup and insert it into your tests when you want
  6. * to set up additional state once before the tests are run.
  7. */
  8. public class TestSetup extends TestDecorator {
  9. public TestSetup(Test test) {
  10. super(test);
  11. }
  12. public void run(final TestResult result) {
  13. Protectable p= new Protectable() {
  14. public void protect() throws Exception {
  15. setUp();
  16. basicRun(result);
  17. tearDown();
  18. }
  19. };
  20. result.runProtected(this, p);
  21. }
  22. /**
  23. * Sets up the fixture. Override to set up additional fixture
  24. * state.
  25. */
  26. protected void setUp() throws Exception {
  27. }
  28. /**
  29. * Tears down the fixture. Override to tear down the additional
  30. * fixture state.
  31. */
  32. protected void tearDown() throws Exception {
  33. }
  34. }