Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Espresso options #1563

Merged
merged 5 commits into from Oct 29, 2021

Conversation

mykola-mokhnach
Copy link
Contributor

Change list

Added a separate Option class to represent Espresso driver caps and updated the related tests.

Types of changes

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Comment on lines 65 to 67
return options == null
? Optional.empty()
: Optional.ofNullable((R) options.getOrDefault(name, null));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return options == null
? Optional.empty()
: Optional.ofNullable((R) options.getOrDefault(name, null));
return Optional.ofNullable(options).map(opts -> (R) opts.getOrDefault(name, null));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

public Map<String, Object> toMap() {
return options == null ? Collections.emptyMap() : options;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return options == null ? Collections.emptyMap() : options;
return Optional.ofNullable(options).orElseGet(Collections::emptyMap);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Comment on lines +54 to +58
if (value instanceof Number) {
toolsVersions.addProperty(name, (Number) value);
} else {
toolsVersions.addProperty(name, String.valueOf(value));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (value instanceof Number) {
toolsVersions.addProperty(name, (Number) value);
} else {
toolsVersions.addProperty(name, String.valueOf(value));
}
toolsVersions.addProperty(name, value instanceof Number ? (Number) value : String.valueOf(value));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried. Java compiler does not like that

}

public JsonObject toJson() {
return json == null ? new JsonObject() : json;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return json == null ? new JsonObject() : json;
return Optional.ofNullable(json).orElseGet(JsonObject::new);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous option was shorter, but changed anyway

Comment on lines 265 to 272
public Optional<Map<String, Integer>> getEi() {
Optional<Map<String, Object>> value = getOptionValue("ei");
return value.map((v) -> v.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey, (entry) -> Integer.parseInt(String.valueOf(entry.getValue())))
)
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Optional<Map<String, Integer>> getEi() {
Optional<Map<String, Object>> value = getOptionValue("ei");
return value.map((v) -> v.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey, (entry) -> Integer.parseInt(String.valueOf(entry.getValue())))
)
);
}
public Optional<Map<String, Integer>> getEi() {
Optional<Map<String, Object>> value = getOptionValue("ei");
return value.map((v) -> convertMapValues(v, Integer::parseInt));
}
private <T> Map<String, T> convertMapValues(Map<String, Object> map, Function<String, T> converter) {
return map.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, (entry) -> converter.apply(String.valueOf(entry.getValue()))));
}

and then convertMapValues can be reused in the methods converting to Long, Float

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@mykola-mokhnach mykola-mokhnach merged commit b6cab92 into appium:master Oct 29, 2021
@mykola-mokhnach mykola-mokhnach deleted the espresso_opts branch October 29, 2021 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants