Skip to content

Commit

Permalink
Remove unneeded 'else' (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour authored and lukeis committed May 21, 2016
1 parent bdabcc0 commit c9e6405
Show file tree
Hide file tree
Showing 45 changed files with 179 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ private String simulateStringDotFormatMethod(String message, Object[] args) {
}
}
throw new RuntimeException("String.format(..) can't be that hard to call");
} else {
String msg = "";
msg = message;
for (int i = 0; i < args.length; i++) {
msg = msg + " " + args[i];
}
return msg;

}

String msg = "";
msg = message;
for (int i = 0; i < args.length; i++) {
msg = msg + " " + args[i];
}
return msg;
}

// drop these for var-args in another year.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public Text(String expectedText, String locator) {
public boolean isTrue(ConditionRunner.Context context) {
if (null == locator) {
return context.getSelenium().isTextPresent(expectedText);
} else {
return context.getSelenium().getText(locator).equalsIgnoreCase(expectedText);
}
return context.getSelenium().getText(locator).equalsIgnoreCase(expectedText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ public void start(Object o) {
if (driver != null) {
if (maker != null) {
throw new SeleniumException("You may not start more than one session at a time");
} else {
// The command processor was instantiated with an already started driver
return;
}
// The command processor was instantiated with an already started driver
return;
}

driver = maker.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ protected String handleSeleneseCommand(WebDriver driver, String locator, String
if (driver instanceof TakesScreenshot) {
TakesScreenshot tsDriver = (TakesScreenshot) driver;
return tsDriver.getScreenshotAs(OutputType.BASE64);
} else {
throw new UnsupportedOperationException("WebDriver does not implement TakeScreenshot");
}
throw new UnsupportedOperationException("WebDriver does not implement TakeScreenshot");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ protected String handleSeleneseCommand(WebDriver driver, String locator, String
{
if (element.getAttribute("checked") == null) {
return "off";
} else {
return "on";
}
return "on";
}

return element.getAttribute("value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ private static final CommandExecutor createCommandExecutor(Capabilities desiredC
Object marionette = desiredCapabilities.getCapability(MARIONETTE);
if (marionette instanceof Boolean && !(Boolean) marionette) {
return new LazyCommandExecutor(binary, profile);
} else {
GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
builder.usingPort(0);
return new DriverCommandExecutor(builder.build());
}
GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
builder.usingPort(0);
return new DriverCommandExecutor(builder.build());
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions java/client/src/org/openqa/selenium/firefox/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ public void writeTo(Writer writer) throws IOException {
private String valueAsPreference(Object value) {
if (value instanceof String) {
return "\"" + escapeValueAsPreference((String) value) + "\"";
} else {
return escapeValueAsPreference(String.valueOf(value));
}

return escapeValueAsPreference(String.valueOf(value));
}

private String escapeValueAsPreference(String value) {
Expand Down
3 changes: 1 addition & 2 deletions java/client/src/org/openqa/selenium/lift/Finders.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ public Collection<WebElement> findFrom(WebDriver context) {
Iterator<WebElement> iter = collection.iterator();
iter.hasNext();
return Collections.singletonList(iter.next());
} else {
return collection;
}
return collection;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ public Collection<S> findFrom(T context) {

if (matchers.isEmpty()) {
return found;
} else {
return allMatching(matchers, found);
}
return allMatching(matchers, found);
}

public Finder<S, T> with(Matcher<S> matcher) {
Expand Down
3 changes: 1 addition & 2 deletions java/client/src/org/openqa/selenium/os/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ private static int waitForProcessDeath(Process p, long timeout) {
public static int killProcess(Process process) {
if (thisIsWindows()) {
return killWinProcess(process);
} else {
return killUnixProcess(process);
}
return killUnixProcess(process);
}

private static int killUnixProcess(Process process) {
Expand Down
7 changes: 3 additions & 4 deletions java/client/src/org/openqa/selenium/remote/Augmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ protected RemoteWebDriver extractRemoteWebDriver(WebDriver driver) {
"org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB")) {
return (RemoteWebDriver) driver;

} else {
logger.warning("Augmenter should be applied to the instances of @Augmentable classes " +
"or previously augmented instances only");
return null;
}
logger.warning("Augmenter should be applied to the instances of @Augmentable classes " +
"or previously augmented instances only");
return null;
}

private void copyFields(Class<?> clazz, Object source, Object target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ private JsonElement convertObject(Object toConvert, int maxDepth) throws Excepti
Object res = toJson.invoke(toConvert);
if (res instanceof JsonElement) {
return (JsonElement) res;
} else {
try {
return new JsonParser().parse((String) res);
} catch (JsonParseException e) {
return new JsonPrimitive((String) res);
}
}
try {
return new JsonParser().parse((String) res);
} catch (JsonParseException e) {
return new JsonPrimitive((String) res);
}
} catch (IllegalArgumentException e) {
throw new WebDriverException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public static String getSessionId(String uri) {
int nextSlash = uri.indexOf("/", sessionIndex);
if (nextSlash != -1) {
return uri.substring(sessionIndex, nextSlash);
} else {
return uri.substring(sessionIndex);
}

return uri.substring(sessionIndex);
}
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions java/client/src/org/openqa/selenium/remote/JdkAugmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ public Object handleInvocation(Object proxy, Method method, Object[] args) throw
System.out.println("Method: " + method + "all handlers: " + handlers.keySet());
if (null == handler) {
return method.invoke(realInstance, args);
} else {
return handler.invoke(new RemoteExecuteMethod(driver), proxy, method, args);
}
return handler.invoke(new RemoteExecuteMethod(driver), proxy, method, args);
} catch (InvocationTargetException i) {
throw i.getCause();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ private <T> T convert(Class<T> clazz, Object source, int depth) {
? new JsonParser().parse((String) source).getAsJsonObject() : (JsonElement) source;
if (json.isJsonPrimitive()) {
return (T) new SessionId(json.getAsString());
} else {
return (T) new SessionId(json.getAsJsonObject().get("value").getAsString());
}
return (T) new SessionId(json.getAsJsonObject().get("value").getAsString());
}

if (Capabilities.class.isAssignableFrom(clazz)) {
Expand Down Expand Up @@ -248,9 +247,8 @@ private Object convertJsonPrimitive(JsonPrimitive json) {
} else if (json.isNumber()) {
if (json.getAsLong() == json.getAsDouble()) {
return json.getAsLong();
} else {
return json.getAsDouble();
}
return json.getAsDouble();
} else if (json.isString()) {
return json.getAsString();
} else {
Expand All @@ -263,19 +261,17 @@ private Enum convertEnum(Class clazz, Object text) {
if (clazz.isEnum()) {
if (text instanceof JsonElement) {
return Enum.valueOf(clazz, (String) convertJsonPrimitive((JsonElement) text));
} else {
return Enum.valueOf(clazz, String.valueOf(text));
}
return Enum.valueOf(clazz, String.valueOf(text));
}

Class[] allClasses = clazz.getClasses();
for (Class current : allClasses) {
if (current.isEnum()) {
if (text instanceof JsonElement) {
return Enum.valueOf(current, (String) convertJsonPrimitive((JsonElement) text));
} else {
return Enum.valueOf(current, String.valueOf(text));
}
return Enum.valueOf(current, String.valueOf(text));
}
}

Expand Down
63 changes: 26 additions & 37 deletions java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,8 @@ public String getCurrentUrl() {
Response response = execute(DriverCommand.GET_CURRENT_URL);
if (response == null || response.getValue() == null) {
throw new WebDriverException("Remote browser did not respond to getCurrentUrl");
} else {
return response.getValue().toString();
}
return response.getValue().toString();
}

public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {
Expand Down Expand Up @@ -426,17 +425,15 @@ static String cssEscape(String using) {
public WebElement findElementById(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElement("id", using);
} else {
return findElementByCssSelector("#" + cssEscape(using));
}
return findElementByCssSelector("#" + cssEscape(using));
}

public List<WebElement> findElementsById(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElements("id", using);
} else {
return findElementsByCssSelector("#" + cssEscape(using));
}
return findElementsByCssSelector("#" + cssEscape(using));
}

public WebElement findElementByLinkText(String using) {
Expand All @@ -458,49 +455,43 @@ public List<WebElement> findElementsByPartialLinkText(String using) {
public WebElement findElementByTagName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElement("tag name", using);
} else {
return findElementByCssSelector(using);
}
return findElementByCssSelector(using);
}

public List<WebElement> findElementsByTagName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElements("tag name", using);
} else {
return findElementsByCssSelector(using);
}
return findElementsByCssSelector(using);
}

public WebElement findElementByName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElement("name", using);
} else {
return findElementByCssSelector("*[name='" + using + "']");
}
return findElementByCssSelector("*[name='" + using + "']");
}

public List<WebElement> findElementsByName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElements("name", using);
} else {
return findElementsByCssSelector("*[name='" + using + "']");
}
return findElementsByCssSelector("*[name='" + using + "']");
}

public WebElement findElementByClassName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElement("class name", using);
} else {
return findElementByCssSelector("." + cssEscape(using));
}
return findElementByCssSelector("." + cssEscape(using));
}

public List<WebElement> findElementsByClassName(String using) {
if (getW3CStandardComplianceLevel() == 0) {
return findElements("class name", using);
} else {
return findElementsByCssSelector("." + cssEscape(using));
}
return findElementsByCssSelector("." + cssEscape(using));
}

public WebElement findElementByCssSelector(String using) {
Expand All @@ -524,12 +515,11 @@ public List<WebElement> findElementsByXPath(String using) {
public String getPageSource() {
if (getW3CStandardComplianceLevel() == 0) {
return (String) execute(DriverCommand.GET_PAGE_SOURCE).getValue();
} else {
String script = "var source = document.documentElement.outerHTML; \n"
+ "if (!source) { source = new XMLSerializer().serializeToString(document); }\n"
+ "return source;";
return (String) executeScript(script);
}
String script = "var source = document.documentElement.outerHTML; \n"
+ "if (!source) { source = new XMLSerializer().serializeToString(document); }\n"
+ "return source;";
return (String) executeScript(script);
}

public void close() {
Expand Down Expand Up @@ -1029,22 +1019,21 @@ public WebDriver window(String windowHandleOrName) {
if (getW3CStandardComplianceLevel() == 0) {
execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("name", windowHandleOrName));
return RemoteWebDriver.this;
} else {
try {
execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("handle", windowHandleOrName));
return RemoteWebDriver.this;
} catch (NoSuchWindowException nsw) {
// simulate search by name
String original = getWindowHandle();
for (String handle : getWindowHandles()) {
switchTo().window(handle);
if (windowHandleOrName.equals(executeScript("return window.name"))) {
return RemoteWebDriver.this; // found by name
}
}
try {
execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("handle", windowHandleOrName));
return RemoteWebDriver.this;
} catch (NoSuchWindowException nsw) {
// simulate search by name
String original = getWindowHandle();
for (String handle : getWindowHandles()) {
switchTo().window(handle);
if (windowHandleOrName.equals(executeScript("return window.name"))) {
return RemoteWebDriver.this; // found by name
}
switchTo().window(original);
throw nsw;
}
switchTo().window(original);
throw nsw;
}
}

Expand Down
Loading

0 comments on commit c9e6405

Please sign in to comment.