From: <rb...@us...> - 2018-03-30 13:05:09
|
Revision: 15219 http://sourceforge.net/p/htmlunit/code/15219 Author: rbri Date: 2018-03-30 13:05:06 +0000 (Fri, 30 Mar 2018) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -1507,19 +1507,19 @@ final HtmlElement element = getHtmlElementByAccessKey(accessKey); if (element != null) { element.focus(); - final Page newPage; - if (element instanceof HtmlAnchor || element instanceof HtmlArea || element instanceof HtmlButton - || element instanceof HtmlInput || element instanceof HtmlLabel || element instanceof HtmlLegend - || element instanceof HtmlTextArea || element instanceof HtmlArea) { - newPage = element.click(); - } - else { - newPage = this; - } + if (element instanceof HtmlAnchor + || element instanceof HtmlArea + || element instanceof HtmlButton + || element instanceof HtmlInput + || element instanceof HtmlLabel + || element instanceof HtmlLegend + || element instanceof HtmlTextArea) { + final Page newPage = element.click(); - if (newPage != this && getFocusedElement() == element) { - // The page was reloaded therefore no element on this page will have the focus. - getFocusedElement().blur(); + if (newPage != this && getFocusedElement() == element) { + // The page was reloaded therefore no element on this page will have the focus. + getFocusedElement().blur(); + } } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -21,8 +21,6 @@ import org.apache.http.client.utils.DateUtils; -import com.gargoylesoftware.htmlunit.WebAssert; - /** * String utilities class for utility functions not covered by third party libraries. * @@ -149,63 +147,26 @@ final int tmpRed = Integer.parseInt(tmpHex.substring(0, 2), 16); final int tmpGreen = Integer.parseInt(tmpHex.substring(2, 4), 16); final int tmpBlue = Integer.parseInt(tmpHex.substring(4, 6), 16); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } final int tmpRed = Integer.parseInt(tmpHex.substring(0, 1) + tmpHex.substring(0, 1), 16); final int tmpGreen = Integer.parseInt(tmpHex.substring(1, 2) + tmpHex.substring(1, 2), 16); final int tmpBlue = Integer.parseInt(tmpHex.substring(2, 3) + tmpHex.substring(2, 3), 16); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } /** - * Returns true if the specified token is in RGB notation. - * @param token the token to check - * @return whether the token is a color in RGB notation or not - */ - public static boolean isColorRGB(final String token) { - if (token == null) { - return false; - } - return RGB_COLOR.matcher(token.trim()).matches(); - } - - /** * Returns a Color parsed from the given rgb notation. * @param token the token to parse * @return a Color whether the token is a color in RGB notation; otherwise null */ - public static Color asColorRGB(final String token) { - if (token == null) { - return null; - } - final Matcher tmpMatcher = RGB_COLOR.matcher(token); - final boolean tmpFound = tmpMatcher.matches(); - if (!tmpFound) { - return null; - } - - final int tmpRed = Integer.parseInt(tmpMatcher.group(1)); - final int tmpGreen = Integer.parseInt(tmpMatcher.group(2)); - final int tmpBlue = Integer.parseInt(tmpMatcher.group(3)); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; - } - - /** - * Returns a Color parsed from the given rgb notation. - * @param token the token to parse - * @return a Color whether the token is a color in RGB notation; otherwise null - */ public static Color findColorRGB(final String token) { if (token == null) { return null; } final Matcher tmpMatcher = RGB_COLOR.matcher(token); - final boolean tmpFound = tmpMatcher.find(); - if (!tmpFound) { + if (!tmpMatcher.find()) { return null; } @@ -212,8 +173,7 @@ final int tmpRed = Integer.parseInt(tmpMatcher.group(1)); final int tmpGreen = Integer.parseInt(tmpMatcher.group(2)); final int tmpBlue = Integer.parseInt(tmpMatcher.group(3)); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } /** @@ -227,17 +187,6 @@ } /** - * Formats the specified date according to RFC 1123. - * - * @param date the date to format - * @return the specified date, formatted according to RFC 1123 - */ - public static String formatHttpDate(final Date date) { - WebAssert.notNull("date", date); - return DateUtils.formatDate(date); - } - - /** * Sanitize a string for use in Matcher.appendReplacement. * Replaces all \ with \\ and $ as \$ because they are used as control * characters in appendReplacement. @@ -246,9 +195,8 @@ * @return sanitized version of the given string */ public static String sanitizeForAppendReplacement(final String toSanitize) { - final String toReplace = org.apache.commons.lang3.StringUtils.replaceEach(toSanitize, - new String[] {"\\", "$"}, new String[]{"\\\\", "\\$"}); - return toReplace; + return org.apache.commons.lang3.StringUtils.replaceEach(toSanitize, + new String[] {"\\", "$"}, new String[]{"\\\\", "\\$"}); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -510,8 +510,7 @@ s.append(ref); } - final URL url = new URL(s.toString()); - return url; + return new URL(s.toString()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit; +import static org.apache.http.client.utils.DateUtils.formatDate; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -23,7 +25,6 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link AbstractPage}. @@ -43,7 +44,7 @@ webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); + headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "unknown_type", headers); startWebServer(getMockWebConnection()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,7 +14,7 @@ */ package com.gargoylesoftware.htmlunit; -import static com.gargoylesoftware.htmlunit.util.StringUtils.formatHttpDate; +import static org.apache.http.client.utils.DateUtils.formatDate; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; @@ -39,7 +39,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link Cache}. @@ -71,13 +70,13 @@ headers.put("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT"); assertTrue(cache.isCacheableContent(response)); - headers.put("Last-Modified", formatHttpDate(DateUtils.addMinutes(new Date(), -5))); + headers.put("Last-Modified", formatDate(DateUtils.addMinutes(new Date(), -5))); assertFalse(cache.isCacheableContent(response)); - headers.put("Expires", formatHttpDate(DateUtils.addMinutes(new Date(), 5))); + headers.put("Expires", formatDate(DateUtils.addMinutes(new Date(), 5))); assertFalse(cache.isCacheableContent(response)); - headers.put("Expires", formatHttpDate(DateUtils.addHours(new Date(), 1))); + headers.put("Expires", formatDate(DateUtils.addHours(new Date(), 1))); assertTrue(cache.isCacheableContent(response)); headers.remove("Last-Modified"); @@ -524,7 +523,7 @@ expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); final WebRequest request2 = new WebRequest(URL_SECOND, HttpMethod.GET); final WebResponse response2 = createMock(WebResponse.class); @@ -533,7 +532,7 @@ expect(response2.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response2.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response2.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); @@ -560,7 +559,7 @@ expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -31,7 +31,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Unit tests for {@link CookieManager}. @@ -282,7 +281,7 @@ final List<NameValuePair> responseHeader1 = new ArrayList<>(); responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Fri, 02-Jan-1970 00:00:00 GMT")); responseHeader1.add(new NameValuePair("Set-Cookie", - "second=2;expires=" + StringUtils.formatHttpDate(aBitLater))); + "second=2;expires=" + DateUtils.formatDate(aBitLater))); responseHeader1.add(new NameValuePair("Set-Cookie", "visit=fo; expires=\"Sat, 07-Apr-2002 13:11:33 GMT\";")); responseHeader1.add(new NameValuePair("Set-Cookie", "visitor=f2; expires=\"Sat, 07-Apr-2092 13:11:33 GMT\";")); getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", "text/html", responseHeader1); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit; +import static org.apache.http.client.utils.DateUtils.formatDate; + import java.util.ArrayList; import java.util.Date; import java.util.Iterator; @@ -31,7 +33,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlDivision; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link SgmlPage}. @@ -51,7 +52,7 @@ webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); + headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "text/html", headers); startWebServer(getMockWebConnection()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -45,35 +45,6 @@ * @throws Exception if the test fails */ @Test - public void isColorRGB() throws Exception { - assertFalse(StringUtils.isColorRGB(null)); - assertFalse(StringUtils.isColorRGB("")); - assertFalse(StringUtils.isColorRGB(" ")); - - assertFalse(StringUtils.isColorRGB("#a1")); - assertTrue(StringUtils.isColorRGB("rgb(1,12,13)")); - assertTrue(StringUtils.isColorRGB(" rgb(1,12,13) ")); - assertTrue(StringUtils.isColorRGB("rgb ( 1, 12, 13 )")); - assertFalse(StringUtils.isColorRGB("rgb(a1,12,13)")); - } - - /** - * @throws Exception if the test fails - */ - @Test - public void asColorRGB() throws Exception { - assertNull(StringUtils.asColorRGB(null)); - assertNull(StringUtils.asColorRGB("")); - assertNull(StringUtils.asColorRGB(" ")); - - assertNull(StringUtils.asColorRGB("#a1")); - assertEquals(new Color(1, 12, 13), StringUtils.asColorRGB("rgb(1,12,13)")); - } - - /** - * @throws Exception if the test fails - */ - @Test public void findColorRGB() throws Exception { assertNull(StringUtils.findColorRGB(null)); assertNull(StringUtils.findColorRGB("")); |