KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > extensions > TestSetupTest


1 package junitx.extensions;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestResult;
6
7 /**
8  * @version $Revision: 1.1 $ $Date: 2002/09/22 23:25:34 $
9  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
10  */

11 public class TestSetupTest
12         extends TestCase {
13
14     public TestSetupTest(String JavaDoc name) {
15         super(name);
16     }
17
18     public void testFailSetUp() {
19         TestCase testcase = new TestCase("testDummy") {
20             public void testDummy() {
21                 System.out.println("h");
22             }
23         };
24
25         MockSetUp wrapper = new MockSetUp(testcase);
26         TestResult result = new TestResult();
27
28         wrapper.run(result);
29         assertTrue(wrapper.tearDownExecuted);
30     }
31
32     public void testFailRun() {
33         TestCase testcase = new TestCase("testDummy") {
34             public void testDummy() {
35                 throw new NullPointerException JavaDoc();
36             }
37         };
38
39         MockSetUp wrapper = new MockSetUp(testcase);
40         TestResult result = new TestResult();
41
42         wrapper.run(result);
43         assertTrue(wrapper.tearDownExecuted);
44     }
45
46     public static class MockSetUp
47             extends TestSetup {
48         public boolean tearDownExecuted = false;
49
50         public MockSetUp(Test test) {
51             super(test);
52         }
53
54         protected void setUp()
55                 throws Exception JavaDoc {
56             throw new NullPointerException JavaDoc();
57         }
58
59         protected void tearDown()
60                 throws Exception JavaDoc {
61             tearDownExecuted = true;
62         }
63     }
64
65 }
66
Popular Tags