1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.report;
20
21 import java.util.List;
22
23 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
24 import org.apache.maven.plugin.surefire.log.api.Level;
25 import org.apache.maven.surefire.api.report.TestSetReportEntry;
26 import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
27 import org.apache.maven.surefire.shared.utils.logging.MessageBuilder;
28
29 import static org.apache.maven.plugin.surefire.log.api.Level.resolveLevel;
30 import static org.apache.maven.plugin.surefire.report.TestSetStats.concatenateWithTestGroup;
31 import static org.apache.maven.surefire.shared.utils.logging.MessageUtils.buffer;
32
33
34
35
36
37
38
39 public class ConsoleReporter extends StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> {
40 public static final String BRIEF = "brief";
41 public static final String PLAIN = "plain";
42 private static final String TEST_SET_STARTING_PREFIX = "Running ";
43
44 private final boolean usePhrasedClassNameInRunning;
45 private final boolean usePhrasedClassNameInTestCaseSummary;
46
47 public ConsoleReporter(
48 ConsoleLogger logger, boolean usePhrasedClassNameInRunning, boolean usePhrasedClassNameInTestCaseSummary) {
49 super(logger);
50 this.usePhrasedClassNameInRunning = usePhrasedClassNameInRunning;
51 this.usePhrasedClassNameInTestCaseSummary = usePhrasedClassNameInTestCaseSummary;
52 }
53
54 @Override
55 public void testSetStarting(TestSetReportEntry report) {
56 MessageBuilder builder = buffer().a(TEST_SET_STARTING_PREFIX);
57 String runningTestCase = concatenateWithTestGroup(builder, report, usePhrasedClassNameInRunning);
58 getConsoleLogger().info(runningTestCase);
59 }
60
61 @Override
62 public void testSetCompleted(WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults) {
63 boolean success = testSetStats.getCompletedCount() > 0;
64 boolean failures = testSetStats.getFailures() > 0;
65 boolean errors = testSetStats.getErrors() > 0;
66 boolean skipped = testSetStats.getSkipped() > 0;
67 boolean flakes = testSetStats.getSkipped() > 0;
68 Level level = resolveLevel(success, failures, errors, skipped, flakes);
69
70 println(testSetStats.getColoredTestSetSummary(report, usePhrasedClassNameInTestCaseSummary), level);
71 for (String testResult : testResults) {
72 println(testResult, level);
73 }
74 }
75
76 @Override
77 public void reset() {}
78
79 private void println(String message, Level level) {
80 switch (level) {
81 case FAILURE:
82 getConsoleLogger().error(message);
83 break;
84 case UNSTABLE:
85 getConsoleLogger().warning(message);
86 break;
87 default:
88 getConsoleLogger().info(message);
89 }
90 }
91 }