Skip to content

Commit 38b83c8

Browse files
committed
a bit more cleanup
1 parent 4562162 commit 38b83c8

File tree

10 files changed

+33
-11
lines changed

10 files changed

+33
-11
lines changed

src/main/java/org/htmlunit/MockWebConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
30+
import org.htmlunit.util.ArrayUtils;
3031
import org.htmlunit.util.MimeType;
3132
import org.htmlunit.util.NameValuePair;
3233

@@ -98,7 +99,7 @@ WebResponseData asWebResponseData() {
9899
content = byteContent_;
99100
}
100101
else if (stringContent_ == null) {
101-
content = new byte[] {};
102+
content = ArrayUtils.EMPTY_BYTE_ARRAY;
102103
}
103104
else {
104105
content = stringContent_.getBytes(charset_);

src/main/java/org/htmlunit/WebResponseData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.apache.commons.io.ByteOrderMark;
2929
import org.apache.commons.io.IOUtils;
3030
import org.apache.commons.io.input.BOMInputStream;
31-
import org.apache.commons.lang3.ArrayUtils;
3231
import org.apache.commons.logging.Log;
3332
import org.apache.commons.logging.LogFactory;
33+
import org.htmlunit.util.ArrayUtils;
3434
import org.htmlunit.util.MimeType;
3535
import org.htmlunit.util.NameValuePair;
3636
import org.htmlunit.util.StringUtils;

src/main/java/org/htmlunit/util/ArrayUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
* @author Ronald Brill
2121
*/
2222
public final class ArrayUtils {
23+
/**
24+
* An empty immutable {@code byte} array.
25+
*/
26+
public static final byte[] EMPTY_BYTE_ARRAY = {};
27+
28+
/**
29+
* An empty immutable {@link String} array.
30+
*/
31+
public static final String[] EMPTY_STRING_ARRAY = {};
2332

2433
/**
2534
* Disallow instantiation of this class.

src/test/java/org/htmlunit/VersionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package org.htmlunit;
1616

17+
import org.htmlunit.util.ArrayUtils;
1718
import org.junit.jupiter.api.Test;
1819

1920
/**
@@ -28,7 +29,7 @@ public class VersionTest {
2829
*/
2930
@Test
3031
public void main() throws Exception {
31-
Version.main(new String[] {});
32+
Version.main(ArrayUtils.EMPTY_STRING_ARRAY);
3233
}
3334

3435
/**

src/test/java/org/htmlunit/WebResponseDataTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.commons.lang3.StringUtils;
3535
import org.htmlunit.html.HtmlPage;
3636
import org.htmlunit.http.HttpStatus;
37+
import org.htmlunit.util.ArrayUtils;
3738
import org.htmlunit.util.MimeType;
3839
import org.htmlunit.util.NameValuePair;
3940
import org.junit.jupiter.api.Test;
@@ -254,7 +255,7 @@ public void brokenBrotliContent() throws Exception {
254255
*/
255256
@Test
256257
public void nullBody() throws Exception {
257-
final DownloadedContent downloadedContent = new DownloadedContent.InMemory(new byte[] {});
258+
final DownloadedContent downloadedContent = new DownloadedContent.InMemory(ArrayUtils.EMPTY_BYTE_ARRAY);
258259
final List<NameValuePair> headers = new ArrayList<>();
259260
final WebResponseData data = new WebResponseData(downloadedContent, 304, "NOT_MODIFIED", headers);
260261
assertEquals(0, data.getBody().length);

src/test/java/org/htmlunit/doc/DetailsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.htmlunit.html.BaseFrameElement;
3737
import org.htmlunit.html.HtmlPage;
3838
import org.htmlunit.http.HttpStatus;
39+
import org.htmlunit.util.ArrayUtils;
3940
import org.htmlunit.util.MimeType;
4041
import org.htmlunit.util.NameValuePair;
4142
import org.htmlunit.util.WebConnectionWrapper;
@@ -98,7 +99,7 @@ private boolean isBlocked(final URL requestUrl) {
9899
*/
99100
@Test
100101
public void contentBlockingResponse() throws Exception {
101-
final byte[] content = new byte[] {};
102+
final byte[] content = ArrayUtils.EMPTY_BYTE_ARRAY;
102103
final List<NameValuePair> headers = new ArrayList<>();
103104
headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length)));
104105

src/test/java/org/htmlunit/html/HtmlAreaTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.htmlunit.WebDriverTestCase;
2626
import org.htmlunit.junit.annotation.Alerts;
2727
import org.htmlunit.junit.annotation.BuggyWebDriver;
28+
import org.htmlunit.util.ArrayUtils;
2829
import org.junit.jupiter.api.Test;
2930
import org.openqa.selenium.By;
3031
import org.openqa.selenium.WebDriver;
@@ -253,7 +254,7 @@ public void isDisplayedEmptyRect() throws Exception {
253254

254255
final String[] expected = getExpectedAlerts();
255256

256-
setExpectedAlerts(new String[] {});
257+
setExpectedAlerts(ArrayUtils.EMPTY_STRING_ARRAY);
257258
final WebDriver driver = loadPage2(html);
258259

259260
boolean displayed = driver.findElement(By.id("myArea1")).isDisplayed();
@@ -296,7 +297,7 @@ public void isDisplayedEmptyCircle() throws Exception {
296297

297298
final String[] expected = getExpectedAlerts();
298299

299-
setExpectedAlerts(new String[] {});
300+
setExpectedAlerts(ArrayUtils.EMPTY_STRING_ARRAY);
300301
final WebDriver driver = loadPage2(html);
301302

302303
boolean displayed = driver.findElement(By.id("myArea1")).isDisplayed();
@@ -332,7 +333,7 @@ public void isDisplayedEmptyPolygon() throws Exception {
332333

333334
final String[] expected = getExpectedAlerts();
334335

335-
setExpectedAlerts(new String[] {});
336+
setExpectedAlerts(ArrayUtils.EMPTY_STRING_ARRAY);
336337
final WebDriver driver = loadPage2(html);
337338

338339
boolean displayed = driver.findElement(By.id("myArea1")).isDisplayed();

src/test/java/org/htmlunit/javascript/host/Location2Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.htmlunit.WebDriverTestCase;
2525
import org.htmlunit.junit.annotation.Alerts;
2626
import org.htmlunit.junit.annotation.HtmlUnitNYI;
27+
import org.htmlunit.util.ArrayUtils;
2728
import org.htmlunit.util.MimeType;
2829
import org.htmlunit.util.NameValuePair;
2930
import org.junit.jupiter.api.Test;
@@ -871,7 +872,7 @@ public void onlick_set_location_WithHref() throws Exception {
871872
getMockWebConnection().setDefaultResponse("");
872873
final WebDriver driver = loadPage2(html);
873874

874-
assertEquals(new String[] {}, getMockWebConnection().getRequestedUrls(URL_FIRST));
875+
assertEquals(ArrayUtils.EMPTY_STRING_ARRAY, getMockWebConnection().getRequestedUrls(URL_FIRST));
875876
driver.findElement(By.tagName("a")).click();
876877

877878
assertEquals(getExpectedAlerts(), getMockWebConnection().getRequestedUrls(URL_FIRST));

src/test/java/org/htmlunit/javascript/host/dom/MutationObserverTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.htmlunit.WebDriverTestCase;
2121
import org.htmlunit.junit.annotation.Alerts;
2222
import org.htmlunit.junit.annotation.BuggyWebDriver;
23+
import org.htmlunit.util.ArrayUtils;
2324
import org.junit.jupiter.api.Test;
2425
import org.openqa.selenium.By;
2526
import org.openqa.selenium.WebDriver;
@@ -314,7 +315,7 @@ public void attributeValue() throws Exception {
314315
+ "</body></html>";
315316
final WebDriver driver = loadPage2(html);
316317
driver.findElement(By.id("tester")).sendKeys("abc");
317-
verifyTitle2(driver, new String[] {});
318+
verifyTitle2(driver, ArrayUtils.EMPTY_STRING_ARRAY);
318319

319320
driver.findElement(By.id("doAlert")).click();
320321
verifyTitle2(driver, new String[] {"heho"});
@@ -370,7 +371,7 @@ public void attributeValueAddRemove() throws Exception {
370371
+ "</body></html>";
371372
final WebDriver driver = loadPage2(html);
372373
driver.findElement(By.id("tester")).sendKeys("abc");
373-
verifyTitle2(driver, new String[] {});
374+
verifyTitle2(driver, ArrayUtils.EMPTY_STRING_ARRAY);
374375

375376
driver.findElement(By.id("doAlert")).click();
376377
verifyTitle2(driver, new String[] {"heho"});

src/test/java/org/htmlunit/util/ArrayUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ public void contains() throws Exception {
3838

3939
assertFalse(ArrayUtils.contains(null, "ab"));
4040
assertFalse(ArrayUtils.contains(new String[] {}, "ab"));
41+
assertFalse(ArrayUtils.contains(ArrayUtils.EMPTY_STRING_ARRAY, "ab"));
4142
assertFalse(ArrayUtils.contains(new String[] {"cd", "ab"}, "x"));
4243

4344
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.contains(new String[] {}, null));
45+
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.contains(ArrayUtils.EMPTY_STRING_ARRAY, null));
4446
}
4547

4648
/**
@@ -58,9 +60,12 @@ public void containsIgnoreCase() throws Exception {
5860

5961
assertFalse(ArrayUtils.containsIgnoreCase(null, "ab"));
6062
assertFalse(ArrayUtils.containsIgnoreCase(new String[] {}, "ab"));
63+
assertFalse(ArrayUtils.containsIgnoreCase(ArrayUtils.EMPTY_STRING_ARRAY, "ab"));
6164
assertFalse(ArrayUtils.containsIgnoreCase(new String[] {"cd", "ab"}, "x"));
6265

6366
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.containsIgnoreCase(new String[] {}, null));
67+
assertThrows(IllegalArgumentException.class,
68+
() -> ArrayUtils.containsIgnoreCase(ArrayUtils.EMPTY_STRING_ARRAY, null));
6469
}
6570

6671
/**
@@ -74,6 +79,7 @@ public void containsByte() throws Exception {
7479

7580
assertFalse(ArrayUtils.contains(null, (byte) 7));
7681
assertFalse(ArrayUtils.contains(new byte[] {}, (byte) 1));
82+
assertFalse(ArrayUtils.contains(ArrayUtils.EMPTY_BYTE_ARRAY, (byte) 1));
7783
assertFalse(ArrayUtils.contains(new byte[] {7, 9}, (byte) 4));
7884
}
7985
}

0 commit comments

Comments
 (0)