1
1
package cucumber .runtime ;
2
2
3
+ import gherkin .formatter .Reporter ;
4
+ import gherkin .formatter .model .Background ;
5
+ import gherkin .formatter .model .Examples ;
6
+ import gherkin .formatter .model .Feature ;
7
+ import gherkin .formatter .model .Match ;
8
+ import gherkin .formatter .model .Result ;
9
+ import gherkin .formatter .model .ScenarioOutline ;
10
+ import gherkin .formatter .model .Step ;
11
+ import cucumber .runtime .formatter .FormatterSpy ;
3
12
import cucumber .api .SnippetType ;
4
13
import cucumber .runtime .formatter .ColorAware ;
5
14
import cucumber .runtime .formatter .PluginFactory ;
13
22
import java .io .ByteArrayInputStream ;
14
23
import java .io .IOException ;
15
24
import java .io .UnsupportedEncodingException ;
16
- import java .net .MalformedURLException ;
17
- import java .net .URL ;
18
25
import java .util .Arrays ;
19
26
import java .util .Collections ;
27
+ import java .util .HashMap ;
20
28
import java .util .List ;
21
29
import java .util .Properties ;
22
30
import java .util .regex .Pattern ;
@@ -296,6 +304,35 @@ public void applies_line_filters_only_to_own_feature() throws Exception {
296
304
assertOnlyScenarioName (features .get (1 ), "scenario_2_2" );
297
305
}
298
306
307
+ @ Test
308
+ public void handles_formatters_missing_startOfScenarioLifeCycle_endOfScenarioLifeCycle () throws Throwable {
309
+ CucumberFeature feature = TestHelper .feature ("path/test.feature" , "" +
310
+ "Feature: feature name\n " +
311
+ " Scenario: scenario name\n " +
312
+ " Given step\n " );
313
+
314
+ FormatterSpy formatterSpy = new FormatterSpy ();
315
+ RuntimeOptions runtimeOptions = new RuntimeOptions ("" );
316
+ runtimeOptions .addPlugin (new FormatterMissingLifecycleMethods ());
317
+ runtimeOptions .addPlugin (formatterSpy );
318
+ ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
319
+ TestHelper .runFeatureWithFormatter (feature , new HashMap <String , String >(),
320
+ runtimeOptions .formatter (classLoader ), runtimeOptions .reporter (classLoader ));
321
+
322
+ assertEquals ("" +
323
+ "uri\n " +
324
+ "feature\n " +
325
+ " startOfScenarioLifeCycle\n " +
326
+ " scenario\n " +
327
+ " step\n " +
328
+ " match\n " +
329
+ " result\n " +
330
+ " endOfScenarioLifeCycle\n " +
331
+ "eof\n " +
332
+ "done\n " +
333
+ "close\n " , formatterSpy .toString ());
334
+ }
335
+
299
336
private void assertOnlyScenarioName (CucumberFeature feature , String scenarioName ) {
300
337
assertEquals ("Wrong number of scenarios loaded for feature" , 1 , feature .getFeatureElements ().size ());
301
338
assertEquals ("Scenario: " + scenarioName , feature .getFeatureElements ().get (0 ).getVisualName ());
@@ -309,3 +346,86 @@ private void mockResource(ResourceLoader resourceLoader, String featurePath, Str
309
346
when (resourceLoader .resources (featurePath , ".feature" )).thenReturn (asList (resource1 ));
310
347
}
311
348
}
349
+
350
+ class FormatterMissingLifecycleMethods implements Formatter , Reporter {
351
+ @ Override
352
+ public void startOfScenarioLifeCycle (gherkin .formatter .model .Scenario arg0 ) {
353
+ throw new NoSuchMethodError (); // simulate that this method is not implemented
354
+ }
355
+
356
+ @ Override
357
+ public void endOfScenarioLifeCycle (gherkin .formatter .model .Scenario arg0 ) {
358
+ throw new NoSuchMethodError (); // simulate that this method is not implemented
359
+ }
360
+
361
+ @ Override
362
+ public void after (Match arg0 , Result arg1 ) {
363
+ }
364
+
365
+ @ Override
366
+ public void before (Match arg0 , Result arg1 ) {
367
+ }
368
+
369
+ @ Override
370
+ public void embedding (String arg0 , byte [] arg1 ) {
371
+ }
372
+
373
+ @ Override
374
+ public void match (Match arg0 ) {
375
+ }
376
+
377
+ @ Override
378
+ public void result (Result arg0 ) {
379
+ }
380
+
381
+ @ Override
382
+ public void write (String arg0 ) {
383
+ }
384
+
385
+ @ Override
386
+ public void background (Background arg0 ) {
387
+ }
388
+
389
+ @ Override
390
+ public void close () {
391
+ }
392
+
393
+ @ Override
394
+ public void done () {
395
+ }
396
+
397
+ @ Override
398
+ public void eof () {
399
+ }
400
+
401
+ @ Override
402
+ public void examples (Examples arg0 ) {
403
+ }
404
+
405
+ @ Override
406
+ public void feature (Feature arg0 ) {
407
+
408
+ }
409
+
410
+ @ Override
411
+ public void scenario (gherkin .formatter .model .Scenario arg0 ) {
412
+
413
+ }
414
+
415
+ @ Override
416
+ public void scenarioOutline (ScenarioOutline arg0 ) {
417
+ }
418
+
419
+ @ Override
420
+ public void step (Step arg0 ) {
421
+ }
422
+
423
+ @ Override
424
+ public void syntaxError (String arg0 , String arg1 , List <String > arg2 , String arg3 , Integer arg4 ) {
425
+ }
426
+
427
+ @ Override
428
+ public void uri (String arg0 ) {
429
+ }
430
+
431
+ }
0 commit comments