1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.junitcore;
20
21 import java.util.Collections;
22 import java.util.Map;
23
24 import org.apache.maven.surefire.api.report.SimpleReportEntry;
25 import org.apache.maven.surefire.api.report.TestOutputReportEntry;
26 import org.apache.maven.surefire.api.report.TestReportListener;
27 import org.apache.maven.surefire.api.report.TestSetReportEntry;
28 import org.apache.maven.surefire.api.util.internal.ClassMethod;
29 import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
30 import org.junit.runner.Description;
31 import org.junit.runner.Result;
32 import org.junit.runner.notification.Failure;
33
34 import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps;
35 import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.toClassMethod;
36
37
38
39
40
41
42
43 @Deprecated
44 class NonConcurrentRunListener extends JUnit4RunListener {
45 private Description currentTestSetDescription;
46
47 private Description lastFinishedDescription;
48
49 NonConcurrentRunListener(TestReportListener<TestOutputReportEntry> reporter) {
50 super(reporter);
51 }
52
53 private TestSetReportEntry createReportEntryForTestSet(Description description, Map<String, String> systemProps) {
54 ClassMethod classMethod = toClassMethod(description);
55 String className = classMethod.getClazz();
56 String methodName = classMethod.getMethod();
57 long testRunId = classMethodIndexer.indexClassMethod(className, methodName);
58 return new SimpleReportEntry(getRunMode(), testRunId, className, null, null, null, systemProps);
59 }
60
61 private TestSetReportEntry createTestSetReportEntryStarted(Description description) {
62 return createReportEntryForTestSet(description, Collections.<String, String>emptyMap());
63 }
64
65 private TestSetReportEntry createTestSetReportEntryFinished(Description description) {
66 return createReportEntryForTestSet(description, systemProps());
67 }
68
69 @Override
70 public void testStarted(Description description) throws Exception {
71 finishLastTestSetIfNecessary(description);
72 super.testStarted(description);
73 }
74
75 private void finishLastTestSetIfNecessary(Description description) {
76 if (describesNewTestSet(description)) {
77 currentTestSetDescription = description;
78 if (lastFinishedDescription != null) {
79 reporter.testSetCompleted(createTestSetReportEntryFinished(lastFinishedDescription));
80 lastFinishedDescription = null;
81 }
82 reporter.testSetStarting(createTestSetReportEntryStarted(description));
83 }
84 }
85
86 private boolean describesNewTestSet(Description description) {
87 if (currentTestSetDescription != null) {
88 if (null != description.getTestClass()) {
89 return !description.getTestClass().equals(currentTestSetDescription.getTestClass());
90 } else if (description.isSuite()) {
91 return description.getChildren().equals(currentTestSetDescription.getChildren());
92 }
93
94 return false;
95 }
96
97 return true;
98 }
99
100 @Override
101 public void testFinished(Description description) throws Exception {
102 super.testFinished(description);
103 lastFinishedDescription = description;
104 }
105
106 @Override
107 public void testIgnored(Description description) throws Exception {
108 finishLastTestSetIfNecessary(description);
109
110 super.testIgnored(description);
111 lastFinishedDescription = description;
112 }
113
114 @Override
115 public void testFailure(Failure failure) throws Exception {
116 finishLastTestSetIfNecessary(failure.getDescription());
117
118 super.testFailure(failure);
119 lastFinishedDescription = failure.getDescription();
120 }
121
122 @Override
123 public void testAssumptionFailure(Failure failure) {
124 finishLastTestSetIfNecessary(failure.getDescription());
125
126 super.testAssumptionFailure(failure);
127 lastFinishedDescription = failure.getDescription();
128 }
129
130 @Override
131 public void testRunStarted(Description description) throws Exception {}
132
133 @Override
134 public void testRunFinished(Result result) throws Exception {
135 if (lastFinishedDescription != null) {
136 reporter.testSetCompleted(createTestSetReportEntryFinished(lastFinishedDescription));
137 lastFinishedDescription = null;
138 }
139 }
140 }