Skip to content

Commit

Permalink
[grid] Java 8 language level fixes, closes #8860
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Nov 10, 2020
1 parent 09db963 commit 203a0fe
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.openqa.selenium.json.Json;

import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashMap;
Expand Down Expand Up @@ -248,7 +250,8 @@ public void updateUserPrefs(File userPrefs) {
prefs.setPreference("browser.startup.page", 1);
}

try (FileWriter writer = new FileWriter(userPrefs, Charset.defaultCharset())) {
try (Writer writer = new OutputStreamWriter(
new FileOutputStream(userPrefs), Charset.defaultCharset())) {
prefs.writeTo(writer);
} catch (IOException e) {
throw new WebDriverException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public String example(Config config) {
Optional<List<String>> allOptions = config.getAll(section, optionName);
if (allOptions.isPresent() && !allOptions.get().isEmpty()) {
if (repeats) {
return allOptions.stream()
return allOptions.get().stream()
.map(value -> quotable ? "\"" + value + "\"" : String.valueOf(value))
.collect(Collectors.joining(", ", "[", "]"));
}
Expand Down
7 changes: 5 additions & 2 deletions java/server/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ public boolean hasCapability(Capabilities caps) {
}

public boolean hasCapacity() {
return slots.stream().anyMatch(slot -> slot.getSession().isEmpty());

return slots.stream().anyMatch(slot -> !slot.getSession().isPresent());
}

public boolean hasCapacity(Capabilities caps) {
return slots.stream().anyMatch(slot -> slot.getSession().isEmpty() && slot.isSupporting(caps));

return slots.stream()
.anyMatch(slot -> !slot.getSession().isPresent() && slot.isSupporting(caps));
}

public NodeId getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private URI getDockerUri() {
}

private boolean isEnabled(HttpClient.Factory clientFactory) {
if (config.getAll(DOCKER_SECTION, "configs").isEmpty()) {
if (!config.getAll(DOCKER_SECTION, "configs").isPresent()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private TimeZone getTimeZone(Capabilities sessionRequestCapabilities) {
private Dimension getScreenResolution(Capabilities sessionRequestCapabilities) {
Optional<Object> screenResolution =
ofNullable(getCapability(sessionRequestCapabilities, "screenResolution"));
if (screenResolution.isEmpty()) {
if (!screenResolution.isPresent()) {
return null;
}
try {
Expand Down

0 comments on commit 203a0fe

Please sign in to comment.