1package junit.extensions;
2
3import junit.framework.Protectable;
4import junit.framework.Test;
5import 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 */
12public class TestSetup extends TestDecorator {
13
14	public TestSetup(Test test) {
15		super(test);
16	}
17
18	@Override
19	public void run(final TestResult result) {
20		Protectable p= new Protectable() {
21			public void protect() throws Exception {
22				setUp();
23				basicRun(result);
24				tearDown();
25			}
26		};
27		result.runProtected(this, p);
28	}
29
30	/**
31	 * Sets up the fixture. Override to set up additional fixture state.
32	 */
33	protected void setUp() throws Exception {
34	}
35
36	/**
37	 * Tears down the fixture. Override to tear down the additional fixture
38	 * state.
39	 */
40	protected void tearDown() throws Exception {
41	}
42}