Skip to content

Commit

Permalink
use lambda expression in the Fluent Wait example (#1245)
Browse files Browse the repository at this point in the history
When we use the code of the previous example, Sonar Lint says :
Anonymous inner classes containing only one method
should become lambdas (java:S1604)
Before Java 8, the only way to partially support closures in Java
was by using anonymous inner classes. But the syntax
of anonymous classes may seem unwieldy and unclear.
With Java 8, most uses of anonymous inner classes should be replaced
by lambdas to highly increase the readability of the source code.
Body of commit message is a few lines of text, explaining things
in more detail, possibly giving some background about the issue
being fixed, etc.

This example uses a lambda function.

Fixes #1243

[deploy site]
  • Loading branch information
JulienBreton committed Nov 26, 2022
1 parent 3a4bd47 commit aee2417
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
6 changes: 2 additions & 4 deletions website_and_docs/content/documentation/webdriver/waits.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
WebElement foo = wait.until(driver -> {
return driver.findElement(By.id("foo"));
});
{{< /tab >}}
{{< tab header="Python" >}}
Expand Down
6 changes: 2 additions & 4 deletions website_and_docs/content/documentation/webdriver/waits.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
WebElement foo = wait.until(driver -> {
return driver.findElement(By.id("foo"));
});
{{< /tab >}}
{{< tab header="Python" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
WebElement foo = wait.until(driver -> {
return driver.findElement(By.id("foo"));
});
{{< /tab >}}
{{< tab header="Python" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
WebElement foo = wait.until(driver -> {
return driver.findElement(By.id("foo"));
});
{{< /tab >}}
{{< tab header="Python" >}}
Expand Down

0 comments on commit aee2417

Please sign in to comment.