@@ -217,10 +217,13 @@ public void writeTo(Appendable appendable) throws IOException {
217
217
try (JsonOutput json = new Json ().newOutput (appendable )) {
218
218
json .beginObject ();
219
219
220
- @ SuppressWarnings ("unchecked" )
221
- Map <String , Object > first = (Map <String , Object >) stream ().findFirst ()
222
- .orElse (new ImmutableCapabilities ())
223
- .asMap ();
220
+ Map <String , Object > first = getOss ();
221
+ if (first == null ) {
222
+ //noinspection unchecked
223
+ first = (Map <String , Object >) stream ().findFirst ()
224
+ .orElse (new ImmutableCapabilities ())
225
+ .asMap ();
226
+ }
224
227
225
228
// Write the first capability we get as the desired capability.
226
229
json .name ("desiredCapabilities" );
@@ -295,7 +298,7 @@ public Stream<ImmutableCapabilities> stream() throws IOException {
295
298
}
296
299
297
300
public ImmutableSet <Dialect > getDownstreamDialects () {
298
- return dialects .isEmpty () ? ImmutableSet .of (Dialect . OSS ) : dialects ;
301
+ return dialects .isEmpty () ? ImmutableSet .of (DEFAULT_DIALECT ) : dialects ;
299
302
}
300
303
301
304
@ Override
@@ -325,7 +328,7 @@ private Stream<Map<String, Object>> getW3C() throws IOException {
325
328
// then add magic to generate each of the w3c capabilities. For the sake of simplicity, we're
326
329
// going to make the (probably wrong) assumption we can hold all of the firstMatch values and
327
330
// alwaysMatch value in memory at the same time.
328
- Map <String , Object > oss = getOss ();
331
+ Map <String , Object > oss = convertOssToW3C ( getOss () );
329
332
Stream <Map <String , Object >> fromOss ;
330
333
if (oss != null ) {
331
334
Set <String > usedKeys = new HashSet <>();
@@ -357,11 +360,10 @@ private Stream<Map<String, Object>> getW3C() throws IOException {
357
360
// into the stream to form a unified set of capabilities. Woohoo!
358
361
fromOss = firsts .stream ()
359
362
.map (first -> ImmutableMap .<String , Object >builder ().putAll (always ).putAll (first ).build ())
360
- .map (this ::convertOssToW3C )
363
+ .map (this ::applyTransforms )
361
364
.map (map -> map .entrySet ().stream ()
362
365
.filter (entry -> ACCEPTED_W3C_PATTERNS .test (entry .getKey ()))
363
366
.collect (ImmutableMap .toImmutableMap (Map .Entry ::getKey , Map .Entry ::getValue )))
364
- .filter (map -> !map .isEmpty ())
365
367
.map (map -> (Map <String , Object >) map );
366
368
} else {
367
369
fromOss = Stream .of ();
@@ -386,10 +388,14 @@ private Stream<Map<String, Object>> getW3C() throws IOException {
386
388
.map (first -> ImmutableMap .<String , Object >builder ().putAll (always ).putAll (first ).build ());
387
389
}
388
390
389
- return Stream .concat (fromOss , fromW3c );
391
+ return Stream .concat (fromOss , fromW3c ). distinct () ;
390
392
}
391
393
392
- private Map <String , Object > convertOssToW3C (ImmutableMap <String , Object > capabilities ) {
394
+ private Map <String , Object > convertOssToW3C (Map <String , Object > capabilities ) {
395
+ if (capabilities == null ) {
396
+ return null ;
397
+ }
398
+
393
399
Map <String , Object > toReturn = new TreeMap <>();
394
400
toReturn .putAll (capabilities );
395
401
0 commit comments