X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2Ftest%2FTestStatus.java;fp=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2Ftest%2FTestStatus.java;h=79cfbcdd320c34c72f6e922f67ff82cbc84ead16;hb=050bd6a22e01442bf34962c4f378e3d92bc6eb21;hp=0000000000000000000000000000000000000000;hpb=1bf049da92fa6cb0dde838a952a63866de313898;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/util/test/TestStatus.java b/org.argeo.util/src/org/argeo/util/test/TestStatus.java new file mode 100644 index 000000000..79cfbcdd3 --- /dev/null +++ b/org.argeo.util/src/org/argeo/util/test/TestStatus.java @@ -0,0 +1,98 @@ +package org.argeo.util.test; + +import java.io.Serializable; + +/** The status of a test. */ +public class TestStatus implements Serializable { + private static final long serialVersionUID = 6272975746885487000L; + + private Boolean passed = null; + private final String uid; + private Throwable throwable = null; + + public TestStatus(String uid) { + this.uid = uid; + } + + /** For cloning. */ + public TestStatus(String uid, Boolean passed, Throwable throwable) { + this(uid); + this.passed = passed; + this.throwable = throwable; + } + + public synchronized Boolean isRunning() { + return passed == null; + } + + public synchronized Boolean isPassed() { + assert passed != null; + return passed; + } + + public synchronized Boolean isFailed() { + assert passed != null; + return !passed; + } + + public synchronized void setPassed() { + setStatus(true); + } + + public synchronized void setFailed() { + setStatus(false); + } + + public synchronized void setFailed(Throwable throwable) { + setStatus(false); + setThrowable(throwable); + } + + protected void setStatus(Boolean passed) { + if (this.passed != null) + throw new IllegalStateException("Passed status of test " + uid + " is already set (to " + passed + ")"); + this.passed = passed; + } + + protected void setThrowable(Throwable throwable) { + if (this.throwable != null) + throw new IllegalStateException("Throwable of test " + uid + " is already set (to " + passed + ")"); + this.throwable = throwable; + } + + public String getUid() { + return uid; + } + + public Throwable getThrowable() { + return throwable; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + // TODO Auto-generated method stub + return super.clone(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof TestStatus) { + TestStatus other = (TestStatus) o; + // we don't check consistency for performance purposes + // this equals() is supposed to be used in collections or for transfer + return other.uid.equals(uid); + } + return false; + } + + @Override + public int hashCode() { + return uid.hashCode(); + } + + @Override + public String toString() { + return uid + "\t" + (passed ? "passed" : "failed"); + } + +}