1 package eu.simuline.testhelpers;
2
3 import org.junit.runner.notification.Failure;
4
5 import org.junit.runner.Description;
6 import org.junit.runner.Result;
7
8 import org.junit.AssumptionViolatedException;
9
10
11 /**
12 * Describe class <code>SeqRunListener</code> here.
13 *
14 * @author <a href="mailto:ernst.reissner@simuline.eu">Ernst Reissner</a>
15 * @version 1.0
16 */
17 public final class SeqRunListener extends ExtRunListener {
18
19 /* -------------------------------------------------------------------- *
20 * fields. *
21 * -------------------------------------------------------------------- */
22
23 private final ExtRunListener runListener1;
24 private final ExtRunListener runListener2;
25
26 /* -------------------------------------------------------------------- *
27 * constructor. *
28 * -------------------------------------------------------------------- */
29
30 private SeqRunListener(ExtRunListener runListener1,
31 ExtRunListener runListener2) {
32 this.runListener1 = runListener1;
33 this.runListener2 = runListener2;
34 }
35
36 SeqRunListener(GUIRunner guiRunner) {
37 this(new TextRunListener(), new GUIRunListener(guiRunner));
38 }
39
40
41 /* -------------------------------------------------------------------- *
42 * methods. *
43 * -------------------------------------------------------------------- */
44
45 /**
46 * Called before any tests
47 * of a suite described by <code>desc</code> have been run.
48 * This may be called on an arbitrary thread.
49 *
50 * @param desc
51 * describes the suite of tests to be run.
52 */
53 // api-docs inherited from class RunListener
54 public void testRunStarted(Description desc) throws Exception { //NOPMD
55 this.runListener1.testRunStarted(desc);
56 this.runListener2.testRunStarted(desc);
57 }
58
59 /**
60 * Called when all tests of the suite
61 * announced by {@link #testRunStarted(Description)} have finished.
62 * This may be called on an arbitrary thread.
63 *
64 * @param result
65 * the summary of the outcoming of the suite of tests run,
66 * including all the tests that failed
67 */
68 // api-docs inherited from class RunListener
69 public void testRunFinished(Result result) throws Exception { //NOPMD
70 this.runListener1.testRunFinished(result);
71 this.runListener2.testRunFinished(result);
72 }
73
74 // api-docs inherited from class RunListener
75 /**
76 * Called when a test suite is about to be started.
77 * If this method is called for a given {@link Description},
78 * then {@link #testSuiteFinished(Description)}
79 * will also be called for the same {@code Description}.
80 * <p>
81 * Note that not all runners will call this method, so runners should
82 * be prepared to handle {@link #testStarted(Description)} calls for tests
83 * where there was no corresponding {@link #testSuiteStarted(Description)}
84 * call for the parent {@link Description}.
85 *
86 * @param desc
87 * the description of the test suite that is about to be run
88 * (generally a class name)
89 * @since 4.13
90 */
91 public void testSuiteStarted(Description desc) throws Exception { //NOPMD
92 this.runListener1.testSuiteStarted(desc);
93 this.runListener2.testSuiteStarted(desc);
94 }
95
96 /**
97 * Called when a test suite has finished,
98 * whether the test suite succeeds or fails.
99 * This method will not be called for a given {@link Description}
100 * unless {@link #testSuiteStarted(Description)} was called
101 * for the same {@link Description}.
102 *
103 * @param desc
104 * the description of the test suite that just ran
105 * @since 4.13
106 */
107 public void testSuiteFinished(Description desc) throws Exception { //NOPMD
108 this.runListener1.testSuiteFinished(desc);
109 this.runListener2.testSuiteFinished(desc);
110 }
111
112 /**
113 * Called when an atomic test is about to be started.
114 * An ignored test is never started.
115 *
116 * @param desc
117 * the description of the test that is about to be run
118 * (generally a class and method name)
119 * @see #testIgnored(Description)
120 */
121 // api-docs inherited from class RunListener
122 public void testStarted(Description desc) throws Exception { //NOPMD
123 this.runListener1.testStarted(desc);
124 this.runListener2.testStarted(desc);
125 }
126
127
128 /**
129 * Called when an atomic test has finished,
130 * whether the test succeeds or fails.
131 * This method must be invoked after a test has been started
132 * which was indicated by {@link #testStarted(Description)} before.
133 * An ignored test is never finished.
134 *
135 * @param desc
136 * the description of the test that just ran
137 * @see #testIgnored(Description)
138 */
139 // api-docs inherited from class RunListener
140 public void testFinished(Description desc) throws Exception { //NOPMD
141 this.runListener1.testFinished(desc);
142 this.runListener2.testFinished(desc);
143 }
144
145 /**
146 * Called when an atomic test fails to execute properly
147 * throwing a Throwable, or when a listener throws an exception.
148 * <p>
149 * In the case of a failure of an atomic test,
150 * this method is invoked after {@link #testStarted(Description)}
151 * and before {@link #testFinished(Description)}
152 * with the according description of <code>failure</code>
153 * from the same thread that called {@link #testStarted(Description)}.
154 * In case of a failed assumption, instead of this method
155 * {@link #testAssumptionFailure(Failure)} is invoked
156 * for the according test.
157 * <p>
158 * In the case of a listener throwing an exception,
159 * this method will be called with the description of <code>failure</code>
160 * given by {@link Description#TEST_MECHANISM},
161 * and may be called on an arbitrary thread.
162 *
163 * @param failure
164 * describes the test that failed and the exception that was thrown
165 * or indicates that a listener has thrown an exception
166 * and the according exception.
167 */
168 // api-docs inherited from class RunListener
169 public void testFailure(Failure failure) throws Exception { //NOPMD
170 this.runListener1.testFailure(failure);
171 this.runListener2.testFailure(failure);
172 }
173
174 /**
175 * Called when an atomic test flags
176 * that it assumes a condition that is false.
177 * This is treated as ignored with the description of the failure.
178 * This method is invoked after {@link #testStarted(Description)}
179 * and before {@link #testFinished(Description)}
180 * with the according description of <code>failure</code>.
181 * A failed assertion does not count as a failure
182 * and so {@link #testFailure(Failure)} is not invoked
183 * for the according test.
184 * <p>
185 * CAUTION: Although a failed assertion is like an ignored test,
186 * {@link #testRunFinished(Result)} does not count this as ignored test
187 * but rather than a passed test.
188 *
189 * @param failure
190 * describes the test that failed
191 * and the {@link AssumptionViolatedException} that was thrown.
192 * @see #testIgnored(Description)
193 */
194 public void testAssumptionFailure(Failure failure) {
195 this.runListener1.testAssumptionFailure(failure);
196 this.runListener2.testAssumptionFailure(failure);
197 }
198
199 /**
200 * Called when a test will not be run,
201 * generally because a test method is annotated
202 * with {@link org.junit.Ignore}.
203 * This implies
204 * that neither {@link #testStarted(Description)}
205 * nor {@link #testFinished(Description)} are invoked
206 * for the according test.
207 * This in turn implies that neither {@link #testFailure(Failure)}
208 * nor {@link #testAssumptionFailure(Failure)} are invoked.
209 *
210 * @param desc
211 * describes the test that will not be run
212 */
213 // api-docs inherited from class RunListener
214 public void testIgnored(Description desc) throws Exception { //NOPMD
215 this.runListener1.testIgnored(desc);
216 this.runListener2.testIgnored(desc);
217 }
218
219 // homemade extension
220 /**
221 * Invoked for stop and for break originated by the user.
222 */
223 // not clear which test has been aborted.
224 public void testRunAborted() {
225 this.runListener1.testRunAborted();
226 }
227
228 // homemade extension
229 /**
230 * Invoked if a test class is loaded defining a testsuite
231 * described by <code>desc</code>.
232 */
233 public void testClassStructureLoaded(final Description desc) {
234 this.runListener1.testClassStructureLoaded(desc);
235 this.runListener2.testClassStructureLoaded(desc);
236 }
237
238 }