Skip to content

Commit

Permalink
[Java] Add a message showing when there are no drivers on $PATH
Browse files Browse the repository at this point in the history
This changes the Require to handle a unique message which can help
guide users on how to fix the issue that they are hitting.
  • Loading branch information
AutomatedTester committed Oct 2, 2020
1 parent 587106b commit 8750123
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
13 changes: 10 additions & 3 deletions java/client/src/org/openqa/selenium/internal/Require.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,24 @@ public static int nonNegative(String argName, Integer number) {
}
return number;
}

public static int positive(String argName, Integer number) {
public static int positive(String argName, Integer number, String message) {
if (number == null) {
throw new IllegalArgumentException(argName + " must be set");
}
if (number <= 0) {
throw new IllegalArgumentException(argName + " must be greater than 0");
if (message == null) {
throw new IllegalArgumentException(argName + " must be greater than 0");
} else {
throw new IllegalArgumentException(message);
}
}
return number;
}

public static int positive(String argName, Integer number) {
return positive(argName, number, null);
}

public static IntChecker argument(String argName, Integer number) {
return new IntChecker(argName, number);
}
Expand Down
7 changes: 7 additions & 0 deletions java/client/test/org/openqa/selenium/RequireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public void canCheckIntegerArgument() {
assertThat(Require.positive("Timeout", 5)).isEqualTo(5);
}

@Test
public void canCheckIntegersWithMessages() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.positive("Timeout", 0, "Message should only be this"))
.withMessage("Message should only be this");
}

@Test
public void canCheckIntegerArgumentWithCheckerObject() {
assertThatExceptionOfType(IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public NodeStatus(
Secret registrationSecret) {
this.nodeId = Require.nonNull("Node id", nodeId);
this.externalUri = Require.nonNull("URI", externalUri);
this.maxSessionCount = Require.positive("Max session count", maxSessionCount);
this.maxSessionCount = Require.positive("Max session count",
maxSessionCount,
"Make sure that a driver is available on $PATH");
this.slots = ImmutableSet.copyOf(Require.nonNull("Slots", slots));
this.availability = Require.nonNull("Availability", availability);
this.registrationSecret = registrationSecret;
Expand Down

0 comments on commit 8750123

Please sign in to comment.