@@ -73,7 +73,23 @@ class ScalaDslStepsTest {
73
73
74
74
val glue = new GlueWithException ()
75
75
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 ))
77
93
}
78
94
79
95
// -------------------- Test on object --------------------
@@ -91,7 +107,7 @@ class ScalaDslStepsTest {
91
107
// @formatter:on
92
108
}
93
109
94
- assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:90 " , Array (), invoked)
110
+ assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:106 " , Array (), invoked)
95
111
}
96
112
97
113
@ Test
@@ -105,7 +121,7 @@ class ScalaDslStepsTest {
105
121
}
106
122
}
107
123
108
- assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:103 " , Array (), invoked)
124
+ assertObjectStepDefinition(Glue .registry.stepDefinitions.head, " Something" , " ScalaDslStepsTest.scala:119 " , Array (), invoked)
109
125
}
110
126
111
127
@ Test
@@ -121,7 +137,7 @@ class ScalaDslStepsTest {
121
137
}
122
138
}
123
139
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" )
125
141
}
126
142
127
143
@ Test
@@ -134,7 +150,21 @@ class ScalaDslStepsTest {
134
150
}
135
151
}
136
152
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 ))
138
168
}
139
169
140
170
private def assertClassStepDefinition (stepDetails : ScalaStepDetails , pattern : String , location : String , args : Array [AnyRef ], check : => Boolean ): Unit = {
@@ -152,31 +182,48 @@ class ScalaDslStepsTest {
152
182
assertTrue(check)
153
183
}
154
184
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)
157
192
}
158
193
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)
161
201
}
162
202
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 = {
164
209
val tried = Try (stepDefinition.execute(args))
165
210
166
211
assertTrue(tried.isFailure)
167
212
168
213
val ex = tried.failed.get
169
214
assertTrue(ex.isInstanceOf [CucumberInvocationTargetException ])
170
215
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
173
220
.getStackTrace
174
221
.filter(stepDefinition.isDefinedAt)
175
222
.head
176
223
177
224
// The result is different between Scala versions, that's why we don't check it precisely
178
225
// 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))
180
227
assertEquals(exceptionFile, matched.getFileName)
181
228
assertEquals(exceptionLine, matched.getLineNumber)
182
229
}
0 commit comments