KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > pth > AbstractTest


1 /*
2  * Author : Stephen Chong
3  * Created: Nov 21, 2003
4  */

5 package polyglot.pth;
6
7 import java.util.Date JavaDoc;
8
9 /**
10  *
11  */

12 public abstract class AbstractTest implements Test {
13     protected String JavaDoc name;
14     protected String JavaDoc description;
15     protected boolean success = false;
16     protected boolean hasRun = false;
17     protected String JavaDoc failureMessage = null;
18     protected TestResult testResult;
19     
20     protected OutputController output;
21
22     public AbstractTest(String JavaDoc name) {
23         this.name = name;
24     }
25     
26     public void setOutputController(OutputController output) {
27         this.output = output;
28     }
29     
30     public final boolean run() {
31         preRun();
32         this.success = this.runTest();
33         
34         this.hasRun = true;
35         Date JavaDoc lastSuccess = null;
36         if (this.getTestResult() != null) {
37             lastSuccess = this.getTestResult().dateLastSuccess;
38         }
39         this.setTestResult(this.createTestResult(lastSuccess));
40         postRun();
41         return success();
42     }
43     
44     
45     protected abstract boolean runTest();
46     
47     protected void preRun() {
48         output.startTest(this);
49     }
50     protected void postRun() {
51         output.finishTest(this, null);
52     }
53     
54     protected TestResult createTestResult(Date JavaDoc lastSuccess) {
55         Date JavaDoc lastRun = new Date JavaDoc();
56         if (this.success()) {
57             lastSuccess = lastRun;
58         }
59         return new TestResult(this, lastRun, lastSuccess);
60     }
61     
62     public boolean success() {
63         return success;
64     }
65     
66     public String JavaDoc getFailureMessage() {
67         return failureMessage;
68     }
69
70     public void setFailureMessage(String JavaDoc failureMessage) {
71         this.failureMessage= failureMessage;
72     }
73     
74     public String JavaDoc getDescription() {
75         return description;
76     }
77     public String JavaDoc getName() {
78         return name;
79     }
80     public void setDescription(String JavaDoc string) {
81         description = string;
82     }
83     public void setName(String JavaDoc string) {
84         name = string;
85     }
86     public TestResult getTestResult() {
87         return testResult;
88     }
89     public void setTestResult(TestResult tr) {
90         testResult = tr;
91     }
92 }
93
Popular Tags