50908
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package com.oracle.mxtool.junit;
|
|
24 |
|
|
25 |
import java.io.PrintStream;
|
|
26 |
|
|
27 |
import org.junit.internal.JUnitSystem;
|
|
28 |
import org.junit.internal.TextListener;
|
|
29 |
import org.junit.runner.Description;
|
|
30 |
import org.junit.runner.Result;
|
|
31 |
import org.junit.runner.notification.Failure;
|
|
32 |
import org.junit.runner.notification.RunListener;
|
|
33 |
|
|
34 |
class TextRunListener implements MxRunListener {
|
|
35 |
|
|
36 |
private final PrintStream fWriter;
|
|
37 |
protected Failure lastFailure;
|
|
38 |
|
|
39 |
TextRunListener(JUnitSystem system) {
|
|
40 |
this(system.out());
|
|
41 |
}
|
|
42 |
|
|
43 |
TextRunListener(PrintStream writer) {
|
|
44 |
fWriter = writer;
|
|
45 |
}
|
|
46 |
|
|
47 |
public boolean beVerbose() {
|
|
48 |
return false;
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
|
52 |
public PrintStream getWriter() {
|
|
53 |
return fWriter;
|
|
54 |
}
|
|
55 |
|
|
56 |
public Failure getLastFailure() {
|
|
57 |
return lastFailure;
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
public void testStarted(Description description) {
|
|
62 |
getWriter().print('.');
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public void testFailed(Failure failure) {
|
|
67 |
getWriter().print('E');
|
|
68 |
lastFailure = failure;
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
|
72 |
public void testIgnored(Description description) {
|
|
73 |
getWriter().print('I');
|
|
74 |
}
|
|
75 |
|
|
76 |
public static RunListener createRunListener(MxRunListener l) {
|
|
77 |
return new TextListener(l.getWriter()) {
|
|
78 |
private Class<?> lastClass;
|
|
79 |
private int passedInLastClass;
|
|
80 |
private int failedInLastClass;
|
|
81 |
private boolean failed;
|
|
82 |
|
|
83 |
@Override
|
|
84 |
public void testStarted(Description description) {
|
|
85 |
Class<?> currentClass = description.getTestClass();
|
|
86 |
if (currentClass != lastClass) {
|
|
87 |
if (lastClass != null) {
|
|
88 |
l.testClassFinished(lastClass, passedInLastClass, failedInLastClass);
|
|
89 |
l.testClassFinishedDelimiter();
|
|
90 |
}
|
|
91 |
lastClass = currentClass;
|
|
92 |
passedInLastClass = 0;
|
|
93 |
failedInLastClass = 0;
|
|
94 |
l.testClassStarted(currentClass);
|
|
95 |
l.testClassStartedDelimiter();
|
|
96 |
}
|
|
97 |
failed = false;
|
|
98 |
l.testStarted(description);
|
|
99 |
l.testStartedDelimiter();
|
|
100 |
}
|
|
101 |
|
|
102 |
@Override
|
|
103 |
public void testFailure(Failure failure) {
|
|
104 |
failed = true;
|
|
105 |
failedInLastClass++;
|
|
106 |
l.testFailed(failure);
|
|
107 |
}
|
|
108 |
|
|
109 |
@Override
|
|
110 |
public void testFinished(Description description) {
|
|
111 |
// we have to do this because there is no callback for successful tests
|
|
112 |
if (!failed) {
|
|
113 |
l.testSucceeded(description);
|
|
114 |
passedInLastClass++;
|
|
115 |
}
|
|
116 |
l.testFinished(description);
|
|
117 |
l.testFinishedDelimiter();
|
|
118 |
}
|
|
119 |
|
|
120 |
@Override
|
|
121 |
public void testIgnored(Description description) {
|
|
122 |
testStarted(description);
|
|
123 |
l.testIgnored(description);
|
|
124 |
l.testFinished(description);
|
|
125 |
l.testFinishedDelimiter();
|
|
126 |
}
|
|
127 |
|
|
128 |
@Override
|
|
129 |
public void testRunStarted(Description description) {
|
|
130 |
l.testRunStarted(description);
|
|
131 |
}
|
|
132 |
|
|
133 |
@Override
|
|
134 |
public void testRunFinished(Result result) {
|
|
135 |
if (lastClass != null) {
|
|
136 |
l.testClassFinished(lastClass, passedInLastClass, failedInLastClass);
|
|
137 |
}
|
|
138 |
l.testRunFinished(result);
|
|
139 |
super.testRunFinished(result);
|
|
140 |
}
|
|
141 |
|
|
142 |
@Override
|
|
143 |
public void testAssumptionFailure(Failure failure) {
|
|
144 |
l.testAssumptionFailure(failure);
|
|
145 |
}
|
|
146 |
};
|
|
147 |
}
|
|
148 |
}
|