Skip to content

Commit

Permalink
[java]Replace lambdas with method references (SeleniumHQ#14857)
Browse files Browse the repository at this point in the history
  • Loading branch information
iampopovich authored and sandeepsuryaprasad committed Dec 7, 2024
1 parent 08db537 commit 356178a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected ChromiumDriver(

try {
try {
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
} catch (Exception e) {
try {
client.ifPresent(HttpClient::close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Optional<Connection> create(
client = reportedUri.map(uri -> CdpEndpointFinder.getHttpClient(clientFactory, uri));

try {
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
} catch (Exception e) {
try {
client.ifPresent(HttpClient::close);
Expand All @@ -87,7 +87,7 @@ public static Optional<Connection> create(
throw e;
}

if (!cdpUri.isPresent()) {
if (cdpUri.isEmpty()) {
try {
client.ifPresent(HttpClient::close);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private FirefoxDriver(
Optional<URI> cdpUri;

try {
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
} catch (Exception e) {
try {
client.ifPresent(HttpClient::close);
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public void addCredential(Credential credential) {
Stream.concat(
credential.toMap().entrySet().stream(),
Stream.of(Map.entry("authenticatorId", id)))
.collect(Collectors.toUnmodifiableMap((e) -> e.getKey(), (e) -> e.getValue())));
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/NoSuchShadowRootTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public void getNoSuchShadowRoot() {
driver.get(pages.shadowRootPage);
WebElement nonExistentShadowRootElement = driver.findElement(By.id("noShadowRoot"));
assertThatExceptionOfType(NoSuchShadowRootException.class)
.isThrownBy(() -> nonExistentShadowRootElement.getShadowRoot());
.isThrownBy(nonExistentShadowRootElement::getShadowRoot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ void protocolVersionThrowsConfigException() {
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));
RelayOptions relayOptions = new RelayOptions(config);
assertThatExceptionOfType(ConfigException.class)
.isThrownBy(
() -> {
relayOptions.getServiceProtocolVersion();
})
.isThrownBy(relayOptions::getServiceProtocolVersion)
.withMessageContaining("Unsupported protocol version provided: HTTP/0.9");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ void externalUriFailsForNonUriStrings() {
BaseServerOptions options =
new BaseServerOptions(new MapConfig(Map.of("server", Map.of("external-url", "not a URL"))));

Exception exception =
assertThrows(
RuntimeException.class,
() -> {
options.getExternalUri();
});
Exception exception = assertThrows(RuntimeException.class, options::getExternalUri);

assertThat(exception.getMessage())
.as("External URI must be parseable as URI.")
Expand Down

0 comments on commit 356178a

Please sign in to comment.