Skip to content

Commit 0d58c67

Browse files
committed
jdk17
1 parent fb1c22c commit 0d58c67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+273
-563
lines changed

src/test/java/org/htmlunit/BrowserVersionFeaturesTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ else if (file.getName().endsWith(".java")) {
148148
final List<String> lines = FileUtils.readLines(file, ISO_8859_1);
149149
final String browserVersionFeatures = BrowserVersionFeatures.class.getSimpleName();
150150
for (final String line : lines) {
151-
for (final Iterator<String> it = unusedFeatures.iterator(); it.hasNext();) {
152-
if (line.contains(browserVersionFeatures + '.' + it.next())) {
153-
it.remove();
154-
}
155-
}
151+
unusedFeatures.removeIf(s -> line.contains(browserVersionFeatures + '.' + s));
156152
}
157153
}
158154
}

src/test/java/org/htmlunit/FailingHttpStatusCodeExceptionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void constructorWithWebResponse() throws Exception {
4545
assertEquals(webResponse, e.getResponse());
4646
assertEquals(webResponse.getStatusMessage(), e.getStatusMessage());
4747
assertEquals(webResponse.getStatusCode(), e.getStatusCode());
48-
assertTrue("message doesn't contain failing url", e.getMessage().indexOf(URL_FIRST.toExternalForm()) > -1);
48+
assertTrue("message doesn't contain failing url", e.getMessage().contains(URL_FIRST.toExternalForm()));
4949
}
5050

