@@ -73,7 +73,23 @@ class ScalaDslStepsTest {
7373
7474 val glue = new GlueWithException ()
7575
76- assertClassStepDefinitionThrow(glue.registry.stepDefinitions.head, " io.cucumber.scala.ScalaDslStepsTest$GlueWithException" , " ScalaDslStepsTest.scala" , 70 , Array ())
76+ assertClassStepDefinitionThrow(glue.registry.stepDefinitions.head, classOf [PendingException ], " io.cucumber.scala.ScalaDslStepsTest$GlueWithException" , " ScalaDslStepsTest.scala" , 70 , Array ())
77+ }
78+
79+ // Note: this is a corner case that we should prevent to happen in the future
80+ @ Test
81+ def testDefNullParameters (): Unit = {
82+
83+ class Glue extends ScalaDsl with EN {
84+ Given (" Something {}" ) { (str : String ) =>
85+ // Nothing
86+ println(str)
87+ }
88+ }
89+
90+ val glue = new Glue ()
91+
92+ assertClassStepDefinitionThrow(glue.registry.stepDefinitions.head, classOf [IncorrectStepDefinitionException ], " io.cucumber.scala.ScalaDslStepsTest" , " ScalaDslStepsTest.scala" , 209 , Array (null ))
7793 }
7894
7995 // -------------------- Test on object --------------------
@@ -91,7 +107,7 @@ class ScalaDslStepsTest {
91107 // @formatter:on
92108 }
93109
94- assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:90 " , Array (), invoked)
110+ assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:106 " , Array (), invoked)
95111 }
96112
97113 @ Test
@@ -105,7 +121,7 @@ class ScalaDslStepsTest {
105121 }
106122 }
107123
108- assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:103 " , Array (), invoked)
124+ assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:119 " , Array (), invoked)
109125 }
110126
111127 @ Test
@@ -121,7 +137,7 @@ class ScalaDslStepsTest {
121137 }
122138 }
123139
124- assertObjectStepDefinition(Glue .registry.stepDefinitions.head, """ Oh boy, (\d+) (\s+) cukes""" , " ScalaDslStepsTest.scala:118 " , Array (new java.lang.Integer (5 ), " green" ), thenumber == 5 && thecolour == " green" )
140+ assertObjectStepDefinition(Glue .registry.stepDefinitions.head, """ Oh boy, (\d+) (\s+) cukes""" , " ScalaDslStepsTest.scala:134 " , Array (new java.lang.Integer (5 ), " green" ), thenumber == 5 && thecolour == " green" )
125141 }
126142
127143 @ Test
@@ -134,7 +150,21 @@ class ScalaDslStepsTest {
134150 }
135151 }
136152
137- assertObjectStepDefinitionThrow(GlueWithException .registry.stepDefinitions.head, " io.cucumber.scala.ScalaDslStepsTest$GlueWithException" , " ScalaDslStepsTest.scala" , 133 , Array ())
153+ assertObjectStepDefinitionThrow(GlueWithException .registry.stepDefinitions.head, classOf [PendingException ], " io.cucumber.scala.ScalaDslStepsTest$GlueWithException" , " ScalaDslStepsTest.scala" , 149 , Array ())
154+ }
155+
156+ // Note: this is a corner case that we should prevent to happen in the future
157+ @ Test
158+ def testObjectDefNullParameters (): Unit = {
159+
160+ object Glue extends ScalaDsl with EN {
161+ Given (" Something {}" ) { (str : String ) =>
162+ // Nothing
163+ println(str)
164+ }
165+ }
166+
167+ assertClassStepDefinitionThrow(Glue .registry.stepDefinitions.head, classOf [IncorrectStepDefinitionException ], " io.cucumber.scala.ScalaDslStepsTest" , " ScalaDslStepsTest.scala" , 209 , Array (null ))
138168 }
139169
140170 private def assertClassStepDefinition (stepDetails : ScalaStepDetails , pattern : String , location : String , args : Array [AnyRef ], check : => Boolean ): Unit = {
@@ -152,31 +182,48 @@ class ScalaDslStepsTest {
152182 assertTrue(check)
153183 }
154184
155- private def assertClassStepDefinitionThrow (stepDetails : ScalaStepDetails , exceptionClassName : String , exceptionFile : String , exceptionLine : Int , args : Array [AnyRef ]): Unit = {
156- assertStepDefinitionThrow(ScalaStepDefinition (stepDetails, true ), exceptionClassName, exceptionFile, exceptionLine, args)
185+ private def assertClassStepDefinitionThrow (stepDetails : ScalaStepDetails ,
186+ underlyingExceptionClass : Class [_ <: Exception ],
187+ exceptionClassName : String ,
188+ exceptionFile : String ,
189+ exceptionLine : Int ,
190+ args : Array [AnyRef ]): Unit = {
191+ assertStepDefinitionThrow(ScalaStepDefinition (stepDetails, true ), underlyingExceptionClass, exceptionClassName, exceptionFile, exceptionLine, args)
157192 }
158193
159- private def assertObjectStepDefinitionThrow (stepDetails : ScalaStepDetails , exceptionClassName : String , exceptionFile : String , exceptionLine : Int , args : Array [AnyRef ]): Unit = {
160- assertStepDefinitionThrow(ScalaStepDefinition (stepDetails, false ), exceptionClassName, exceptionFile, exceptionLine, args)
194+ private def assertObjectStepDefinitionThrow (stepDetails : ScalaStepDetails ,
195+ underlyingExceptionClass : Class [_ <: Exception ],
196+ exceptionClassName : String ,
197+ exceptionFile : String ,
198+ exceptionLine : Int ,
199+ args : Array [AnyRef ]): Unit = {
200+ assertStepDefinitionThrow(ScalaStepDefinition (stepDetails, false ), underlyingExceptionClass, exceptionClassName, exceptionFile, exceptionLine, args)
161201 }
162202
163- private def assertStepDefinitionThrow (stepDefinition : StepDefinition , exceptionClassName : String , exceptionFile : String , exceptionLine : Int , args : Array [AnyRef ]): Unit = {
203+ private def assertStepDefinitionThrow (stepDefinition : StepDefinition ,
204+ underlyingExceptionClass : Class [_ <: Exception ],
205+ exceptionClassName : String ,
206+ exceptionFile : String ,
207+ exceptionLine : Int ,
208+ args : Array [AnyRef ]): Unit = {
164209 val tried = Try (stepDefinition.execute(args))
165210
166211 assertTrue(tried.isFailure)
167212
168213 val ex = tried.failed.get
169214 assertTrue(ex.isInstanceOf [CucumberInvocationTargetException ])
170215
171- val matched = ex.asInstanceOf [CucumberInvocationTargetException ]
172- .getInvocationTargetExceptionCause
216+ val underlying = ex.asInstanceOf [CucumberInvocationTargetException ].getInvocationTargetExceptionCause
217+ assertEquals(underlyingExceptionClass, underlying.getClass)
218+
219+ val matched = underlying
173220 .getStackTrace
174221 .filter(stepDefinition.isDefinedAt)
175222 .head
176223
177224 // The result is different between Scala versions, that's why we don't check it precisely
178225 // assertEquals("$anonfun$can_provide_location_of_step$1", matched.getMethodName)
179- assertTrue(matched.getClassName.contains(exceptionClassName))
226+ assertTrue(s " ${matched.getClassName} did not contain $exceptionClassName " , matched.getClassName.contains(exceptionClassName))
180227 assertEquals(exceptionFile, matched.getFileName)
181228 assertEquals(exceptionLine, matched.getLineNumber)
182229 }
0 commit comments