1 5 package polyglot.pth; 6 7 import java.util.Date ; 8 9 12 public abstract class AbstractTest implements Test { 13 protected String name; 14 protected String description; 15 protected boolean success = false; 16 protected boolean hasRun = false; 17 protected String failureMessage = null; 18 protected TestResult testResult; 19 20 protected OutputController output; 21 22 public AbstractTest(String 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 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 lastSuccess) { 55 Date lastRun = new Date (); 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 getFailureMessage() { 67 return failureMessage; 68 } 69 70 public void setFailureMessage(String failureMessage) { 71 this.failureMessage= failureMessage; 72 } 73 74 public String getDescription() { 75 return description; 76 } 77 public String getName() { 78 return name; 79 } 80 public void setDescription(String string) { 81 description = string; 82 } 83 public void setName(String 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 |