Skip to content

Commit bdd4bbd

Browse files
committed
fix(utils): replace putIfAbsent with computeIfAbsent
1 parent 07058b8 commit bdd4bbd

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/main/java/io/github/seleniumquery/utils/DriverVersionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 seleniumQuery authors
2+
* Copyright (c) 2017 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public static void overrideSingletonInstance(DriverVersionUtils instance) {
6262
}
6363

6464
public boolean hasNativeSupportForPseudo(WebDriver driver, String pseudoClass) {
65-
Map<String, Boolean> driverMap = driverSupportedPseudos.putIfAbsent(driver, new HashMap<>());
65+
Map<String, Boolean> driverMap = driverSupportedPseudos.computeIfAbsent(driver, k -> new HashMap<>());
6666
Boolean supports = driverMap.get(pseudoClass);
6767
if (supports == null) {
6868
boolean supported = testPseudoClassNativeSupport(pseudoClass, driver);

src/test/java/integration/io/github/seleniumquery/by/DriverVersionUtilsTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 seleniumQuery authors
2+
* Copyright (c) 2017 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,21 +16,24 @@
1616

1717
package integration.io.github.seleniumquery.by;
1818

19-
import com.gargoylesoftware.htmlunit.BrowserVersion;
20-
import io.github.seleniumquery.utils.DriverVersionUtils;
19+
import static org.hamcrest.Matchers.is;
20+
import static org.junit.Assert.assertThat;
21+
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
22+
23+
import java.util.List;
24+
2125
import org.junit.Before;
2226
import org.junit.Test;
2327
import org.openqa.selenium.WebDriver;
2428
import org.openqa.selenium.WebElement;
2529
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
30+
31+
import com.gargoylesoftware.htmlunit.BrowserVersion;
32+
import io.github.seleniumquery.utils.DriverVersionUtils;
2633
import testinfrastructure.testdouble.PseudoTestDoubleException;
2734
import testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy;
2835
import testinfrastructure.testutils.DriverInTest;
2936

30-
import static org.hamcrest.Matchers.is;
31-
import static org.junit.Assert.assertThat;
32-
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
33-
3437
public class DriverVersionUtilsTest {
3538

3639
@Before
@@ -76,7 +79,7 @@ public void hasNativeSupportForPseudo__should_return_true_if_driver_doesnt_throw
7679
// given
7780
final String supportedPseudo = ":some-supported-pseudo";
7881
class WebDriverThatSupportsSomePseudo extends WebDriverDummy {
79-
@Override public WebElement findElementByCssSelector(String s) { assertThat(s, is("#AAA_SomeIdThatShouldNotExist" + supportedPseudo)); return null; }
82+
@Override public List<WebElement> findElementsByCssSelector(String s) { assertThat(s, is("#AAA_SomeIdThatShouldNotExist" + supportedPseudo)); return null; }
8083
}
8184
DriverVersionUtils driverVersionUtils = new DriverVersionUtils();
8285
WebDriver webDriver = new WebDriverThatSupportsSomePseudo();

0 commit comments

Comments
 (0)