]> git.argeo.org Git - lgpl/argeo-commons.git/blob - src/org/argeo/util/TesterStatus.java
Prepare next development cycle
[lgpl/argeo-commons.git] / src / org / argeo / util / TesterStatus.java
1 package org.argeo.util;
2
3 import java.io.Serializable;
4
5 /** The status of a test. */
6 public class TesterStatus implements Serializable {
7 private static final long serialVersionUID = 6272975746885487000L;
8
9 private Boolean passed = null;
10 private final String uid;
11 private Throwable throwable = null;
12
13 public TesterStatus(String uid) {
14 this.uid = uid;
15 }
16
17 /** For cloning. */
18 public TesterStatus(String uid, Boolean passed, Throwable throwable) {
19 this(uid);
20 this.passed = passed;
21 this.throwable = throwable;
22 }
23
24 public synchronized Boolean isRunning() {
25 return passed == null;
26 }
27
28 public synchronized Boolean isPassed() {
29 assert passed != null;
30 return passed;
31 }
32
33 public synchronized Boolean isFailed() {
34 assert passed != null;
35 return !passed;
36 }
37
38 public synchronized void setPassed() {
39 setStatus(true);
40 }
41
42 public synchronized void setFailed() {
43 setStatus(false);
44 }
45
46 public synchronized void setFailed(Throwable throwable) {
47 setStatus(false);
48 setThrowable(throwable);
49 }
50
51 protected void setStatus(Boolean passed) {
52 if (this.passed != null)
53 throw new IllegalStateException("Passed status of test " + uid + " is already set (to " + passed + ")");
54 this.passed = passed;
55 }
56
57 protected void setThrowable(Throwable throwable) {
58 if (this.throwable != null)
59 throw new IllegalStateException("Throwable of test " + uid + " is already set (to " + passed + ")");
60 this.throwable = throwable;
61 }
62
63 public String getUid() {
64 return uid;
65 }
66
67 public Throwable getThrowable() {
68 return throwable;
69 }
70
71 @Override
72 protected Object clone() throws CloneNotSupportedException {
73 // TODO Auto-generated method stub
74 return super.clone();
75 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (o instanceof TesterStatus) {
80 TesterStatus other = (TesterStatus) o;
81 // we don't check consistency for performance purposes
82 // this equals() is supposed to be used in collections or for transfer
83 return other.uid.equals(uid);
84 }
85 return false;
86 }
87
88 @Override
89 public int hashCode() {
90 return uid.hashCode();
91 }
92
93 @Override
94 public String toString() {
95 return uid + "\t" + (passed ? "passed" : "failed");
96 }
97
98 }