1 | package org.jtiger.report.failure; |
2 | |
3 | import static org.jtiger.framework.TestResultType.FAILURE; |
4 | import static org.jtiger.framework.TestResultType.FAILURE_SETUP; |
5 | import static org.jtiger.framework.TestResultType.FAILURE_TEARDOWN; |
6 | import org.jtiger.framework.FixtureResultsHandler; |
7 | import org.jtiger.framework.FixtureResults; |
8 | import org.jtiger.framework.ReadOnlyArray; |
9 | import org.jtiger.framework.FixtureResult; |
10 | import org.jtiger.framework.TestResult; |
11 | import org.jtiger.framework.TestResultType; |
12 | |
13 | /** |
14 | * A result handler that outputs to <a href="%j2se.api.spec%/java/lang/System.html#out">the standard output stream</a> |
15 | * information regarding test failures. A test failure is one that has a result type of {@link TestResultType#FAILURE}, |
16 | * {@link TestResultType#FAILURE_SETUP} or {@link TestResultType#FAILURE_TEARDOWN}. |
17 | * <br/> |
18 | * This class was inspired by suggestions from Pierre Legall. |
19 | * |
20 | * @author %javadoc.author.tag% |
21 | * @version %version%<br/> |
22 | * <i>Build Number %build.number%</i><br/> |
23 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
24 | */ |
25 | public final class FailureFixtureResultsHandler implements FixtureResultsHandler |
26 | { |
27 | /** |
28 | * Create a default <tt>FailureFixtureResultsHandler</tt>. |
29 | */ |
30 | public FailureFixtureResultsHandler() |
31 | { |
32 | |
33 | } |
34 | |
35 | /** |
36 | * Outputs test failure information to |
37 | * <a href="%j2se.api.spec%/java/lang/System.html#out">the standard output stream</a>. |
38 | * |
39 | * @param results The test run results to produce the failure output of. |
40 | * @param params This parameter is not used. |
41 | */ |
42 | public void handleResult(final FixtureResults results, final ReadOnlyArray<String> params) |
43 | { |
44 | for(FixtureResult fr : results) |
45 | { |
46 | boolean first = true; |
47 | |
48 | for(TestResult tr : fr) |
49 | { |
50 | final TestResultType trt = tr.getTestResultType(); |
51 | |
52 | if (trt == FAILURE || trt == FAILURE_SETUP || trt == FAILURE_TEARDOWN) |
53 | { |
54 | if(first) |
55 | { |
56 | first = false; |
57 | } |
58 | else |
59 | { |
60 | System.out.println(); |
61 | } |
62 | |
63 | final Throwable t = tr.getException(); |
64 | |
65 | if(t == null) |
66 | { |
67 | System.out.println(t); |
68 | System.out.println(new StringBuilder(" at ") |
69 | .append(tr.getFixtureClass()) |
70 | .append('.') |
71 | .append(tr.getTestMethodName())); |
72 | } |
73 | else |
74 | { |
75 | System.out.println(t); |
76 | |
77 | final StackTraceElement[] stes = t.getStackTrace(); |
78 | |
79 | for (StackTraceElement ste : stes) |
80 | { |
81 | System.out.println(new StringBuilder(" at ").append(ste)); |
82 | } |
83 | } |
84 | } |
85 | } |
86 | } |
87 | } |
88 | } |