-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestResult.java
More file actions
62 lines (53 loc) · 1.89 KB
/
TestResult.java
File metadata and controls
62 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package task.Tester;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.PrintStream;
import java.lang.reflect.Method;
/**
* Stores result run some test.
*/
public class TestResult {
public final @NotNull Method method;
public final boolean ok;
public final @NotNull String message;
public final @Nullable Throwable exception;
public final long time;
private TestResult(@NotNull Method method, boolean ok, @NotNull String message, @Nullable Throwable exception, long time) {
this.method = method;
this.ok = ok;
this.message = message;
this.exception = exception;
this.time = time;
}
static TestResult ok(@NotNull Method method, long time) {
return new TestResult(method, true, "ok.", null, time);
}
static TestResult expectedException(@NotNull Method method, @NotNull Class<? extends Throwable> exceptionClass, long time) {
return new TestResult(method, false, "expected " + exceptionClass.getName(), null, time);
}
static TestResult exception(@NotNull Method method, @NotNull Throwable exception, long time) {
return new TestResult(method, false, "exception: ", exception, time);
}
static TestResult ignored(@NotNull Method method, @NotNull String message) {
return new TestResult(method, true, "ignore. \ncause:" + message, null, 0);
}
/**
* Prints report of result to out
*/
public void print(PrintStream out) {
out.println("Testing " + method);
if (ok) {
out.println("Ok");
out.println(message);
} else {
out.println("Fail");
out.println(message);
if (exception != null) {
exception.printStackTrace(out);
}
}
out.println("time: "+ time + "ms");
out.println();
out.println();
}
}