Skip to content

Commit e013f70

Browse files
Formatted code to fix the spacing issue
removed redundant validation of StringUtils#isBlank() on the basepath replaced Assert#fail with Assert#assertThrows for the test cases
1 parent 69d2a41 commit e013f70

File tree

3 files changed

+29
-74
lines changed

3 files changed

+29
-74
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,15 @@
2020
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
2121

2222
import com.google.common.collect.ImmutableList;
23-
2423
import com.google.gson.Gson;
2524
import com.google.gson.GsonBuilder;
2625
import io.appium.java_client.remote.AndroidMobileCapabilityType;
2726
import io.appium.java_client.remote.MobileBrowserType;
2827
import io.appium.java_client.remote.MobileCapabilityType;
2928
import io.appium.java_client.service.local.flags.GeneralServerFlag;
3029
import io.appium.java_client.service.local.flags.ServerArgument;
31-
32-
import lombok.SneakyThrows;
33-
import org.apache.commons.io.IOUtils;
34-
import org.apache.commons.lang3.StringUtils;
35-
import org.apache.commons.lang3.SystemUtils;
36-
import org.apache.commons.validator.routines.InetAddressValidator;
37-
import org.openqa.selenium.Capabilities;
38-
import org.openqa.selenium.Platform;
39-
import org.openqa.selenium.os.ExecutableFinder;
40-
import org.openqa.selenium.remote.Browser;
41-
import org.openqa.selenium.remote.service.DriverService;
42-
43-
import javax.annotation.Nullable;
4430
import java.io.File;
4531
import java.io.IOException;
46-
4732
import java.nio.charset.StandardCharsets;
4833
import java.nio.file.Path;
4934
import java.nio.file.Paths;
@@ -55,6 +40,17 @@
5540
import java.util.Map;
5641
import java.util.Set;
5742
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;
5854

5955
public final class AppiumServiceBuilder
6056
extends DriverService.Builder<AppiumDriverLocalService, AppiumServiceBuilder> {
@@ -219,7 +215,7 @@ public AppiumServiceBuilder withArgument(ServerArgument argument, String value)
219215
withLogFile(new File(value));
220216
break;
221217
case "--base-path":
222-
serverArguments.put(argName,sanitizeBasePath(value));
218+
serverArguments.put(argName, sanitizeBasePath(value));
223219
break;
224220
default:
225221
serverArguments.put(argName, value);
@@ -230,8 +226,8 @@ public AppiumServiceBuilder withArgument(ServerArgument argument, String value)
230226

231227
private static String sanitizeBasePath(String basePath) {
232228
basePath = checkNotNull(basePath).trim();
233-
if (StringUtils.isBlank(basePath) || basePath.isEmpty()) {
234-
throw new InvalidBasePathException(
229+
if (basePath.isEmpty()) {
230+
throw new IllegalArgumentException(
235231
"Given base path is not valid - blank or empty values are not allowed for base path");
236232
}
237233
return basePath.endsWith("/") ? basePath : basePath + "/";

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import static io.appium.java_client.service.local.AppiumServiceBuilder.APPIUM_PATH;
77
import static io.appium.java_client.service.local.AppiumServiceBuilder.BROADCAST_IP_ADDRESS;
88
import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
9+
import static io.appium.java_client.service.local.flags.GeneralServerFlag.BASEPATH;
910
import static io.appium.java_client.service.local.flags.GeneralServerFlag.CALLBACK_ADDRESS;
1011
import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE;
11-
import static io.appium.java_client.service.local.flags.GeneralServerFlag.BASEPATH;
1212
import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver;
1313
import static java.lang.System.getProperty;
1414
import static java.lang.System.setProperty;
@@ -21,23 +21,22 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
2323
import static org.junit.Assert.assertThat;
24+
import static org.junit.Assert.assertThrows;
2425
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
2626

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-
3430
import java.io.File;
3531
import java.io.FileOutputStream;
3632
import java.io.OutputStream;
3733
import java.nio.file.Path;
3834
import java.time.Duration;
3935
import java.util.ArrayList;
4036
import java.util.List;
37+
import org.junit.After;
38+
import org.junit.BeforeClass;
39+
import org.junit.Test;
4140

4241
@SuppressWarnings("ResultOfMethodCallIgnored")
4342
public class ServerBuilderTest {
@@ -327,7 +326,7 @@ public void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams()
327326
service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build();
328327
service.start();
329328
assertTrue(service.isRunning());
330-
assertEquals(baseUrl + basePath + "/",service.getUrl().toString());
329+
assertEquals(baseUrl + basePath + "/", service.getUrl().toString());
331330
}
332331

333332
@Test
@@ -337,38 +336,29 @@ public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() {
337336
service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build();
338337
service.start();
339338
assertTrue(service.isRunning());
340-
assertEquals(baseUrl + basePath.substring(1) ,service.getUrl().toString());
339+
assertEquals(baseUrl + basePath.substring(1), service.getUrl().toString());
341340
}
342341

343342
@Test
344343
public void checkAbilityToValidateBasePathForEmptyBasePath() {
345-
try {
344+
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
346345
service = new AppiumServiceBuilder().withArgument(BASEPATH, "").build();
347-
fail("Base path was not validated for Blank or Empty string");
348-
} catch (Exception e) {
349-
assertEquals(InvalidBasePathException.class, e.getClass());
350-
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, e.getMessage());
351-
}
346+
});
347+
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, exception.getMessage());
352348
}
353349

354350
@Test
355351
public void checkAbilityToValidateBasePathForBlankBasePath() {
356-
try {
352+
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
357353
service = new AppiumServiceBuilder().withArgument(BASEPATH, " ").build();
358-
fail("Base path was not validated for Blank or Empty string");
359-
} catch (Exception e) {
360-
assertEquals(InvalidBasePathException.class, e.getClass());
361-
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, e.getMessage());
362-
}
354+
});
355+
assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, exception.getMessage());
363356
}
364357

365358
@Test
366359
public void checkAbilityToValidateBasePathForNullBasePath() {
367-
try {
360+
assertThrows(NullPointerException.class, () -> {
368361
service = new AppiumServiceBuilder().withArgument(BASEPATH, null).build();
369-
fail("Base path was not validated for a null value");
370-
} catch (Exception e) {
371-
assertEquals(NullPointerException.class, e.getClass());
372-
}
362+
});
373363
}
374364
}

0 commit comments

Comments
 (0)