1
1
package cucumber .runtime .junit ;
2
2
3
- import cucumber .runtime . Runtime ;
4
- import cucumber . runtime . model . CucumberScenario ;
5
- import gherkin .formatter . model . Step ;
3
+ import cucumber .runner . Runner ;
4
+ import gherkin . pickles . Pickle ;
5
+ import gherkin .pickles . PickleStep ;
6
6
import org .junit .runner .Description ;
7
7
import org .junit .runner .notification .RunNotifier ;
8
8
import org .junit .runners .ParentRunner ;
9
9
import org .junit .runners .model .InitializationError ;
10
10
11
- import java .util . ArrayList ;
11
+ import java .io . Serializable ;
12
12
import java .util .HashMap ;
13
13
import java .util .List ;
14
14
import java .util .Map ;
15
15
16
16
/**
17
17
* Runs a scenario, or a "synthetic" scenario derived from an Examples row.
18
18
*/
19
- public class ExecutionUnitRunner extends ParentRunner <Step > {
20
- private final Runtime runtime ;
21
- private final CucumberScenario cucumberScenario ;
19
+ public class ExecutionUnitRunner extends ParentRunner <PickleStep > {
20
+ private final Runner runner ;
21
+ private final Pickle pickle ;
22
+ private final String language ;
22
23
private final JUnitReporter jUnitReporter ;
24
+ private final Map <PickleStep , Description > stepDescriptions = new HashMap <PickleStep , Description >();
23
25
private Description description ;
24
- private final Map <Step , Description > stepDescriptions = new HashMap <Step , Description >();
25
- private final List <Step > runnerSteps = new ArrayList <Step >();
26
26
27
- public ExecutionUnitRunner (Runtime runtime , CucumberScenario cucumberScenario , JUnitReporter jUnitReporter ) throws InitializationError {
27
+ public ExecutionUnitRunner (Runner runner , Pickle pickle , String language , JUnitReporter jUnitReporter ) throws InitializationError {
28
28
super (ExecutionUnitRunner .class );
29
- this .runtime = runtime ;
30
- this .cucumberScenario = cucumberScenario ;
29
+ this .runner = runner ;
30
+ this .pickle = pickle ;
31
+ this .language = language ;
31
32
this .jUnitReporter = jUnitReporter ;
32
33
}
33
34
34
- public List <Step > getRunnerSteps () {
35
- return runnerSteps ;
36
- }
37
-
38
35
@ Override
39
- protected List <Step > getChildren () {
40
- return cucumberScenario .getSteps ();
36
+ protected List <PickleStep > getChildren () {
37
+ return pickle .getSteps ();
41
38
}
42
39
43
40
@ Override
44
41
public String getName () {
45
- String name = cucumberScenario . getVisualName ();
42
+ String name = pickle . getName ();
46
43
if (jUnitReporter .useFilenameCompatibleNames ()) {
47
44
return makeNameFilenameCompatible (name );
48
45
} else {
@@ -53,43 +50,27 @@ public String getName() {
53
50
@ Override
54
51
public Description getDescription () {
55
52
if (description == null ) {
56
- description = Description .createSuiteDescription (getName (), cucumberScenario .getGherkinModel ());
57
-
58
- if (cucumberScenario .getCucumberBackground () != null ) {
59
- for (Step backgroundStep : cucumberScenario .getCucumberBackground ().getSteps ()) {
60
- // We need to make a copy of that step, so we have a unique one per scenario
61
- Step copy = new Step (
62
- backgroundStep .getComments (),
63
- backgroundStep .getKeyword (),
64
- backgroundStep .getName (),
65
- backgroundStep .getLine (),
66
- backgroundStep .getRows (),
67
- backgroundStep .getDocString ()
68
- );
69
- description .addChild (describeChild (copy ));
70
- runnerSteps .add (copy );
71
- }
72
- }
53
+ String nameForDescription = getName ().isEmpty () ? "EMPTY_NAME" : getName ();
54
+ description = Description .createSuiteDescription (nameForDescription , new PickleWrapper (pickle ));
73
55
74
- for (Step step : getChildren ()) {
56
+ for (PickleStep step : getChildren ()) {
75
57
description .addChild (describeChild (step ));
76
- runnerSteps .add (step );
77
58
}
78
59
}
79
60
return description ;
80
61
}
81
62
82
63
@ Override
83
- protected Description describeChild (Step step ) {
64
+ protected Description describeChild (PickleStep step ) {
84
65
Description description = stepDescriptions .get (step );
85
66
if (description == null ) {
86
67
String testName ;
87
68
if (jUnitReporter .useFilenameCompatibleNames ()) {
88
- testName = makeNameFilenameCompatible (step .getKeyword () + step . getName ());
69
+ testName = makeNameFilenameCompatible (step .getText ());
89
70
} else {
90
- testName = step .getKeyword () + step . getName ();
71
+ testName = step .getText ();
91
72
}
92
- description = Description .createTestDescription (getName (), testName , step );
73
+ description = Description .createTestDescription (getName (), testName , new PickleStepWrapper ( step ) );
93
74
stepDescriptions .put (step , description );
94
75
}
95
76
return description ;
@@ -99,12 +80,12 @@ protected Description describeChild(Step step) {
99
80
public void run (final RunNotifier notifier ) {
100
81
jUnitReporter .startExecutionUnit (this , notifier );
101
82
// This causes runChild to never be called, which seems OK.
102
- cucumberScenario . run ( jUnitReporter , jUnitReporter , runtime );
83
+ runner . runPickle ( pickle , language );
103
84
jUnitReporter .finishExecutionUnit ();
104
85
}
105
86
106
87
@ Override
107
- protected void runChild (Step step , RunNotifier notifier ) {
88
+ protected void runChild (PickleStep step , RunNotifier notifier ) {
108
89
// The way we override run(RunNotifier) causes this method to never be called.
109
90
// Instead it happens via cucumberScenario.run(jUnitReporter, jUnitReporter, runtime);
110
91
throw new UnsupportedOperationException ();
@@ -115,3 +96,21 @@ private String makeNameFilenameCompatible(String name) {
115
96
return name .replaceAll ("[^A-Za-z0-9_]" , "_" );
116
97
}
117
98
}
99
+
100
+ class PickleWrapper implements Serializable {
101
+ private static final long serialVersionUID = 1L ;
102
+ private Pickle pickle ;
103
+
104
+ public PickleWrapper (Pickle pickle ) {
105
+ this .pickle = pickle ;
106
+ }
107
+ }
108
+
109
+ class PickleStepWrapper implements Serializable {
110
+ private static final long serialVersionUID = 1L ;
111
+ private PickleStep step ;
112
+
113
+ public PickleStepWrapper (PickleStep step ) {
114
+ this .step = step ;
115
+ }
116
+ }
0 commit comments