5151
/**

src/test/java/org/htmlunit/HttpWebConnection3Test.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public void acceptEncoding() throws Exception {
160160
driver.get("http://localhost:" + primitiveWebServer.getPort());
161161
final String request = primitiveWebServer.getRequests().get(0);
162162
final String[] headers = request.split("\\r\\n");
163-
for (int i = 0; i < headers.length; i++) {
164-
final String header = headers[i];
163+
for (final String header : headers) {
165164
if (StringUtils.startsWithIgnoreCase(header, HttpHeader.ACCEPT_ENCODING_LC)) {
166165
final String value = header.substring(header.indexOf(':') + 1);
167166
assertEquals(getExpectedAlerts()[0], value.trim());
@@ -179,12 +178,9 @@ public void acceptEncoding() throws Exception {
179178
* @return true when the url matches, false otherwise
180179
*/
181180
public static ExpectedCondition<Boolean> currentUrlContains(final String url) {
182-
return new ExpectedCondition<>() {
183-
@Override
184-
public Boolean apply(final WebDriver driver) {
185-
final String currentUrl = driver.getCurrentUrl();
186-
return currentUrl != null && currentUrl.contains(url);
187-
}
181+
return driver -> {
182+
final String currentUrl = driver.getCurrentUrl();
183+
return currentUrl != null && currentUrl.contains(url);
188184
};
189185
}
190186

src/test/java/org/htmlunit/IncorrectnessListenerTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ public void notification() throws Exception {
4343
final WebClient webClient = getWebClient();
4444

4545
final List<String> collectedIncorrectness = new ArrayList<>();
46-
final IncorrectnessListener listener = new IncorrectnessListener() {
47-
@Override
48-
public void notify(final String message, final Object origin) {
49-
collectedIncorrectness.add(message);
50-
}
51-
};
46+
final IncorrectnessListener listener = (message, origin) -> collectedIncorrectness.add(message);
5247
webClient.setIncorrectnessListener(listener);
5348

5449
final MockWebConnection webConnection = new MockWebConnection();

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

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -91,74 +91,70 @@ private void start() throws Exception {
9191
}
9292
}
9393

94-
new Thread(new Runnable() {
95-
96-
@Override
97-
public void run() {
98-
boolean first = true;
99-
try {
100-
while (true) {
101-
final Socket socket = server_.accept();
102-
final InputStream in = socket.getInputStream();
103-
final CharArrayWriter writer = new CharArrayWriter();
104-
105-
String requestString = writer.toString();
106-
int i;
107-
108-
while ((i = in.read()) != -1) {
109-
writer.append((char) i);
110-
requestString = writer.toString();
111-
112-
if (i == '\n' && requestString.endsWith("\r\n\r\n")) {
113-
break;
114-
}
94+
new Thread(() -> {
95+
boolean first = true;
96+
try {
97+
while (true) {
98+
final Socket socket = server_.accept();
99+
final InputStream in = socket.getInputStream();
100+
final CharArrayWriter writer = new CharArrayWriter();
101+
102+
String requestString = writer.toString();
103+
int i;
104+
105+
while ((i = in.read()) != -1) {
106+
writer.append((char) i);
107+
requestString = writer.toString();
108+
109+
if (i == '\n' && requestString.endsWith("\r\n\r\n")) {
110+
break;
115111
}
116-
final int contentLengthPos =
117-
StringUtils.indexOfIgnoreCase(requestString, HttpHeader.CONTENT_LENGTH);
118-
if (contentLengthPos > -1) {
119-
final int endPos = requestString.indexOf('\n', contentLengthPos + 16);
120-
final String toParse = requestString.substring(contentLengthPos + 16, endPos);
121-
final int contentLength = Integer.parseInt(toParse.trim());
122-
123-
if (contentLength > 0) {
124-
final byte[] charArray = new byte[contentLength];
125-
IOUtils.read(in, charArray, 0, contentLength);
126-
requestString += new String(charArray);
127-
}
112+
}
113+
final int contentLengthPos =
114+
StringUtils.indexOfIgnoreCase(requestString, HttpHeader.CONTENT_LENGTH);
115+
if (contentLengthPos > -1) {
116+
final int endPos = requestString.indexOf('\n', contentLengthPos + 16);
117+
final String toParse = requestString.substring(contentLengthPos + 16, endPos);
118+
final int contentLength = Integer.parseInt(toParse.trim());
119+
120+
if (contentLength > 0) {
121+
final byte[] charArray = new byte[contentLength];
122+
IOUtils.read(in, charArray, 0, contentLength);
123+
requestString += new String(charArray);
128124
}
125+
}
129126

130-
final String response;
131-
if (requestString.length() < 1
132-
|| requestString.contains("/favicon.ico")) {
133-
response = "HTTP/1.1 404 Not Found\r\n"
134-
+ "Content-Length: 0\r\n"
135-
+ "Connection: close\r\n"
136-
+ "\r\n";
127+
final String response;
128+
if (requestString.length() < 1
129+
|| requestString.contains("/favicon.ico")) {
130+
response = "HTTP/1.1 404 Not Found\r\n"
131+
+ "Content-Length: 0\r\n"
132+
+ "Connection: close\r\n"
133+
+ "\r\n";
134+
}
135+
else {
136+
requests_.add(requestString);
137+
if (first || otherResponse_ == null) {
138+
response = firstResponse_;
137139
}
138140
else {
139-
requests_.add(requestString);
140-
if (first || otherResponse_ == null) {
141-
response = firstResponse_;
142-
}
143-
else {
144-
response = otherResponse_;
145-
}
146-
first = false;
141+
response = otherResponse_;
147142
}
143+
first = false;
144+
}
148145

149-
try (OutputStream out = socket.getOutputStream()) {
150-
final int headPos = response.indexOf("\r\n\r\n");
151-
out.write(response.substring(0, headPos + 4).getBytes(StandardCharsets.US_ASCII));
152-
out.write(response.substring(headPos + 4).getBytes(charset_));
153-
}
146+
try (OutputStream out = socket.getOutputStream()) {
147+
final int headPos = response.indexOf("\r\n\r\n");
148+
out.write(response.substring(0, headPos + 4).getBytes(StandardCharsets.US_ASCII));
149+
out.write(response.substring(headPos + 4).getBytes(charset_));
154150
}
155151
}
156-
catch (final SocketException e) {
157-
// ignore
158-
}
159-
catch (final Exception e) {
160-
throw new RuntimeException(e);
161-
}
152+
}
153+
catch (final SocketException e) {
154+
// ignore
155+
}
156+
catch (final Exception e) {
157+
throw new RuntimeException(e);
162158
}
163159
}).start();
164160
}

src/test/java/org/htmlunit/ScriptPreProcessorTest.java

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,21 @@ public void scriptPreProcessor() throws IOException {
6666
client.setWebConnection(webConnection);
6767

6868
// Test null return from pre processor
69-
client.setScriptPreProcessor(new ScriptPreProcessor() {
70-
@Override
71-
public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName,
72-
final int lineNumber, final HtmlElement htmlElement) {
73-
return null;
74-
}
75-
});
76-
client.setAlertHandler(new AlertHandler() {
77-
@Override
78-
public void handleAlert(final Page page, final String message) {
79-
fail("The pre processor did not remove the JavaScript");
80-
}
81-
82-
});
69+
client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> null);
70+
client.setAlertHandler((AlertHandler) (page, message) -> fail("The pre processor did not remove the JavaScript"));
8371
client.getPage(URL_FIRST);
8472

8573
// Test modify script in pre processor
86-
client.setScriptPreProcessor(new ScriptPreProcessor() {
87-
@Override
88-
public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName,
89-
final int lineNumber, final HtmlElement htmlElement) {
90-
final int start = sourceCode.indexOf(alertText);
91-
final int end = start + alertText.length();
92-
93-
return sourceCode.substring(0, start) + newAlertText + sourceCode.substring(end);
94-
}
74+
client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> {
75+
final int start = sourceCode.indexOf(alertText);
76+
final int end = start + alertText.length();
77+
78+
return sourceCode.substring(0, start) + newAlertText + sourceCode.substring(end);
9579
});
96-
client.setAlertHandler(new AlertHandler() {
97-
@Override
98-
public void handleAlert(final Page page, final String message) {
99-
if (!message.equals(newAlertText)) {
100-
fail("The pre processor did not modify the JavaScript");
101-
}
80+
client.setAlertHandler((AlertHandler) (page, message) -> {
81+
if (!message.equals(newAlertText)) {
82+
fail("The pre processor did not modify the JavaScript");
10283
}
103-
10484
});
10585
client.getPage(URL_FIRST);
10686
}
@@ -125,15 +105,11 @@ public void scriptPreProcessor_UnimplementedJavascript() throws Exception {
125105
webConnection.setDefaultResponse(content);
126106
client.setWebConnection(webConnection);
127107

128-
client.setScriptPreProcessor(new ScriptPreProcessor() {
129-
@Override
130-
public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName,
131-
final int lineNumber, final HtmlElement htmlElement) {
132-
if (sourceCode.indexOf("unimplementedFunction") > -1) {
133-
return "";
134-
}
135-
return sourceCode;
108+
client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> {
109+
if (sourceCode.contains("unimplementedFunction")) {
110+
return "";
136111
}
112+
return sourceCode;
137113
});
138114
final List<String> alerts = new ArrayList<>();
139115
client.setAlertHandler(new CollectingAlertHandler(alerts));
@@ -157,13 +133,7 @@ public void scriptPreProcessor_Eval() throws Exception {
157133
conn.setDefaultResponse(html);
158134
client.setWebConnection(conn);
159135

160-
client.setScriptPreProcessor(new ScriptPreProcessor() {
161-
@Override
162-
public String preProcess(final HtmlPage p, final String src, final String srcName,
163-
final int lineNumber, final HtmlElement htmlElement) {
164-
return src.replaceAll("aXert", "alert");
165-
}
166-
});
136+
client.setScriptPreProcessor((p, src, srcName, lineNumber, htmlElement) -> src.replaceAll("aXert", "alert"));
167137

168138
final List<String> alerts = new ArrayList<>();
169139
client.setAlertHandler(new CollectingAlertHandler(alerts));

0 commit comments

Comments
 (0)