50908
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 2016, 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.*;
|
|
26 |
|
|
27 |
import org.junit.internal.*;
|
|
28 |
import org.junit.runner.*;
|
|
29 |
import org.junit.runner.notification.*;
|
|
30 |
|
|
31 |
class VerboseTextListener extends TextRunListener {
|
|
32 |
|
|
33 |
private static final int DEFAULT_MAX_TEST_PER_CLASS = 50;
|
|
34 |
public static final int SHOW_ALL_TESTS = Integer.MAX_VALUE;
|
|
35 |
private final int classesCount;
|
|
36 |
private final int maxTestsPerClass;
|
|
37 |
private int currentClassNum;
|
|
38 |
private int currentTestNum;
|
|
39 |
|
|
40 |
VerboseTextListener(JUnitSystem system, int classesCount) {
|
|
41 |
this(system.out(), classesCount, DEFAULT_MAX_TEST_PER_CLASS);
|
|
42 |
}
|
|
43 |
|
|
44 |
VerboseTextListener(JUnitSystem system, int classesCount, int maxTests) {
|
|
45 |
this(system.out(), classesCount, maxTests);
|
|
46 |
}
|
|
47 |
|
|
48 |
VerboseTextListener(PrintStream writer, int classesCount, int maxTests) {
|
|
49 |
super(writer);
|
|
50 |
maxTestsPerClass = maxTests;
|
|
51 |
this.classesCount = classesCount;
|
|
52 |
}
|
|
53 |
|
|
54 |
@Override
|
|
55 |
public boolean beVerbose() {
|
|
56 |
return currentTestNum < maxTestsPerClass;
|
|
57 |
}
|
|
58 |
|
|
59 |
@Override
|
|
60 |
public void testClassStarted(Class<?> clazz) {
|
|
61 |
++currentClassNum;
|
|
62 |
getWriter().printf("%s started (%d of %d)", clazz.getName(), currentClassNum, classesCount);
|
|
63 |
currentTestNum = 0;
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
|
67 |
public void testClassFinished(Class<?> clazz, int numPassed, int numFailed) {
|
|
68 |
getWriter().print(clazz.getName() + " finished");
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
|
72 |
public void testStarted(Description description) {
|
|
73 |
if (beVerbose()) {
|
|
74 |
getWriter().print(" " + description.getMethodName() + ": ");
|
|
75 |
currentTestNum++;
|
|
76 |
} else {
|
|
77 |
super.testStarted(description);
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
@Override
|
|
82 |
public void testIgnored(Description description) {
|
|
83 |
if (beVerbose()) {
|
|
84 |
getWriter().print("Ignored");
|
|
85 |
} else {
|
|
86 |
super.testIgnored(description);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
@Override
|
|
91 |
public void testSucceeded(Description description) {
|
|
92 |
if (beVerbose()) {
|
|
93 |
getWriter().print("Passed");
|
|
94 |
} else {
|
|
95 |
super.testSucceeded(description);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
@Override
|
|
100 |
public void testAssumptionFailure(Failure failure) {
|
|
101 |
if (beVerbose()) {
|
|
102 |
getWriter().printf("(%s) ", failure.getMessage());
|
|
103 |
} else {
|
|
104 |
super.testAssumptionFailure(failure);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
@Override
|
|
109 |
public void testFailed(Failure failure) {
|
|
110 |
getWriter().print("FAILED");
|
|
111 |
lastFailure = failure;
|
|
112 |
}
|
|
113 |
|
|
114 |
@Override
|
|
115 |
public void testClassFinishedDelimiter() {
|
|
116 |
getWriter().println();
|
|
117 |
}
|
|
118 |
|
|
119 |
@Override
|
|
120 |
public void testClassStartedDelimiter() {
|
|
121 |
getWriter().println();
|
|
122 |
}
|
|
123 |
|
|
124 |
@Override
|
|
125 |
public void testFinishedDelimiter() {
|
|
126 |
if (beVerbose()) {
|
|
127 |
getWriter().println();
|
|
128 |
} else {
|
|
129 |
super.testFinishedDelimiter();
|
|
130 |
}
|
|
131 |
}
|
|
132 |
}
|