Skip to content

Commit

Permalink
[java] Reduce redundant toString() calls (#13932)
Browse files Browse the repository at this point in the history
* removed unnecessary semicolons

* removed redundant access modifier for interface member

* removed redundant toString() calls for id in RedisBackedSessionMap

* removed redundant toString() call in DragAndDropTest

* removed redundant toString() calls

* applying formatting
  • Loading branch information
iampopovich committed May 13, 2024
1 parent 2aa0f5a commit e7324ef
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/bidi/network/FetchError.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private FetchError(BaseParameters baseParameters, String errorText) {

public static FetchError fromJsonMap(Map<String, Object> jsonMap) {
try (StringReader baseParameterReader = new StringReader(JSON.toJson(jsonMap));
JsonInput baseParamsInput = JSON.newInput(baseParameterReader); ) {
JsonInput baseParamsInput = JSON.newInput(baseParameterReader)) {
String errorText = JSON.toJson(jsonMap.get("errorText"));
return new FetchError(BaseParameters.fromJson(baseParamsInput), errorText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface EvaluateResult {

String getRealmId();

public enum Type {
enum Type {
SUCCESS("success"),
EXCEPTION("exception");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SerializationOptions {
public enum IncludeShadowTree {
NONE,
OPEN,
ALL;
ALL
}

private Optional<Long> maxDomDepth = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,25 +316,25 @@ public boolean isReady() {
private String uriKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":uri";
return "session:" + id + ":uri";
}

private String capabilitiesKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":capabilities";
return "session:" + id + ":capabilities";
}

private String startKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":start";
return "session:" + id + ":start";
}

private String stereotypeKey(SessionId id) {
Require.nonNull("Session ID", id);

return "session:" + id.toString() + ":stereotype";
return "session:" + id + ":stereotype";
}

private void setCommonSpanAttributes(Span span) {
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/json/JsonInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public Number nextNumber() {
}
return number.longValue();
} catch (NumberFormatException e) {
throw new JsonException("Unable to parse to a number: " + builder.toString() + ". " + input);
throw new JsonException("Unable to parse to a number: " + builder + ". " + input);
}
}

Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/remote/ErrorCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public int getHttpStatusCode(Throwable throwable) {

public WebDriverException decode(Map<String, Object> response) {
if (!(response.get("value") instanceof Map)) {
throw new IllegalArgumentException("Unable to find mapping for " + response.toString());
throw new IllegalArgumentException("Unable to find mapping for " + response);
}

Map<?, ?> value = (Map<?, ?>) response.get("value");
if (!(value.get("error") instanceof String)) {
throw new IllegalArgumentException("Unable to find mapping for " + response.toString());
throw new IllegalArgumentException("Unable to find mapping for " + response);
}

String error = (String) value.get("error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Object invoke(Object object, Method method, Object[] objects) throws Thro
element = locator.findElement();
} catch (NoSuchElementException e) {
if ("toString".equals(method.getName())) {
return "Proxy element for: " + locator.toString();
return "Proxy element for: " + locator;
}
throw e;
}
Expand Down
4 changes: 2 additions & 2 deletions java/test/org/openqa/selenium/ProxySettingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void canConfigureProxyThroughPACFile() throws URISyntaxException, Interru
.join(
"function FindProxyForURL(url, host) {",
" return 'PROXY " + getHostAndPort(helloServer) + "';",
"}")); ) {
"}"))) {

Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://" + getHostAndPort(pacFileServer) + "/proxy.pac");
Expand Down Expand Up @@ -132,7 +132,7 @@ public void canUsePACThatOnlyProxiesCertainHosts()
" return 'PROXY " + getHostAndPort(goodbyeServer) + "';",
" }",
" return 'DIRECT';",
"}")); ) {
"}"))) {

Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://" + getHostAndPort(pacFileServer) + "/proxy.pac");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void sleep(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted: " + e.toString());
throw new RuntimeException("Interrupted: " + e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static String getTestFilePath(Path baseDir, Path testFile) {
testFile
.toAbsolutePath()
.toString()
.replace(baseDir.toAbsolutePath().toString() + File.separator, "")
.replace(baseDir.toAbsolutePath() + File.separator, "")
.replace(File.separator, "/");
if (path.endsWith(".js")) {
path = "common/generated/" + path;
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void shouldBeAbleToConvertASelenium3CommandToASelenium2Command() {
// In selenium 2, the sessionId is an object. In selenium 3, it's a straight string.
String raw =
"{\"sessionId\": \""
+ expectedId.toString()
+ expectedId
+ "\", "
+ "\"name\": \"some command\","
+ "\"parameters\": {}}";
Expand Down

0 comments on commit e7324ef

Please sign in to comment.