2424import io .qameta .allure .model .Parameter ;
2525import io .qameta .allure .model .Status ;
2626import io .qameta .allure .model .StatusDetails ;
27- import io .qameta .allure .model .StepResult ;
2827import io .qameta .allure .model .TestResult ;
2928import io .qameta .allure .model .TestResultContainer ;
3029import io .qameta .allure .testfilter .FileTestPlanSupplier ;
3130import io .qameta .allure .testfilter .TestPlan ;
32- import io .qameta .allure .testfilter .TestPlanUnknown ;
3331import io .qameta .allure .testfilter .TestPlanV1_0 ;
3432import io .qameta .allure .util .AnnotationUtils ;
3533import io .qameta .allure .util .ExceptionUtils ;
3634import io .qameta .allure .util .ResultsUtils ;
3735import org .spockframework .runtime .AbstractRunListener ;
38- import org .spockframework .runtime .IStandardStreamsListener ;
39- import org .spockframework .runtime .StandardStreamsCapturer ;
4036import org .spockframework .runtime .extension .IGlobalExtension ;
4137import org .spockframework .runtime .extension .IMethodInterceptor ;
4238import org .spockframework .runtime .extension .IMethodInvocation ;
8682@ SuppressWarnings ({
8783 "PMD.NcssCount"
8884})
89- public class AllureSpock2 extends AbstractRunListener implements IGlobalExtension , IStandardStreamsListener {
90-
91- private final StandardStreamsCapturer streamsCapturer = new StandardStreamsCapturer ();
85+ public class AllureSpock2 extends AbstractRunListener implements IGlobalExtension {
9286
9387 private final ThreadLocal <String > testResults = new InheritableThreadLocal <String >() {
9488 @ Override
@@ -107,22 +101,14 @@ public AllureSpock2() {
107101 }
108102
109103 public AllureSpock2 (final AllureLifecycle lifecycle ) {
110- this .lifecycle = lifecycle ;
111- this .streamsCapturer .addStandardStreamsListener (this );
112- this .testPlan = new FileTestPlanSupplier ().supply ().orElse (new TestPlanUnknown ());
104+ this (lifecycle , new FileTestPlanSupplier ().supply ().orElse (null ));
113105 }
114106
115107 public AllureSpock2 (final AllureLifecycle lifecycle , final TestPlan plan ) {
116108 this .lifecycle = lifecycle ;
117- this .streamsCapturer .addStandardStreamsListener (this );
118109 this .testPlan = plan ;
119110 }
120111
121- @ Override
122- public void start () {
123- //do nothing at this point
124- }
125-
126112 @ Override
127113 public void visitSpec (final SpecInfo spec ) {
128114 spec .getAllFeatures ().forEach (methodInfo -> methodInfo .setSkipped (this .isSkipped (methodInfo )));
@@ -156,42 +142,6 @@ public void visitSpec(final SpecInfo spec) {
156142 }));
157143 }
158144
159- @ Override
160- public void stop () {
161- //do nothing at this point
162- }
163-
164- @ Override
165- public void standardOut (final String message ) {
166- logMessage (message , Status .PASSED );
167- }
168-
169- @ Override
170- public void standardErr (final String message ) {
171- logMessage (message , Status .BROKEN );
172- }
173-
174- private void logMessage (final String message , final Status status ) {
175- if (Objects .isNull (message )) {
176- return ;
177- }
178-
179- final String trimmed = message .trim ();
180- if (trimmed .isEmpty ()) {
181- return ;
182- }
183-
184- getLifecycle ().getCurrentTestCaseOrStep ().ifPresent (parentUuid -> {
185- final String uuid = UUID .randomUUID ().toString ();
186- getLifecycle ().startStep (
187- parentUuid , uuid ,
188- new StepResult ().setName (trimmed ).setStatus (status )
189- );
190- getLifecycle ().stopStep (uuid );
191- });
192- }
193-
194-
195145 @ Override
196146 public void beforeIteration (final IterationInfo iteration ) {
197147 final String uuid = testResults .get ();
@@ -299,12 +249,19 @@ private String getHistoryId(final String name, final List<Parameter> parameters)
299249 }
300250
301251 private boolean isSkipped (final FeatureInfo featureInfo ) {
252+ if (Objects .isNull (this .testPlan )) {
253+ return false ;
254+ }
302255 if (this .testPlan instanceof TestPlanV1_0 ) {
303256 final TestPlanV1_0 tp = (TestPlanV1_0 ) testPlan ;
304257 return !Objects .isNull (tp .getTests ()) && tp .getTests ()
305258 .stream ()
306259 .filter (Objects ::nonNull )
307- .noneMatch (tc -> this .match (tc , this .getAllureId (featureInfo ), this .getQualifiedName (featureInfo )));
260+ .noneMatch (tc -> this .match (
261+ tc ,
262+ this .getAllureId (featureInfo ),
263+ this .getQualifiedName (featureInfo ))
264+ );
308265 }
309266 return false ;
310267 }
@@ -344,16 +301,6 @@ public void afterIteration(final IterationInfo iteration) {
344301 getLifecycle ().writeTestCase (uuid );
345302 }
346303
347- @ Override
348- public void beforeSpec (final SpecInfo spec ) {
349- streamsCapturer .start ();
350- }
351-
352- @ Override
353- public void afterSpec (final SpecInfo spec ) {
354- streamsCapturer .stop ();
355- }
356-
357304 private List <Parameter > getParameters (final List <String > names , final Object ... values ) {
358305 return IntStream .range (0 , Math .min (names .size (), values .length ))
359306 .mapToObj (index -> createParameter (names .get (index ), values [index ]))
0 commit comments