Skip to content

Commit d2faec2

Browse files
committed
code style and cleanup
1 parent 115a62a commit d2faec2

7 files changed

Lines changed: 69 additions & 86 deletions

File tree

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void webWindowClosed(final WebWindowEvent event) {
295295
}
296296

297297
// Check if the event window refers to us or one of our parent windows
298-
// setup the currentWindow appropriately if necessary
298+
// set up the currentWindow appropriately if necessary
299299
WebWindow ourCurrentWindow = currentWindow_.getWebWindow();
300300
final WebWindow ourCurrentTopWindow = currentWindow_.getWebWindow().getTopWindow();
301301
do {
@@ -430,7 +430,7 @@ public void click(final DomElement element, final boolean directClick) {
430430
}
431431

432432
/**
433-
* Performs a double-click on the specified element.
433+
* Performs a double click on the specified element.
434434
* <p>
435435
* This simulates a WebDriver double-click gesture by issuing two click
436436
* sequences in rapid succession and dispatching a {@code dblclick} event.
@@ -760,7 +760,7 @@ protected void get(final URL fullUrl) {
760760
getAlert().setAutoAccept(false);
761761
try {
762762
// we can't use webClient.getPage(url) here because selenium has a different
763-
// idea of the current window and we like to load into to selenium current one
763+
// idea of the current window, and we like to load into to selenium current one
764764
final BrowserVersion browser = getBrowserVersion();
765765
final WebRequest request = new WebRequest(fullUrl, browser.getHtmlAcceptHeader(),
766766
browser.getAcceptEncodingHeader());
@@ -779,10 +779,7 @@ protected void get(final URL fullUrl) {
779779
catch (final SocketTimeoutException e) {
780780
throw new TimeoutException(e);
781781
}
782-
catch (final NoSuchSessionException e) {
783-
throw e;
784-
}
785-
catch (final NoSuchWindowException e) {
782+
catch (final NoSuchSessionException | NoSuchWindowException e) {
786783
throw e;
787784
}
788785
catch (final SSLHandshakeException e) {
@@ -1851,7 +1848,7 @@ private void verifyDomain(final Cookie cookie, String expectedDomain) {
18511848
return;
18521849
}
18531850

1854-
if ("".equals(domain)) {
1851+
if (domain.length() == 0) {
18551852
throw new InvalidCookieDomainException(
18561853
"Domain must not be an empty string. Consider using null instead");
18571854
}

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitMouse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void doubleClick(final Coordinates elementCoordinates) {
217217
}
218218

219219
/**
220-
* Performs a double-click on the specified {@link DomElement}, including
220+
* Performs a double click on the specified {@link DomElement}, including
221221
* hover-out behavior if necessary and dispatch of modifier-key state.
222222
*
223223
* @param element the element to be double-clicked; must not be {@code null}

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.ArrayList;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.concurrent.Callable;
2928

3029
import org.apache.commons.lang3.StringUtils;
3130
import org.htmlunit.ScriptResult;
@@ -288,12 +287,7 @@ else if (!element_.getAttribute("contenteditable").equals(ATTRIBUTE_NOT_DEFINED)
288287
void verifyCanInteractWithElement(final boolean ignoreDisabled) {
289288
assertElementNotStale();
290289

291-
final Boolean displayed = driver_.implicitlyWaitFor(new Callable<Boolean>() {
292-
@Override
293-
public Boolean call() throws Exception {
294-
return isDisplayed();
295-
}
296-
});
290+
final Boolean displayed = driver_.implicitlyWaitFor(this::isDisplayed);
297291

298292
if (displayed == null || !displayed) {
299293
throw new ElementNotInteractableException("You may only interact with visible elements");
@@ -322,7 +316,7 @@ void switchFocusToThisIfNeeded() {
322316
final boolean jsEnabled = driver_.isJavascriptEnabled();
323317
final boolean oldActiveEqualsCurrent = oldActiveElement.equals(this);
324318
try {
325-
final boolean isBody = oldActiveElement.getTagName().toLowerCase().equals("body");
319+
final boolean isBody = "body".equalsIgnoreCase(oldActiveElement.getTagName());
326320
if (jsEnabled && !oldActiveEqualsCurrent && !isBody) {
327321
oldActiveElement.element_.blur();
328322
}
@@ -357,63 +351,58 @@ public String getAttribute(final String name) {
357351
return trueOrNull(((HtmlInput) element_).isChecked());
358352
}
359353

360-
if ("href".equals(lowerName)) {
361-
final String href = element_.getAttribute(name);
362-
if (ATTRIBUTE_NOT_DEFINED == href) {
363-
return null;
364-
}
365-
final HtmlPage page = (HtmlPage) element_.getPage();
366-
try {
367-
return page.getFullyQualifiedUrl(href.trim()).toString();
368-
}
369-
catch (final MalformedURLException e) {
370-
return null;
371-
}
372-
}
373-
374-
if ("src".equals(lowerName)) {
375-
final String link = element_.getAttribute(name);
376-
if (ATTRIBUTE_NOT_DEFINED == link) {
377-
return "";
378-
}
379-
final HtmlPage page = (HtmlPage) element_.getPage();
380-
try {
381-
return page.getFullyQualifiedUrl(link.trim()).toString();
382-
}
383-
catch (final MalformedURLException e) {
384-
return null;
385-
}
386-
}
387-
388-
if ("value".equals(lowerName)) {
389-
if (element_ instanceof HtmlInput) {
390-
return ((HtmlInput) element_).getValue();
391-
}
392-
if (element_ instanceof HtmlTextArea) {
393-
return ((HtmlTextArea) element_).getText();
354+
switch (lowerName) {
355+
case "href": {
356+
final String href = element_.getAttribute(name);
357+
if (ATTRIBUTE_NOT_DEFINED == href) {
358+
return null;
359+
}
360+
final HtmlPage page = (HtmlPage) element_.getPage();
361+
try {
362+
return page.getFullyQualifiedUrl(href.trim()).toString();
363+
} catch (final MalformedURLException e) {
364+
return null;
365+
}
394366
}
395-
396-
// According to
397-
// http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#adef-value-OPTION
398-
// if the value attribute doesn't exist, getting the "value" attribute defers to
399-
// the
400-
// option's content.
401-
if (element_ instanceof HtmlOption && !element_.hasAttribute("value")) {
402-
return getText();
367+
case "src": {
368+
final String link = element_.getAttribute(name);
369+
if (ATTRIBUTE_NOT_DEFINED == link) {
370+
return "";
371+
}
372+
final HtmlPage page = (HtmlPage) element_.getPage();
373+
try {
374+
return page.getFullyQualifiedUrl(link.trim()).toString();
375+
} catch (final MalformedURLException e) {
376+
return null;
377+
}
403378
}
379+
case "value":
380+
if (element_ instanceof HtmlInput) {
381+
return ((HtmlInput) element_).getValue();
382+
}
383+
if (element_ instanceof HtmlTextArea) {
384+
return ((HtmlTextArea) element_).getText();
385+
}
404386

405-
final String attributeValue = element_.getAttribute(name);
406-
if (ATTRIBUTE_NOT_DEFINED == attributeValue) {
407-
return null;
408-
}
409-
return attributeValue;
410-
}
387+
// According to
388+
// http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#adef-value-OPTION
389+
// if the value attribute doesn't exist, getting the "value" attribute defers to
390+
// the
391+
// option's content.
392+
if (element_ instanceof HtmlOption && !element_.hasAttribute("value")) {
393+
return getText();
394+
}
411395

412-
if ("disabled".equals(lowerName)) {
413-
if (element_ instanceof DisabledElement) {
414-
return trueOrNull(((DisabledElement) element_).isDisabled());
415-
}
416-
return "true";
396+
final String attributeValue = element_.getAttribute(name);
397+
if (ATTRIBUTE_NOT_DEFINED == attributeValue) {
398+
return null;
399+
}
400+
return attributeValue;
401+
case "disabled":
402+
if (element_ instanceof DisabledElement) {
403+
return trueOrNull(((DisabledElement) element_).isDisabled());
404+
}
405+
return "true";
417406
}
418407

419408
if ("multiple".equals(lowerName) && element_ instanceof HtmlSelect) {

src/main/java/org/openqa/selenium/htmlunit/logging/HtmlUnitLogs.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.htmlunit.logging;
1919

2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.Set;
@@ -104,9 +105,7 @@ private List<LogEntry> getContentAndFlush() {
104105
result = new ArrayList<>(insertPos_);
105106
}
106107

107-
for (int i = 0; i < insertPos_; i++) {
108-
result.add(buffer_[i]);
109-
}
108+
result.addAll(Arrays.asList(buffer_).subList(0, insertPos_));
110109

111110
insertPos_ = 0;
112111
isFull_ = false;

src/main/java/org/openqa/selenium/htmlunit/options/HtmlUnitDriverOptions.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,12 @@ public void setCapability(final String capabilityName, final Object value) {
307307
}
308308
final HtmlUnitOption option = HtmlUnitOption.fromCapabilityKey(capabilityName);
309309
if (option != null) {
310-
switch (option) {
311-
case WEB_CLIENT_VERSION:
312-
webClientVersion_ = (BrowserVersion) option.decode(value);
313-
return;
314-
default:
315-
option.insert(webClientOptions_, value);
316-
return;
310+
if (option == HtmlUnitOption.WEB_CLIENT_VERSION) {
311+
webClientVersion_ = (BrowserVersion) option.decode(value);
312+
return;
317313
}
314+
option.insert(webClientOptions_, value);
315+
return;
318316
}
319317
if (BrowserVersionTrait.fromCapabilityKey(capabilityName) != null) {
320318
throw new UnsupportedOperationException(

src/main/java/org/openqa/selenium/htmlunit/options/HtmlUnitOption.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public Object obtain(final WebClientOptions options) {
182182

183183
/**
184184
* Path to the directory to be used for storing the response content in a
185-
* temporary file. The specified directory is created if if doesn't exist.
185+
* temporary file. The specified directory is created if it doesn't exist.
186186
* <p>
187187
* property: <b>webdriver.htmlunit.tempFileDirectory</b><br>
188188
* type: {@link File}<br>
@@ -754,7 +754,7 @@ public Object obtain(final WebClientOptions options) {
754754
* <p>
755755
* property: <b>webdriver.htmlunit.webSocketMaxTextMessageSize</b><br>
756756
* type: {@code int}<br>
757-
* default: -1 {use default size)
757+
* default: -1 (use default size)
758758
*/
759759
WEB_SOCKET_MAX_TEXT_MESSAGE_SIZE(optWebSocketMaxTextMessageSize, int.class, -1) {
760760
@Override
@@ -773,7 +773,7 @@ public Object obtain(final WebClientOptions options) {
773773
* <p>
774774
* property: <b>webdriver.htmlunit.webSocketMaxTextMessageBufferSize</b><br>
775775
* type: {@code int}<br>
776-
* default: -1 {use default size)
776+
* default: -1 (use default size)
777777
*/
778778
WEB_SOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE(optWebSocketMaxTextMessageBufferSize, int.class, -1) {
779779
@Override
@@ -792,7 +792,7 @@ public Object obtain(final WebClientOptions options) {
792792
* <p>
793793
* property: <b>webdriver.htmlunit.webSocketMaxBinaryMessageSize</b><br>
794794
* type: {@code int}<br>
795-
* default: -1 {use default size)
795+
* default: -1 (use default size)
796796
*/
797797
WEB_SOCKET_MAX_BINARY_MESSAGE_SIZE(optWebSocketMaxBinaryMessageSize, int.class, -1) {
798798
@Override
@@ -811,7 +811,7 @@ public Object obtain(final WebClientOptions options) {
811811
* <p>
812812
* property: <b>webdriver.htmlunit.webSocketMaxBinaryMessageBufferSize</b><br>
813813
* type: {@code int}<br>
814-
* default: -1 {use default size)
814+
* default: -1 (use default size)
815815
*/
816816
WEB_SOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE(optWebSocketMaxBinaryMessageBufferSize, int.class, -1) {
817817
@Override

src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
import org.openqa.selenium.chrome.ChromeDriverService;
102102
import org.openqa.selenium.chrome.ChromeOptions;
103103
import org.openqa.selenium.devtools.DevTools;
104-
import org.openqa.selenium.devtools.v143.emulation.Emulation;
104+
import org.openqa.selenium.devtools.v144.emulation.Emulation;
105105
import org.openqa.selenium.edge.EdgeDriver;
106106
import org.openqa.selenium.edge.EdgeDriverService;
107107
import org.openqa.selenium.edge.EdgeOptions;

0 commit comments

Comments
 (0)