@@ -68,9 +68,7 @@ public void requestShouldIncludeJsonWireProtocolCapabilities() throws IOExceptio
68
68
69
69
new ProtocolHandshake ().createSession (client , command );
70
70
71
- HttpRequest request = client .getRequest ();
72
- Map <String , Object > json = new Gson ()
73
- .fromJson (request .getContentString (), new TypeToken <Map <String , Object >>(){}.getType ());
71
+ Map <String , Object > json = getRequestPayloadAsMap (client );
74
72
75
73
assertEquals (ImmutableMap .of (), json .get ("desiredCapabilities" ));
76
74
}
@@ -88,9 +86,7 @@ public void requestShouldIncludeOlderGeckoDriverCapabilities() throws IOExceptio
88
86
89
87
new ProtocolHandshake ().createSession (client , command );
90
88
91
- HttpRequest request = client .getRequest ();
92
- Map <String , Object > json = new Gson ()
93
- .fromJson (request .getContentString (), new TypeToken <Map <String , Object >>(){}.getType ());
89
+ Map <String , Object > json = getRequestPayloadAsMap (client );
94
90
Map <String , Object > capabilities = (Map <String , Object >) json .get ("capabilities" );
95
91
96
92
assertEquals (ImmutableMap .of (), capabilities .get ("desiredCapabilities" ));
@@ -109,9 +105,7 @@ public void requestShouldIncludeSpecCompliantW3CCapabilities() throws IOExceptio
109
105
110
106
new ProtocolHandshake ().createSession (client , command );
111
107
112
- HttpRequest request = client .getRequest ();
113
- Map <String , Object > json = new Gson ()
114
- .fromJson (request .getContentString (), new TypeToken <Map <String , Object >>(){}.getType ());
108
+ Map <String , Object > json = getRequestPayloadAsMap (client );
115
109
116
110
List <Map <String , Object >> caps = mergeW3C (json );
117
111
@@ -180,10 +174,7 @@ public void shouldAddBothGeckoDriverAndW3CCapabilitiesToRootCapabilitiesProperty
180
174
181
175
new ProtocolHandshake ().createSession (client , command );
182
176
183
- HttpRequest request = client .getRequest ();
184
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
185
- request .getContentString (),
186
- new TypeToken <Map <String , Object >>() {}.getType ());
177
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
187
178
188
179
Object rawCaps = handshakeRequest .get ("capabilities" );
189
180
assertTrue (rawCaps instanceof Map );
@@ -215,11 +206,7 @@ public void shouldNotIncludeNonProtocolExtensionKeys() throws IOException {
215
206
216
207
new ProtocolHandshake ().createSession (client , command );
217
208
218
- HttpRequest request = client .getRequest ();
219
-
220
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
221
- request .getContentString (),
222
- new TypeToken <Map <String , Object >>() {}.getType ());
209
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
223
210
224
211
Object rawCaps = handshakeRequest .get ("capabilities" );
225
212
assertTrue (rawCaps instanceof Map );
@@ -258,10 +245,7 @@ public void firstMatchSeparatesCapsForDifferentBrowsers() throws IOException {
258
245
259
246
new ProtocolHandshake ().createSession (client , command );
260
247
261
- HttpRequest request = client .getRequest ();
262
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
263
- request .getContentString (),
264
- new TypeToken <Map <String , Object >>() {}.getType ());
248
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
265
249
266
250
List <Map <String , Object >> capabilities = mergeW3C (handshakeRequest );
267
251
@@ -288,10 +272,7 @@ public void doesNotCreateFirstMatchForNonW3CCaps() throws IOException {
288
272
289
273
new ProtocolHandshake ().createSession (client , command );
290
274
291
- HttpRequest request = client .getRequest ();
292
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
293
- request .getContentString (),
294
- new TypeToken <Map <String , Object >>() {}.getType ());
275
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
295
276
296
277
List <Map <String , Object >> w3c = mergeW3C (handshakeRequest );
297
278
@@ -320,10 +301,7 @@ public void shouldLowerCaseProxyTypeForW3CRequest() throws IOException {
320
301
321
302
new ProtocolHandshake ().createSession (client , command );
322
303
323
- HttpRequest request = client .getRequest ();
324
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
325
- request .getContentString (),
326
- new TypeToken <Map <String , Object >>() {}.getType ());
304
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
327
305
328
306
mergeW3C (handshakeRequest ).forEach (always -> {
329
307
Map <String , ?> seenProxy = (Map <String , ?>) always .get ("proxy" );
@@ -353,10 +331,7 @@ public void shouldNotIncludeMappingOfANYPlatform() throws IOException {
353
331
354
332
new ProtocolHandshake ().createSession (client , command );
355
333
356
- HttpRequest request = client .getRequest ();
357
- Map <String , Object > handshakeRequest = new Gson ().fromJson (
358
- request .getContentString (),
359
- new TypeToken <Map <String , Object >>() {}.getType ());
334
+ Map <String , Object > handshakeRequest = getRequestPayloadAsMap (client );
360
335
361
336
mergeW3C (handshakeRequest )
362
337
.forEach (capabilities -> {
@@ -389,33 +364,33 @@ private List<Map<String, Object>> mergeW3C(Map<String, Object> caps) {
389
364
return allCaps ;
390
365
}
391
366
367
+ private Map <String , Object > getRequestPayloadAsMap (RecordingHttpClient client ) {
368
+ return new Gson ().fromJson (
369
+ client .getRequestPayload (), new TypeToken <Map <String , Object >>(){}.getType ());
370
+ }
371
+
392
372
class RecordingHttpClient implements HttpClient {
393
373
394
374
private final HttpResponse response ;
395
- private HttpRequest request ;
375
+ private String payload ;
396
376
397
- public RecordingHttpClient (HttpResponse response ) {
377
+ RecordingHttpClient (HttpResponse response ) {
398
378
this .response = response ;
399
379
}
400
380
401
381
@ Override
402
- public HttpResponse execute (HttpRequest request ) throws IOException {
403
- return execute (request , true );
404
- }
405
-
406
- private HttpResponse execute (HttpRequest request , boolean followRedirects ) throws IOException {
407
- this .request = request ;
408
- request .getContentString ();
382
+ public HttpResponse execute (HttpRequest request ) {
383
+ payload = request .getContentString ();
409
384
return response ;
410
385
}
411
386
412
387
@ Override
413
- public void close () throws IOException {
388
+ public void close () {
414
389
// Does nothing
415
390
}
416
391
417
- public HttpRequest getRequest () {
418
- return request ;
392
+ String getRequestPayload () {
393
+ return payload ;
419
394
}
420
395
}
421
396
}
0 commit comments