@@ -131,7 +131,7 @@ public void testCauseShouldUseTheNamedClassIfAvailableOnTheClassPath() {
131
131
.isThrownBy (() -> handler .throwIfResponseFailed (
132
132
createResponse (ErrorCodes .UNHANDLED_ERROR ,
133
133
ImmutableMap .of ("message" , "boom" , "class" , NullPointerException .class .getName ())), 123 ))
134
- .withMessage (new WebDriverException ("boom\n Command duration or timeout: 123 milliseconds" ).getMessage ())
134
+ .withMessage (new WebDriverException ("boom (WARNING: The server did not provide any stacktrace information) \n Command duration or timeout: 123 milliseconds" ).getMessage ())
135
135
.withCauseInstanceOf (NullPointerException .class )
136
136
.satisfies (expected -> assertThat (expected .getCause ()).hasMessage ("boom" ));
137
137
}
@@ -142,7 +142,7 @@ public void testCauseStackTraceShouldBeEmptyIfTheServerDidNotProvideThatInformat
142
142
.isThrownBy (() -> handler .throwIfResponseFailed (
143
143
createResponse (ErrorCodes .UNHANDLED_ERROR ,
144
144
ImmutableMap .of ("message" , "boom" , "class" , NullPointerException .class .getName ())), 1234 ))
145
- .withMessage (new WebDriverException ("boom\n Command duration or timeout: 1.23 seconds" ).getMessage ())
145
+ .withMessage (new WebDriverException ("boom (WARNING: The server did not provide any stacktrace information) \n Command duration or timeout: 1.23 seconds" ).getMessage ())
146
146
.withCauseInstanceOf (NullPointerException .class )
147
147
.satisfies (expected -> {
148
148
assertThat (expected .getCause ()).hasMessage ("boom" );
@@ -239,58 +239,53 @@ public void testShouldStillTryToBuildWebDriverExceptionIfClassIsNotProvidedAndSt
239
239
});
240
240
}
241
241
242
- @ SuppressWarnings ("ThrowableInstanceNeverThrown" )
243
242
@ Test
244
243
public void testShoulNotBuildWebDriverExceptionIfClassAndStackTraceIsNull () {
245
- Map <String , ?> data = ImmutableMap .of (
246
- "message" , "some error message" ,
247
- "class" , null ,
248
- "stackTrace" , null );
249
-
250
- try {
251
- handler .throwIfResponseFailed (createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 );
252
- fail ("Should have thrown!" );
253
- } catch (WebDriverException expected ) {
254
- assertEquals (new WebDriverException ("some error message\n Command duration or timeout: 123 milliseconds" ,
255
- new WebDriverException ()).getMessage (),
256
- expected .getMessage ());
257
- }
244
+ Map <String , Object > data = new HashMap <>();
245
+ data .put ("message" , "some error message" );
246
+ data .put ("class" , null );
247
+ data .put ("stackTrace" , null );
248
+
249
+ assertThatExceptionOfType (WebDriverException .class )
250
+ .isThrownBy (() -> handler .throwIfResponseFailed (
251
+ createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 ))
252
+ .withMessageStartingWith (new WebDriverException (
253
+ "some error message (WARNING: The server did not provide any stacktrace information)\n Command duration or timeout: 123 milliseconds" ,
254
+ new WebDriverException ()).getMessage ());
258
255
}
259
256
260
- @ SuppressWarnings ("ThrowableInstanceNeverThrown" )
261
257
@ Test
262
258
public void testShoulNotBuildWebDriverExceptionIfClassNullAndStackTraceNotNull () {
263
- Map <String , ?> data = ImmutableMap .of (
264
- "message" , "some error message" ,
265
- "class" , null ,
266
- "stackTrace" , "a" );
267
-
268
- try {
269
- handler .throwIfResponseFailed (createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 );
270
- fail ("Should have thrown!" );
271
- } catch (WebDriverException expected ) {
272
- assertEquals (new WebDriverException ("some error message\n Command duration or timeout: 123 milliseconds" ,
273
- new WebDriverException ()).getMessage (),
274
- expected .getMessage ());
275
- }
259
+ Map <String , Object > data = new HashMap <>();
260
+ data .put ("message" , "some error message" );
261
+ data .put ("class" , null );
262
+ data .put ("stackTrace" , Collections .singletonList (
263
+ ImmutableMap .of ("lineNumber" , 1224 ,
264
+ "methodName" , "someMethod" ,
265
+ "className" , "MyClass" ,
266
+ "fileName" , "Resource.m" )));
267
+
268
+ assertThatExceptionOfType (WebDriverException .class )
269
+ .isThrownBy (() -> handler .throwIfResponseFailed (
270
+ createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 ))
271
+ .withMessageStartingWith (new WebDriverException (
272
+ "some error message\n Command duration or timeout: 123 milliseconds" ,
273
+ new WebDriverException ()).getMessage ());
276
274
}
277
275
278
- @ SuppressWarnings ("ThrowableInstanceNeverThrown" )
279
276
@ Test
280
277
public void testShoulNotBuildWebDriverExceptionIfClassNotNullAndStackTraceNull () {
281
- Map <String , ?> data = ImmutableMap .of (
282
- "message" , "some error message" ,
283
- "class" , "a" ,
284
- "stackTrace" , null );
285
-
286
- try {
287
- handler .throwIfResponseFailed (createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 );
288
- fail ("Should have thrown!" );
289
- } catch (WebDriverException expected ) {
290
- assertEquals (new WebDriverException ("some error message\n Command duration or timeout: 123 milliseconds" ,
291
- new WebDriverException ()).getMessage (),
292
- expected .getMessage ());
293
- }
278
+ Map <String , Object > data = new HashMap <>();
279
+ data .put ("message" , "some error message" );
280
+ data .put ("class" , "a" );
281
+ data .put ("stackTrace" , null );
282
+
283
+ assertThatExceptionOfType (WebDriverException .class )
284
+ .isThrownBy (() -> handler .throwIfResponseFailed (
285
+ createResponse (ErrorCodes .UNHANDLED_ERROR , data ), 123 ))
286
+ .withMessageStartingWith (new WebDriverException (
287
+ "some error message (WARNING: The server did not provide any stacktrace information)\n Command duration or timeout: 123 milliseconds" ,
288
+ new WebDriverException ()).getMessage ());
294
289
}
295
290
296
291
@ Test
0 commit comments