2929import java .util .Deque ;
3030import java .util .LinkedList ;
3131import java .util .List ;
32-
32+ import java .util .Map ;
33+ import java .util .UUID ;
34+ import java .util .concurrent .ConcurrentHashMap ;
3335
3436/**
3537 * Allure plugin for Cucumber-JVM.
3638 */
39+ @ SuppressWarnings ({
40+ "PMD.ExcessiveImports" ,
41+ "ClassFanOutComplexity" ,
42+ "ClassDataAbstractionCoupling" ,
43+ "unused"
44+ })
3745public class AllureCucumberJvm implements Reporter , Formatter {
3846
3947 private static final List <String > SCENARIO_OUTLINE_KEYWORDS = Collections .synchronizedList (new ArrayList <String >());
@@ -43,12 +51,14 @@ public class AllureCucumberJvm implements Reporter, Formatter {
4351 private static final String SKIPPED = "skipped" ;
4452 private static final String PENDING = "pending" ;
4553
54+ private final Map <Scenario , String > scenarioUuids = new ConcurrentHashMap <>();
4655 private final Deque <Step > gherkinSteps = new LinkedList <>();
4756 private final AllureLifecycle lifecycle ;
4857 private Feature currentFeature ;
4958 private boolean isNullMatch = true ;
5059 private Scenario currentScenario ;
5160
61+
5262 @ SuppressWarnings ("unused" )
5363 public AllureCucumberJvm () {
5464 this (Allure .getLifecycle ());
@@ -91,9 +101,11 @@ public void startOfScenarioLifeCycle(final Scenario scenario) {
91101
92102 final LabelBuilder labelBuilder = new LabelBuilder (currentFeature , scenario , tags );
93103
104+ final String uuid = UUID .randomUUID ().toString ();
105+ scenarioUuids .put (scenario , uuid );
94106
95107 final TestResult result = new TestResult ()
96- .setUuid (scenario . getId () )
108+ .setUuid (uuid )
97109 .setHistoryId (StepUtils .getHistoryId (scenario .getId ()))
98110 .setFullName (String .format ("%s: %s" , currentFeature .getName (), scenario .getName ()))
99111 .setName (scenario .getName ())
@@ -105,7 +117,7 @@ public void startOfScenarioLifeCycle(final Scenario scenario) {
105117 }
106118
107119 lifecycle .scheduleTestCase (result );
108- lifecycle .startTestCase (scenario . getId () );
120+ lifecycle .startTestCase (uuid );
109121
110122 }
111123
@@ -134,13 +146,13 @@ public void match(final Match match) {
134146 stepResult .setName (String .format ("%s %s" , step .getKeyword (), getStepName (step )))
135147 .setStart (System .currentTimeMillis ());
136148
137- lifecycle .startStep (currentScenario .getId (), stepUtils .getStepUuid (step ), stepResult );
149+ final String scenarioUuid = scenarioUuids .get (currentScenario );
150+ lifecycle .startStep (scenarioUuid , stepUtils .getStepUuid (step ), stepResult );
138151 createDataTableAttachment (step .getRows ());
139-
140152 }
141153 }
142154
143-
155+ @ SuppressWarnings ( "PMD.NcssCount" )
144156 @ Override
145157 public void result (final Result result ) {
146158 if (!isNullMatch ) {
@@ -152,19 +164,20 @@ public void result(final Result result) {
152164 .setMuted (tagParser .isMuted ())
153165 .setKnown (tagParser .isKnown ());
154166
167+ final String scenarioUuid = scenarioUuids .get (currentScenario );
155168 switch (result .getStatus ()) {
156169 case FAILED :
157170 final Status status = ResultsUtils .getStatus (result .getError ())
158171 .orElse (Status .FAILED );
159172 lifecycle .updateStep (stepResult -> stepResult .setStatus (Status .FAILED ));
160- lifecycle .updateTestCase (currentScenario . getId () , scenarioResult ->
173+ lifecycle .updateTestCase (scenarioUuid , scenarioResult ->
161174 scenarioResult .setStatus (status )
162175 .setStatusDetails (statusDetails ));
163176 lifecycle .stopStep ();
164177 break ;
165178 case PENDING :
166179 lifecycle .updateStep (stepResult -> stepResult .setStatus (Status .SKIPPED ));
167- lifecycle .updateTestCase (currentScenario . getId () , scenarioResult ->
180+ lifecycle .updateTestCase (scenarioUuid , scenarioResult ->
168181 scenarioResult .setStatus (Status .SKIPPED )
169182 .setStatusDetails (statusDetails ));
170183 lifecycle .stopStep ();
@@ -176,7 +189,7 @@ public void result(final Result result) {
176189 case PASSED :
177190 lifecycle .updateStep (stepResult -> stepResult .setStatus (Status .PASSED ));
178191 lifecycle .stopStep ();
179- lifecycle .updateTestCase (currentScenario . getId () , scenarioResult ->
192+ lifecycle .updateTestCase (scenarioUuid , scenarioResult ->
180193 scenarioResult .setStatus (Status .PASSED )
181194 .setStatusDetails (statusDetails ));
182195 break ;
@@ -195,8 +208,9 @@ public void endOfScenarioLifeCycle(final Scenario scenario) {
195208 stepUtils .fireCanceledStep (gherkinSteps .remove ());
196209 }
197210 }
198- lifecycle .stopTestCase (scenario .getId ());
199- lifecycle .writeTestCase (scenario .getId ());
211+ final String scenarioUuid = scenarioUuids .remove (scenario );
212+ lifecycle .stopTestCase (scenarioUuid );
213+ lifecycle .writeTestCase (scenarioUuid );
200214 }
201215
202216 public String getStepName (final Step step ) {
0 commit comments