Skip to content

Commit 9addc66

Browse files
committed
jdk17
1 parent 0d58c67 commit 9addc66

40 files changed

+100
-97
lines changed

src/test/java/org/htmlunit/CacheTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.htmlunit.HttpHeader.LAST_MODIFIED;
2424

2525
import java.net.URL;
26+
import java.nio.charset.StandardCharsets;
2627
import java.text.SimpleDateFormat;
2728
import java.util.ArrayList;
2829
import java.util.Collections;
@@ -558,7 +559,7 @@ public void cssManuallyAddeToCache() throws Exception {
558559
final List<NameValuePair> headers = new ArrayList<>();
559560
headers.add(new NameValuePair(LAST_MODIFIED, "Sun, 15 Jul 2007 20:46:27 GMT"));
560561
final WebRequest request = new WebRequest(cssUrl);
561-
final WebResponseData data = new WebResponseData(css.getBytes("UTF-8"),
562+
final WebResponseData data = new WebResponseData(css.getBytes(StandardCharsets.UTF_8),
562563
HttpStatus.OK_200, HttpStatus.OK_200_MSG, headers);
563564
final WebResponse response = new WebResponse(data, request, 100);
564565
client.getCache().cacheIfPossible(new WebRequest(cssUrl), response, headers);

src/test/java/org/htmlunit/CodeStyleTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class CodeStyleTest {
5858
private static final Pattern LEADING_WHITESPACE = Pattern.compile("^\\s+");
5959
private static final Pattern LOG_STATIC_STRING =
6060
Pattern.compile("^\\s*LOG\\.[a-z]+\\(\"[^\"]*\"(, [a-zA-Z_]+)?\\);");
61-
private List<String> failures_ = new ArrayList<>();
61+
private final List<String> failures_ = new ArrayList<>();
6262
private String title_ = "unknown";
6363

6464
/**
@@ -684,7 +684,7 @@ private static List<String> alertsToList(final List<String> lines, final int ale
684684
final StringBuilder alerts = new StringBuilder();
685685
for (int i = alertsIndex;; i++) {
686686
final String line = lines.get(i);
687-
if (alerts.length() != 0) {
687+
if (!alerts.isEmpty()) {
688688
alerts.append('\n');
689689
}
690690
if (line.startsWith(" @Alerts(")) {
@@ -757,7 +757,7 @@ private static List<String> alertsToList(final String string) {
757757
boolean startsWithBraces = false;
758758
for (final String token : string.split("(?<!\\\\)\"")) {
759759
insideString = !insideString;
760-
if (currentToken.length() != 0) {
760+
if (!currentToken.isEmpty()) {
761761
currentToken.append('"');
762762
}
763763
else {
@@ -781,7 +781,7 @@ private static List<String> alertsToList(final String string) {
781781
if (!insideString && token.contains(",") && !startsWithBraces) {
782782
final String[] expressions = token.split(",");
783783
currentToken.append(expressions[0]);
784-
if (currentToken.length() != 0) {
784+
if (!currentToken.isEmpty()) {
785785
list.add(currentToken.toString());
786786
}
787787
for (int i = 1; i < expressions.length - 1; i++) {
@@ -795,7 +795,7 @@ private static List<String> alertsToList(final String string) {
795795
}
796796
}
797797
}
798-
if (currentToken.length() != 0) {
798+
if (!currentToken.isEmpty()) {
799799
if (!currentToken.toString().contains("\"")) {
800800
currentToken.insert(0, '"');
801801
}

src/test/java/org/htmlunit/DefaultPageCreatorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.OutputStream;
1919
import java.io.OutputStreamWriter;
2020
import java.io.Writer;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

@@ -427,7 +428,7 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
427428
output.write('\u00fe');
428429
output.write('\u00ff');
429430
output.flush();
430-
final Writer writer = new OutputStreamWriter(output, "UTF16");
431+
final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_16);
431432
writer.write(DOCTYPE_HTML + "<html><head></head><body></body></html>");
432433
writer.flush();
433434
}

src/test/java/org/htmlunit/ExternalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void pom() throws Exception {
129129
}
130130
}
131131

132-
if (wrongVersions.size() > 0) {
132+
if (!wrongVersions.isEmpty()) {
133133
Assertions.fail(String.join("\n ", wrongVersions));
134134
}
135135

src/test/java/org/htmlunit/NoHttpResponseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void htmlUnitDriverUsesGetPage() throws Exception {
215215
catch (final FailingHttpStatusCodeException e) {
216216
// expected
217217
assertEquals(0, e.getStatusCode());
218-
assertEquals("0 No HTTP Response for " + URL_FIRST.toString(), e.getMessage());
218+
assertEquals("0 No HTTP Response for " + URL_FIRST, e.getMessage());
219219
}
220220
}
221221
}

src/test/java/org/htmlunit/NotYetImplementedTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class NotYetImplementedTest {
3636

37-
private Set<String> entries_ = new TreeSet<>();
37+
private final Set<String> entries_ = new TreeSet<>();
3838

3939
/**
4040
* @throws Exception if the test fails
@@ -121,13 +121,13 @@ else if (line.startsWith(" @HtmlUnitNYI")) {
121121
browser += "EDGE";
122122
}
123123
if (nyiString.contains("FF_ESR = ")) {
124-
if (browser.length() > 0) {
124+
if (!browser.isEmpty()) {
125125
browser += ", ";
126126
}
127127
browser += "FF_ESR";
128128
}
129129
if (nyiString.contains("FF = ")) {
130-
if (browser.length() > 0) {
130+
if (!browser.isEmpty()) {
131131
browser += ", ";
132132
}
133133
browser += "FF";
@@ -163,7 +163,7 @@ private static String getDescription(final List<String> lines, final int index)
163163
break;
164164
}
165165
if (start != -1) {
166-
if (builder.length() != 0) {
166+
if (!builder.isEmpty()) {
167167
builder.append(' ');
168168
}
169169
builder.append(line, start, line.length() - (end ? 2 : 0));
@@ -232,7 +232,7 @@ private void save() throws Exception {
232232
builder.append("</td>\n");
233233
lastFile = file;
234234
}
235-
builder.append(" <td>").append(Integer.toString(count++)).append("</td>\n");
235+
builder.append(" <td>").append(count++).append("</td>\n");
236236

237237
builder.append(" <td><a target='_blank' href='https://github.com/HtmlUnit/htmlunit/blob/master/")
238238
.append(file)
@@ -268,7 +268,7 @@ private void save() throws Exception {
268268
final StringBuilder overview = new StringBuilder();
269269
overview.append("<table class='bottomBorder'>\n");
270270
overview.append(" <tr>\n");
271-
overview.append(" <td class='numeric'>").append(Integer.toString(count)).append("</td>\n");
271+
overview.append(" <td class='numeric'>").append(count).append("</td>\n");
272272
overview.append(" <td>methods marked as NotYetImplemented</td>\n");
273273
overview.append(" </tr>\n");
274274

@@ -283,7 +283,7 @@ private void save() throws Exception {
283283
overview.append(" </tr>\n");
284284

285285
overview.append(" <tr>\n");
286-
overview.append(" <td class='numeric'>").append(Integer.toString(countChrome)).append("</td>\n");
286+
overview.append(" <td class='numeric'>").append(countChrome).append("</td>\n");
287287
overview.append(" <td>for Chrome</td>\n");
288288
overview.append(" </tr>\n");
289289

src/test/java/org/htmlunit/PrimitiveWebServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class PrimitiveWebServer implements Closeable {
4646
private final String otherResponse_;
4747
private ServerSocket server_;
4848
private Charset charset_ = StandardCharsets.ISO_8859_1;
49-
private List<String> requests_ = new ArrayList<>();
49+
private final List<String> requests_ = new ArrayList<>();
5050

5151
/**
5252
* Constructs a new SimpleWebServer.
@@ -125,7 +125,7 @@ private void start() throws Exception {
125125
}
126126

127127
final String response;
128-
if (requestString.length() < 1
128+
if (requestString.isEmpty()
129129
|| requestString.contains("/favicon.ico")) {
130130
response = "HTTP/1.1 404 Not Found\r\n"
131131
+ "Content-Length: 0\r\n"

src/test/java/org/htmlunit/SimpleWebTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public void releaseResources() {
263263
// collect stack traces
264264
// caution: the threads may terminate after the threads have been returned by getJavaScriptThreads()
265265
// and before stack traces are retrieved
266-
if (jsThreads.size() > 0) {
266+
if (!jsThreads.isEmpty()) {
267267
final Map<String, StackTraceElement[]> stackTraces = new HashMap<>();
268268
for (final Thread t : jsThreads) {
269269
final StackTraceElement[] elts = t.getStackTrace();

src/test/java/org/htmlunit/WebClient2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public void toLocaleLowerCase() throws Exception {
442442
@Test
443443
public void localFile() throws Exception {
444444
final URL url = getClass().getClassLoader().getResource("simple.html");
445-
String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8.name());
445+
String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8);
446446
if (file.startsWith("/") && file.contains(":")) {
447447
// we have to remove the trailing slash to test the c:\.... case.
448448
file = file.substring(1);
@@ -468,7 +468,7 @@ public void localFile() throws Exception {
468468
@Alerts("titel - simple.html")
469469
public void localFileFile() throws Exception {
470470
final URL url = getClass().getClassLoader().getResource("simple.html");
471-
String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8.name());
471+
String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8);
472472
if (file.startsWith("/") && file.contains(":")) {
473473
// we have to remove the trailing slash to test the c:\.... case.
474474
file = file.substring(1);

src/test/java/org/htmlunit/WebClient4Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public void redirectInfinite303And307() throws Exception {
104104
*/
105105
public static class RedirectServlet extends HttpServlet {
106106
private int count_;
107-
private int status_;
108-
private String location_;
107+
private final int status_;
108+
private final String location_;
109109

110110
/**
111111
* Creates a new instance.

0 commit comments

Comments
 (0)