Skip to content

Commit cca9625

Browse files
committed
use consts and util.objects
1 parent b8af810 commit cca9625

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/DownloadCanceled.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@
1717

1818
package org.openqa.selenium.bidi.browsingcontext;
1919

20+
import static java.util.Objects.requireNonNullElse;
21+
2022
import org.openqa.selenium.json.JsonInput;
2123

2224
public class DownloadCanceled extends NavigationInfo {
2325

2426
private final String status;
2527

28+
private static final String CANCELED = "canceled";
29+
2630
DownloadCanceled(
2731
String browsingContextId, String navigationId, long timestamp, String url, String status) {
2832
super(browsingContextId, navigationId, timestamp, url);
29-
this.status = status != null ? status : "canceled";
33+
this.status = requireNonNullElse(status, CANCELED);
3034
}
3135

3236
public static DownloadCanceled fromJson(JsonInput input) {
3337
String browsingContextId = null;
3438
String navigationId = null;
3539
long timestamp = 0;
3640
String url = null;
37-
String status = "canceled";
41+
String status = CANCELED;
3842

3943
input.beginObject();
4044
while (input.hasNext()) {
@@ -57,8 +61,9 @@ public static DownloadCanceled fromJson(JsonInput input) {
5761

5862
case "status":
5963
status = input.read(String.class);
60-
if (!"canceled".equals(status)) {
61-
throw new IllegalArgumentException("Expected status 'canceled', but got: " + status);
64+
if (!CANCELED.equals(status)) {
65+
throw new IllegalArgumentException(
66+
"Expected status '" + CANCELED + "' , but got: " + status);
6267
}
6368
break;
6469

java/src/org/openqa/selenium/bidi/browsingcontext/DownloadCompleted.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package org.openqa.selenium.bidi.browsingcontext;
1919

20+
import static java.util.Objects.requireNonNullElse;
21+
2022
import org.openqa.selenium.json.JsonInput;
2123

2224
public class DownloadCompleted extends NavigationInfo {
2325

2426
private final String status;
2527
private final String filepath;
2628

29+
private static final String COMPLETE = "complete";
30+
2731
DownloadCompleted(
2832
String browsingContextId,
2933
String navigationId,
@@ -32,7 +36,7 @@ public class DownloadCompleted extends NavigationInfo {
3236
String status,
3337
String filepath) {
3438
super(browsingContextId, navigationId, timestamp, url);
35-
this.status = status != null ? status : "complete";
39+
this.status = requireNonNullElse(status, COMPLETE);
3640
this.filepath = filepath;
3741
}
3842

@@ -41,7 +45,7 @@ public static DownloadCompleted fromJson(JsonInput input) {
4145
String navigationId = null;
4246
long timestamp = 0;
4347
String url = null;
44-
String status = "complete";
48+
String status = COMPLETE;
4549
String filepath = null;
4650

4751
input.beginObject();
@@ -65,8 +69,9 @@ public static DownloadCompleted fromJson(JsonInput input) {
6569

6670
case "status":
6771
status = input.read(String.class);
68-
if (!"complete".equals(status)) {
69-
throw new IllegalArgumentException("Expected status 'complete', but got: " + status);
72+
if (!COMPLETE.equals(status)) {
73+
throw new IllegalArgumentException(
74+
"Expected status '" + COMPLETE + "' , but got: " + status);
7075
}
7176
break;
7277

java/src/org/openqa/selenium/bidi/browsingcontext/DownloadEnded.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
public class DownloadEnded {
2626

27+
private static final String CANCELED = "canceled";
28+
private static final String COMPLETE = "complete";
29+
2730
private final NavigationInfo downloadParams;
2831

2932
public DownloadEnded(NavigationInfo downloadParams) {
@@ -36,13 +39,13 @@ public static DownloadEnded fromJson(JsonInput input) {
3639

3740
try (StringReader reader = new StringReader(new Json().toJson(jsonMap));
3841
JsonInput jsonInput = new Json().newInput(reader)) {
39-
if ("canceled".equals(status)) {
42+
if (CANCELED.equals(status)) {
4043
return new DownloadEnded(DownloadCanceled.fromJson(jsonInput));
41-
} else if ("complete".equals(status)) {
44+
} else if (COMPLETE.equals(status)) {
4245
return new DownloadEnded(DownloadCompleted.fromJson(jsonInput));
4346
} else {
4447
throw new IllegalArgumentException(
45-
"status must be either 'canceled' or 'complete', but got: " + status);
48+
"status must be either '" + CANCELED + "' or '" + COMPLETE + "', but got: " + status);
4649
}
4750
}
4851
}

0 commit comments

Comments
 (0)