Skip to content

Commit 7a93ff7

Browse files
authored
[java]Replace lambdas with method references (#14857)
1 parent c286473 commit 7a93ff7

File tree

7 files changed

+8
-16
lines changed

7 files changed

+8
-16
lines changed

Diff for: java/src/org/openqa/selenium/chromium/ChromiumDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected ChromiumDriver(
147147

148148
try {
149149
try {
150-
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
150+
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
151151
} catch (Exception e) {
152152
try {
153153
client.ifPresent(HttpClient::close);

Diff for: java/src/org/openqa/selenium/devtools/SeleniumCdpConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static Optional<Connection> create(
7777
client = reportedUri.map(uri -> CdpEndpointFinder.getHttpClient(clientFactory, uri));
7878

7979
try {
80-
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
80+
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
8181
} catch (Exception e) {
8282
try {
8383
client.ifPresent(HttpClient::close);
@@ -87,7 +87,7 @@ public static Optional<Connection> create(
8787
throw e;
8888
}
8989

90-
if (!cdpUri.isPresent()) {
90+
if (cdpUri.isEmpty()) {
9191
try {
9292
client.ifPresent(HttpClient::close);
9393
} catch (Exception e) {

Diff for: java/src/org/openqa/selenium/firefox/FirefoxDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private FirefoxDriver(
176176
Optional<URI> cdpUri;
177177

178178
try {
179-
cdpUri = client.flatMap(httpClient -> CdpEndpointFinder.getCdpEndPoint(httpClient));
179+
cdpUri = client.flatMap(CdpEndpointFinder::getCdpEndPoint);
180180
} catch (Exception e) {
181181
try {
182182
client.ifPresent(HttpClient::close);

Diff for: java/src/org/openqa/selenium/remote/RemoteWebDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ public void addCredential(Credential credential) {
12471247
Stream.concat(
12481248
credential.toMap().entrySet().stream(),
12491249
Stream.of(Map.entry("authenticatorId", id)))
1250-
.collect(Collectors.toUnmodifiableMap((e) -> e.getKey(), (e) -> e.getValue())));
1250+
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)));
12511251
}
12521252

12531253
@Override

Diff for: java/test/org/openqa/selenium/NoSuchShadowRootTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public void getNoSuchShadowRoot() {
3434
driver.get(pages.shadowRootPage);
3535
WebElement nonExistentShadowRootElement = driver.findElement(By.id("noShadowRoot"));
3636
assertThatExceptionOfType(NoSuchShadowRootException.class)
37-
.isThrownBy(() -> nonExistentShadowRootElement.getShadowRoot());
37+
.isThrownBy(nonExistentShadowRootElement::getShadowRoot);
3838
}
3939
}

Diff for: java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ void protocolVersionThrowsConfigException() {
137137
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));
138138
RelayOptions relayOptions = new RelayOptions(config);
139139
assertThatExceptionOfType(ConfigException.class)
140-
.isThrownBy(
141-
() -> {
142-
relayOptions.getServiceProtocolVersion();
143-
})
140+
.isThrownBy(relayOptions::getServiceProtocolVersion)
144141
.withMessageContaining("Unsupported protocol version provided: HTTP/0.9");
145142
}
146143

Diff for: java/test/org/openqa/selenium/grid/server/BaseServerOptionsTest.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ void externalUriFailsForNonUriStrings() {
5252
BaseServerOptions options =
5353
new BaseServerOptions(new MapConfig(Map.of("server", Map.of("external-url", "not a URL"))));
5454

55-
Exception exception =
56-
assertThrows(
57-
RuntimeException.class,
58-
() -> {
59-
options.getExternalUri();
60-
});
55+
Exception exception = assertThrows(RuntimeException.class, options::getExternalUri);
6156

6257
assertThat(exception.getMessage())
6358
.as("External URI must be parseable as URI.")

0 commit comments

Comments
 (0)