5
5
import io .cucumber .core .gherkin .Example ;
6
6
import io .cucumber .core .gherkin .Examples ;
7
7
import io .cucumber .core .gherkin .Feature ;
8
- import io .cucumber .core .gherkin .Located ;
9
8
import io .cucumber .core .gherkin .Named ;
9
+ import io .cucumber .core .gherkin .Pickle ;
10
10
import io .cucumber .core .gherkin .Rule ;
11
11
import io .cucumber .core .gherkin .Scenario ;
12
12
import io .cucumber .core .gherkin .ScenarioOutline ;
@@ -96,7 +96,7 @@ private void resolvePath(Path path) {
96
96
.scanForResourcesPath (path )
97
97
.stream ()
98
98
.sorted (comparing (Feature ::getUri ))
99
- .map (this ::resolveFeature )
99
+ .map (this ::createFeatureDescriptor )
100
100
.forEach (engineDescriptor ::mergeFeature );
101
101
}
102
102
@@ -117,7 +117,7 @@ private void resolvePackageResource(String packageName) {
117
117
.scanForResourcesInPackage (packageName , packageFilter )
118
118
.stream ()
119
119
.sorted (comparing (Feature ::getUri ))
120
- .map (this ::resolveFeature )
120
+ .map (this ::createFeatureDescriptor )
121
121
.forEach (engineDescriptor ::mergeFeature );
122
122
}
123
123
@@ -127,7 +127,7 @@ void resolveClasspathResource(ClasspathResourceSelector selector) {
127
127
.scanForClasspathResource (classpathResourceName , packageFilter )
128
128
.stream ()
129
129
.sorted (comparing (Feature ::getUri ))
130
- .map (this ::resolveFeature )
130
+ .map (this ::createFeatureDescriptor )
131
131
.forEach (engineDescriptor ::mergeFeature );
132
132
}
133
133
@@ -136,7 +136,7 @@ void resolveClasspathRoot(ClasspathRootSelector selector) {
136
136
.scanForResourcesInClasspathRoot (selector .getClasspathRoot (), packageFilter )
137
137
.stream ()
138
138
.sorted (comparing (Feature ::getUri ))
139
- .map (this ::resolveFeature )
139
+ .map (this ::createFeatureDescriptor )
140
140
.forEach (engineDescriptor ::mergeFeature );
141
141
}
142
142
@@ -182,81 +182,70 @@ private Stream<FeatureDescriptor> resolveUri(URI uri) {
182
182
.scanForResourcesUri (uri )
183
183
.stream ()
184
184
.sorted (comparing (Feature ::getUri ))
185
- .map (this ::resolveFeature );
185
+ .map (this ::createFeatureDescriptor );
186
186
}
187
187
188
- private FeatureDescriptor resolveFeature (Feature feature ) {
188
+ private FeatureDescriptor createFeatureDescriptor (Feature feature ) {
189
189
FeatureOrigin source = FeatureOrigin .fromUri (feature .getUri ());
190
- FeatureDescriptor descriptor = new FeatureDescriptor (
191
- source .featureSegment (engineDescriptor .getUniqueId (), feature ),
192
- getNameOrKeyWord (feature ),
193
- source .featureSource (),
194
- feature
195
- );
196
- feature .children ().forEach (scenarioDefinition -> visit (feature , descriptor , source , scenarioDefinition ));
197
- return descriptor ;
198
- }
199
-
200
- private <T extends Located & Named > void visit (Feature feature , TestDescriptor parent , FeatureOrigin source , T node ) {
201
- if (node instanceof Scenario ) {
202
- feature .getPickleAt (node )
203
- .ifPresent (pickle -> {
204
- PickleDescriptor descriptor = new PickleDescriptor (
205
- source .scenarioSegment (parent .getUniqueId (), node ),
206
- getNameOrKeyWord (node ),
207
- source .nodeSource (node ),
208
- pickle
209
- );
210
- parent .addChild (descriptor );
211
- });
212
- }
213
-
214
- if (node instanceof Rule ) {
215
- NodeDescriptor descriptor = new NodeDescriptor (
216
- source .ruleSegment (parent .getUniqueId (), node ),
217
- getNameOrKeyWord (node ),
218
- source .nodeSource (node )
219
- );
220
- parent .addChild (descriptor );
221
- Rule rule = (Rule ) node ;
222
- rule .children ().forEach (section -> visit (feature , descriptor , source , section ));
223
- }
224
-
225
- if (node instanceof ScenarioOutline ) {
226
- NodeDescriptor descriptor = new NodeDescriptor (
227
- source .scenarioSegment (parent .getUniqueId (), node ),
228
- getNameOrKeyWord (node ),
229
- source .nodeSource (node )
230
- );
231
- parent .addChild (descriptor );
232
- ScenarioOutline scenarioOutline = (ScenarioOutline ) node ;
233
- scenarioOutline .children ().forEach (section -> visit (feature , descriptor , source , section ));
234
- }
235
-
236
- if (node instanceof Examples ) {
237
- NodeDescriptor descriptor = new NodeDescriptor (
238
- source .examplesSegment (parent .getUniqueId (), node ),
239
- getNameOrKeyWord (node ),
240
- source .nodeSource (node )
241
- );
242
- parent .addChild (descriptor );
243
- Examples examples = (Examples ) node ;
244
- examples .children ().forEach (example -> visit (feature , descriptor , source , example ));
245
- }
246
-
247
- if (node instanceof Example ) {
248
- feature .getPickleAt (node )
249
- .ifPresent (pickle -> {
250
- PickleDescriptor descriptor = new PickleDescriptor (
251
- source .exampleSegment (parent .getUniqueId (), node ),
252
- getNameOrKeyWord (node ),
253
- source .nodeSource (node ),
254
- pickle
255
- );
256
- parent .addChild (descriptor );
257
- });
258
- }
259
190
191
+ return (FeatureDescriptor ) feature .map (
192
+ engineDescriptor ,
193
+ (Feature self , TestDescriptor parent ) -> new FeatureDescriptor (
194
+ source .featureSegment (parent .getUniqueId (), self ),
195
+ getNameOrKeyWord (self ),
196
+ source .featureSource (),
197
+ self
198
+ ),
199
+ (Scenario node , TestDescriptor parent ) -> {
200
+ Pickle pickle = feature .getPickleAt (node );
201
+ TestDescriptor descriptor = new PickleDescriptor (
202
+ source .scenarioSegment (parent .getUniqueId (), node ),
203
+ getNameOrKeyWord (node ),
204
+ source .nodeSource (node ),
205
+ pickle
206
+ );
207
+ parent .addChild (descriptor );
208
+ return descriptor ;
209
+ },
210
+ (Rule node , TestDescriptor parent ) -> {
211
+ TestDescriptor descriptor = new NodeDescriptor (
212
+ source .ruleSegment (parent .getUniqueId (), node ),
213
+ getNameOrKeyWord (node ),
214
+ source .nodeSource (node )
215
+ );
216
+ parent .addChild (descriptor );
217
+ return descriptor ;
218
+ },
219
+ (ScenarioOutline node , TestDescriptor parent ) -> {
220
+ TestDescriptor descriptor = new NodeDescriptor (
221
+ source .scenarioSegment (parent .getUniqueId (), node ),
222
+ getNameOrKeyWord (node ),
223
+ source .nodeSource (node )
224
+ );
225
+ parent .addChild (descriptor );
226
+ return descriptor ;
227
+ },
228
+ (Examples node , TestDescriptor parent ) -> {
229
+ NodeDescriptor descriptor = new NodeDescriptor (
230
+ source .examplesSegment (parent .getUniqueId (), node ),
231
+ getNameOrKeyWord (node ),
232
+ source .nodeSource (node )
233
+ );
234
+ parent .addChild (descriptor );
235
+ return descriptor ;
236
+ },
237
+ (Example node , TestDescriptor parent ) -> {
238
+ Pickle pickle = feature .getPickleAt (node );
239
+ PickleDescriptor descriptor = new PickleDescriptor (
240
+ source .exampleSegment (parent .getUniqueId (), node ),
241
+ getNameOrKeyWord (node ),
242
+ source .nodeSource (node ),
243
+ pickle
244
+ );
245
+ parent .addChild (descriptor );
246
+ return descriptor ;
247
+ }
248
+ );
260
249
}
261
250
262
251
private <T extends Named > String getNameOrKeyWord (T node ) {
0 commit comments