4343import  static  org .hamcrest .collection .IsIterableContainingInOrder .contains ;
4444import  static  org .hamcrest .core .Is .is ;
4545import  static  org .hamcrest .core .IsEqual .equalTo ;
46- import  static  org .junit .jupiter .api .Assertions .assertAll ;
47- import  static  org .junit .jupiter .api .Assertions .assertThrows ;
48- import  static  org .junit .jupiter .api .Assertions .assertTrue ;
46+ import  static  org .junit .jupiter .api .Assertions .*;
4947import  static  org .mockito .Mockito .mock ;
5048import  static  org .mockito .Mockito .when ;
5149
@@ -464,7 +462,7 @@ void scenario_scoped_hooks_have_higher_order() {
464462    }
465463
466464    @ Test 
467-     public   void  emits_hook_messages_to_bus () {
465+     void  emits_hook_messages_to_bus () {
468466
469467        List <Envelope > events  = new  ArrayList <>();
470468        EventHandler <Envelope > messageEventHandler  = e  -> events .add (e );
@@ -482,6 +480,50 @@ public void emits_hook_messages_to_bus() {
482480        assertThat (events .size (), is (4 ));
483481    }
484482
483+     @ Test 
484+     void  parameterTypeDefinition_without_source_reference_emits_parameterType_with_empty_source_reference () {
485+         // Given 
486+         List <Envelope > events  = new  ArrayList <>();
487+         EventHandler <Envelope > messageEventHandler  = events ::add ;
488+ 
489+         EventBus  bus  = new  TimeServiceEventBus (Clock .systemUTC (), UUID ::randomUUID );
490+         bus .registerHandlerFor (Envelope .class , messageEventHandler );
491+         CachingGlue  glue  = new  CachingGlue (bus );
492+ 
493+         glue .addParameterType (new  MockedParameterTypeDefinition ());
494+ 
495+         // When 
496+         glue .prepareGlue (stepTypeRegistry );
497+ 
498+         // Then 
499+         assertThat (events .size (), is (1 ));
500+         io .cucumber .messages .types .SourceReference  sourceReference  = events .get (0 ).getParameterType ().get ()
501+                 .getSourceReference ().get ();
502+         assertEquals (new  io .cucumber .messages .types .SourceReference (null , null , null , null ), sourceReference );
503+     }
504+ 
505+     @ Test 
506+     void  parameterTypeDefinition_with_source_reference_emits_parameterType_with_non_empty_source_reference () {
507+         // Given 
508+         List <Envelope > events  = new  ArrayList <>();
509+         EventHandler <Envelope > messageEventHandler  = events ::add ;
510+ 
511+         EventBus  bus  = new  TimeServiceEventBus (Clock .systemUTC (), UUID ::randomUUID );
512+         bus .registerHandlerFor (Envelope .class , messageEventHandler );
513+         CachingGlue  glue  = new  CachingGlue (bus );
514+ 
515+         glue .addParameterType (new  MockedParameterTypeDefinitionWithSourceReference ());
516+ 
517+         // When 
518+         glue .prepareGlue (stepTypeRegistry );
519+ 
520+         // Then 
521+         assertThat (events .size (), is (1 ));
522+         io .cucumber .messages .types .SourceReference  sourceReference  = events .get (0 ).getParameterType ().get ()
523+                 .getSourceReference ().get ();
524+         assertNotNull (sourceReference .getJavaStackTraceElement ());
525+     }
526+ 
485527    private  static  class  MockedScenarioScopedStepDefinition  extends  StubStepDefinition  implements  ScenarioScoped  {
486528
487529        MockedScenarioScopedStepDefinition (String  pattern , Type ... types ) {
@@ -564,6 +606,17 @@ public boolean isDisposed() {
564606
565607    }
566608
609+     private  static  class  MockedParameterTypeDefinitionWithSourceReference  extends  MockedParameterTypeDefinition  {
610+         @ Override 
611+         public  Optional <SourceReference > getSourceReference () {
612+             return  Optional .of (SourceReference .fromStackTraceElement (new  StackTraceElement (
613+                 "MockedParameterTypeDefinition" ,
614+                 "getSourceReference" ,
615+                 "CachingGlueTest.java" ,
616+                 593 )));
617+         }
618+     }
619+ 
567620    private  static  class  MockedHookDefinition  implements  HookDefinition  {
568621
569622        private  final  int  order ;
0 commit comments