Skip to content

Commit 5b76ab9

Browse files
Import order correction
Removed validations of exception message in the tests Accepted the change from val to use checkArgument method from Preconditions class
1 parent 3061c99 commit 5b76ab9

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,35 @@
1616

1717
package io.appium.java_client.service.local;
1818

19+
import static com.google.common.base.Preconditions.checkArgument;
1920
import static com.google.common.base.Preconditions.checkNotNull;
2021
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
2122

2223
import com.google.common.collect.ImmutableList;
24+
2325
import com.google.gson.Gson;
2426
import com.google.gson.GsonBuilder;
2527
import io.appium.java_client.remote.AndroidMobileCapabilityType;
2628
import io.appium.java_client.remote.MobileBrowserType;
2729
import io.appium.java_client.remote.MobileCapabilityType;
2830
import io.appium.java_client.service.local.flags.GeneralServerFlag;
2931
import io.appium.java_client.service.local.flags.ServerArgument;
32+
33+
import lombok.SneakyThrows;
34+
import org.apache.commons.io.IOUtils;
35+
import org.apache.commons.lang3.StringUtils;
36+
import org.apache.commons.lang3.SystemUtils;
37+
import org.apache.commons.validator.routines.InetAddressValidator;
38+
import org.openqa.selenium.Capabilities;
39+
import org.openqa.selenium.Platform;
40+
import org.openqa.selenium.os.ExecutableFinder;
41+
import org.openqa.selenium.remote.Browser;
42+
import org.openqa.selenium.remote.service.DriverService;
43+
44+
import javax.annotation.Nullable;
3045
import java.io.File;
3146
import java.io.IOException;
47+
3248
import java.nio.charset.StandardCharsets;
3349
import java.nio.file.Path;
3450
import java.nio.file.Paths;
@@ -40,17 +56,6 @@
4056
import java.util.Map;
4157
import java.util.Set;
4258
import java.util.function.Function;
43-
import javax.annotation.Nullable;
44-
import lombok.SneakyThrows;
45-
import org.apache.commons.io.IOUtils;
46-
import org.apache.commons.lang3.StringUtils;
47-
import org.apache.commons.lang3.SystemUtils;
48-
import org.apache.commons.validator.routines.InetAddressValidator;
49-
import org.openqa.selenium.Capabilities;
50-
import org.openqa.selenium.Platform;
51-
import org.openqa.selenium.os.ExecutableFinder;
52-
import org.openqa.selenium.remote.Browser;
53-
import org.openqa.selenium.remote.service.DriverService;
5459

5560
public final class AppiumServiceBuilder
5661
extends DriverService.Builder<AppiumDriverLocalService, AppiumServiceBuilder> {
@@ -226,7 +231,8 @@ public AppiumServiceBuilder withArgument(ServerArgument argument, String value)
226231

227232
private static String sanitizeBasePath(String basePath) {
228233
basePath = checkNotNull(basePath).trim();
229-
Preconditions.checkArgument(!basePath.isEmpty(), "Given base path is not valid - blank or empty values are not allowed for base path");
234+
checkArgument(!basePath.isEmpty(),
235+
"Given base path is not valid - blank or empty values are not allowed for base path");
230236
return basePath.endsWith("/") ? basePath : basePath + "/";
231237
}
232238

src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
import com.google.common.collect.ImmutableMap;
2828
import io.appium.java_client.android.options.UiAutomator2Options;
2929
import io.github.bonigarcia.wdm.WebDriverManager;
30+
import org.junit.After;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
3034
import java.io.File;
3135
import java.io.FileOutputStream;
3236
import java.io.OutputStream;
3337
import java.nio.file.Path;
3438
import java.time.Duration;
3539
import java.util.ArrayList;
3640
import java.util.List;
37-
import org.junit.After;
38-
import org.junit.BeforeClass;
39-
import org.junit.Test;
4041

4142
@SuppressWarnings("ResultOfMethodCallIgnored")
4243
public class ServerBuilderTest {
@@ -57,9 +58,6 @@ public class ServerBuilderTest {
5758
private static final Path PATH_T0_TEST_MAIN_JS = ROOT_TEST_PATH
5859
.resolve("service").resolve("local").resolve("main.js");
5960

60-
private static final String INVALID_BASE_PATH_ERROR_MESSAGE =
61-
"Given base path is not valid - blank or empty values are not allowed for base path";
62-
6361
private static String testIP;
6462
private AppiumDriverLocalService service;
6563
private File testLogFile;
@@ -341,24 +339,22 @@ public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() {
341339

342340
@Test
343341
public void checkAbilityToValidateBasePathForEmptyBasePath() {
344-
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
345-
service = new AppiumServiceBuilder().withArgument(BASEPATH, "").build();
342+
assertThrows(IllegalArgumentException.class, () -> {
343+
new AppiumServiceBuilder().withArgument(BASEPATH, "").build();
346344
});
347-
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, exception.getMessage());
348345
}
349346

350347
@Test
351348
public void checkAbilityToValidateBasePathForBlankBasePath() {
352-
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
353-
service = new AppiumServiceBuilder().withArgument(BASEPATH, " ").build();
349+
assertThrows(IllegalArgumentException.class, () -> {
350+
new AppiumServiceBuilder().withArgument(BASEPATH, " ").build();
354351
});
355-
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, exception.getMessage());
356352
}
357353

358354
@Test
359355
public void checkAbilityToValidateBasePathForNullBasePath() {
360356
assertThrows(NullPointerException.class, () -> {
361-
service = new AppiumServiceBuilder().withArgument(BASEPATH, null).build();
357+
new AppiumServiceBuilder().withArgument(BASEPATH, null).build();
362358
});
363359
}
364360
}

0 commit comments

Comments
 (0)