Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 20, 2024
1 parent eb60969 commit 529db8e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/test/java/org/htmlunit/CodeStyleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
*/
package org.htmlunit;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
Expand Down Expand Up @@ -52,6 +53,7 @@
*/
public class CodeStyleTest {

private static final Charset SOURCE_ENCODING = StandardCharsets.UTF_8;
private static final Pattern LEADING_WHITESPACE = Pattern.compile("^\\s+");
private static final Pattern LOG_STATIC_STRING =
Pattern.compile("^\\s*LOG\\.[a-z]+\\(\"[^\"]*\"(, [a-zA-Z_]+)?\\);");
Expand Down Expand Up @@ -139,7 +141,7 @@ private void process(final List<File> files, final List<String> classNames) thro
for (final File file : files) {
final String relativePath = file.getAbsolutePath().substring(new File(".").getAbsolutePath().length() - 1);
if (file.getName().endsWith(".java")) {
final List<String> lines = FileUtils.readLines(file, UTF_8);
final List<String> lines = FileUtils.readLines(file, SOURCE_ENCODING);
openingCurlyBracket(lines, relativePath);
year(lines, relativePath);
javaDocFirstLine(lines, relativePath);
Expand Down Expand Up @@ -290,7 +292,7 @@ private void processXML(final File dir, final boolean recursive) throws Exceptio
}
else {
if (file.getName().endsWith(".xml")) {
final List<String> lines = FileUtils.readLines(file, UTF_8);
final List<String> lines = FileUtils.readLines(file, SOURCE_ENCODING);
final String relativePath = file.getAbsolutePath().substring(
new File(".").getAbsolutePath().length() - 1);
mixedIndentation(lines, relativePath);
Expand Down Expand Up @@ -345,7 +347,7 @@ private void badIndentationLevels(final List<String> lines, final String relativ
* Checks the year in {@code LICENSE.txt}.
*/
private void licenseYear() throws IOException {
final List<String> lines = FileUtils.readLines(new File("checkstyle.xml"), UTF_8);
final List<String> lines = FileUtils.readLines(new File("checkstyle.xml"), SOURCE_ENCODING);
boolean check = false;
final String copyright = "Copyright (c) 2002-" + LocalDate.now().getYear();
for (final String line : lines) {
Expand All @@ -367,7 +369,7 @@ private void licenseYear() throws IOException {
private void versionYear() throws IOException {
final List<String> lines =
FileUtils.readLines(new File("src/main/java/org/htmlunit/Version.java"),
UTF_8);
SOURCE_ENCODING);
for (final String line : lines) {
if (line.contains("return \"Copyright (c) 2002-" + Calendar.getInstance(Locale.ROOT).get(Calendar.YEAR))) {
return;
Expand All @@ -380,7 +382,7 @@ private void versionYear() throws IOException {
* Verifies no &lt;parent&gt; tag in {@code pom.xml}.
*/
private void parentInPom() throws IOException {
final List<String> lines = FileUtils.readLines(new File("pom.xml"), UTF_8);
final List<String> lines = FileUtils.readLines(new File("pom.xml"), SOURCE_ENCODING);
for (int i = 0; i < lines.size(); i++) {
if (lines.get(i).contains("<parent>")) {
addFailure("pom.xml", i + 1, "'pom.xml' should not have <parent> tag");
Expand Down Expand Up @@ -927,7 +929,7 @@ private void testTests(final File dir) throws Exception {
&& method.getAnnotation(Test.class) == null
&& method.getReturnType() == Void.TYPE
&& method.getParameterTypes().length == 0) {
final List<String> lines = FileUtils.readLines(file, UTF_8);
final List<String> lines = FileUtils.readLines(file, SOURCE_ENCODING);
int line = -1;
for (int i = 0; i < lines.size(); ++i) {
if (lines.get(i).contains("public void " + method.getName() + "()")) {
Expand Down

0 comments on commit 529db8e

Please sign in to comment.