[java]Replace lambdas with method references #14857
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
This pull request includes several refactorings to improve code readability and consistency across multiple files, primarily by replacing lambda expressions with method references and simplifying conditional checks.
Code readability improvements:
java/src/org/openqa/selenium/chromium/ChromiumDriver.java
: Replaced lambda expression with method reference inprotected ChromiumDriver
constructor.java/src/org/openqa/selenium/devtools/SeleniumCdpConnection.java
: Replaced lambda expressions with method references increate
method and simplifiedif
condition to useisEmpty()
instead of!isPresent()
. [1] [2]java/src/org/openqa/selenium/firefox/FirefoxDriver.java
: Replaced lambda expression with method reference inprivate FirefoxDriver
constructor.java/src/org/openqa/selenium/remote/RemoteWebDriver.java
: Replaced lambda expression with method reference inaddCredential
method.Test code simplification:
java/test/org/openqa/selenium/NoSuchShadowRootTest.java
: Simplified exception assertion by replacing lambda expression with method reference ingetNoSuchShadowRoot
test method.java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java
: Simplified exception assertion by replacing lambda expression with method reference inprotocolVersionThrowsConfigException
test method.java/test/org/openqa/selenium/grid/server/BaseServerOptionsTest.java
: Simplified exception assertion by replacing lambda expression with method reference inexternalUriFailsForNonUriStrings
test method.Motivation and Context
While often it could be a matter of taste, method references are more clear and readable compared to lambdas.
Types of changes
Checklist
PR Type
enhancement, tests
Description
isEmpty()
instead of!isPresent()
.Changes walkthrough 📝
ChromiumDriver.java
Use method reference in ChromiumDriver constructor
java/src/org/openqa/selenium/chromium/ChromiumDriver.java
ChromiumDriver
constructor.
SeleniumCdpConnection.java
Refactor SeleniumCdpConnection with method references and simplified
conditions
java/src/org/openqa/selenium/devtools/SeleniumCdpConnection.java
create
method.isEmpty()
.FirefoxDriver.java
Use method reference in FirefoxDriver constructor
java/src/org/openqa/selenium/firefox/FirefoxDriver.java
FirefoxDriver
constructor.
RemoteWebDriver.java
Refactor addCredential method with method reference
java/src/org/openqa/selenium/remote/RemoteWebDriver.java
addCredential
method.
NoSuchShadowRootTest.java
Use method reference in NoSuchShadowRootTest assertion
java/test/org/openqa/selenium/NoSuchShadowRootTest.java
RelayOptionsTest.java
Use method reference in RelayOptionsTest assertion
java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java
BaseServerOptionsTest.java
Use method reference in BaseServerOptionsTest assertion
java/test/org/openqa/selenium/grid/server/BaseServerOptionsTest.java