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

[java] type casting and numeric improvements #13909

Merged
merged 8 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions java/src/org/openqa/selenium/devtools/CdpClientGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,18 +913,23 @@ public TypeDeclaration<?> toTypeDeclaration() {
fromJson.getBody().get().addStatement(String.format("return new %s(%s);", name, getMapper()));

MethodDeclaration toJson = classDecl.addMethod("toJson").setPublic(true);
if (type.equals("object")) {
toJson.setType("java.util.Map<String, Object>");
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else if (type.equals("number")) {
toJson.setType(Number.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else if (type.equals("integer")) {
toJson.setType(Integer.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else {
toJson.setType(String.class);
toJson.getBody().get().addStatement(String.format("return %s.toString();", propertyName));
switch (type) {
case "object":
toJson.setType("java.util.Map<String, Object>");
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
case "number":
toJson.setType(Number.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
case "integer":
toJson.setType(Integer.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
default:
toJson.setType(String.class);
toJson.getBody().get().addStatement(String.format("return %s.toString();", propertyName));
break;
}

MethodDeclaration toString = classDecl.addMethod("toString").setPublic(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void assertValidFindBy(FindBy findBy) {
throw new IllegalArgumentException(
String.format(
"You must specify at most one location strategy. Number found: %d (%s)",
finders.size(), finders.toString()));
finders.size(), finders));
}
}

Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/support/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public int hashCode() {
result = 31 * result + green;
result = 31 * result + blue;
temp = alpha != +0.0d ? Double.doubleToLongBits(alpha) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + Long.hashCode(temp);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public void testCanMoveOverAndOutOfAnElement() {
inputModule.perform(
windowHandle,
getBuilder(driver)
.moveToElement(redbox, redSize.getWidth() / 1 + 1, redSize.getHeight() / 1 + 1)
diemol marked this conversation as resolved.
Show resolved Hide resolved
.moveToElement(redbox, redSize.getWidth() + 1, redSize.getHeight() + 1)
.getSequences());

wait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 @@ -404,7 +404,7 @@ public void testCanMoveOverAndOutOfAnElement() {
.isEqualTo(RED.getColorValue());

getBuilder(driver)
.moveToElement(redbox, redSize.getWidth() / 1 + 1, redSize.getHeight() / 1 + 1)
.moveToElement(redbox, redSize.getWidth() + 1, redSize.getHeight() + 1)
.perform();

wait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void testCanMoveOverAndOutOfAnElement() {
.isEqualTo(RED.getColorValue());

setDefaultPen(driver)
.moveToElement(redbox, redSize.getWidth() / 1 + 1, redSize.getHeight() / 1 + 1)
.moveToElement(redbox, redSize.getWidth() + 1, redSize.getHeight() + 1)
.perform();

wait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
Expand Down Expand Up @@ -407,8 +407,8 @@ public void setPointerEventProperties() {

Rectangle rect = pointerArea.getRect();

int centerX = (int) Math.floor(rect.width / 2 + rect.getX());
diemol marked this conversation as resolved.
Show resolved Hide resolved
int centerY = (int) Math.floor(rect.height / 2 + rect.getY());
int centerX = rect.width / 2 + rect.getX();
int centerY = rect.height / 2 + rect.getY();
Assertions.assertThat(moveTo.get("button")).isEqualTo("-1");
Assertions.assertThat(moveTo.get("pageX")).isEqualTo("" + centerX);
Assertions.assertThat(moveTo.get("pageY")).isEqualTo("" + centerY);
Expand Down
Loading