diff --git a/pom.xml b/pom.xml index c355d15..7ba0747 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 - 8.1 + 8.4 2.17 3.7 3.0.4 diff --git a/src/main/resources/com/github/checkstyle/regression/extract/ExtractInfoGeneratorTest.java b/src/main/resources/com/github/checkstyle/regression/extract/ExtractInfoGeneratorTest.java index f7f2790..209c41c 100644 --- a/src/main/resources/com/github/checkstyle/regression/extract/ExtractInfoGeneratorTest.java +++ b/src/main/resources/com/github/checkstyle/regression/extract/ExtractInfoGeneratorTest.java @@ -31,7 +31,7 @@ import org.junit.Test; -import com.puppycrawl.tools.checkstyle.internal.CheckUtil; +import com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil; import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtils; /** diff --git a/src/test/java/com/github/checkstyle/regression/configuration/ConfigGeneratorTest.java b/src/test/java/com/github/checkstyle/regression/configuration/ConfigGeneratorTest.java index 7c20ebf..e775628 100644 --- a/src/test/java/com/github/checkstyle/regression/configuration/ConfigGeneratorTest.java +++ b/src/test/java/com/github/checkstyle/regression/configuration/ConfigGeneratorTest.java @@ -20,7 +20,9 @@ package com.github.checkstyle.regression.configuration; import static com.github.checkstyle.regression.configuration.ConfigGenerator.DOCTYPE_PUBLIC; +import static com.github.checkstyle.regression.internal.FileUtils.readFile; import static com.github.checkstyle.regression.internal.TestUtils.assertUtilsClassHasPrivateConstructor; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; @@ -84,7 +86,7 @@ public void testGenerateConfigTextWithEmptyModuleInfos() throws Exception { final File excepted = getExpectedXml("expected_empty_module_infos.xml"); final File actual = generateConfig(Collections.emptyList()); - assertTrue("Config is not as expected", FileUtils.contentEquals(excepted, actual)); + assertEquals("Config is not as expected", readFile(excepted), readFile(actual)); } @Test @@ -102,7 +104,7 @@ public void testGenerateConfigTextWithCheckerParentModule() throws Exception { final File actual = generateConfig(Collections.singletonList(moduleInfo)); - assertTrue("Config is not as expected", FileUtils.contentEquals(excepted, actual)); + assertEquals("Config is not as expected", readFile(excepted), readFile(actual)); } @Test @@ -119,7 +121,7 @@ public void testGenerateConfigTextWithTreeWalkerParentModule() throws Exception .build(); final File actual = generateConfig(Collections.singletonList(moduleInfo)); - assertTrue("Config is not as expected", FileUtils.contentEquals(excepted, actual)); + assertEquals("Config is not as expected", readFile(excepted), readFile(actual)); } @Test @@ -145,7 +147,7 @@ public void testGenerateConfigTextWithMiscModuleInfos() throws Exception { .build(); final File actual = generateConfig(Arrays.asList(moduleInfo1, moduleInfo2)); - assertTrue("Config is not as expected", FileUtils.contentEquals(excepted, actual)); + assertEquals("Config is not as expected", readFile(excepted), readFile(actual)); } @Test diff --git a/src/test/java/com/github/checkstyle/regression/internal/FileUtils.java b/src/test/java/com/github/checkstyle/regression/internal/FileUtils.java new file mode 100644 index 0000000..7df5344 --- /dev/null +++ b/src/test/java/com/github/checkstyle/regression/internal/FileUtils.java @@ -0,0 +1,46 @@ +//////////////////////////////////////////////////////////////////////////////// +// checkstyle: Checks Java source code for adherence to a set of rules. +// Copyright (C) 2001-2017 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//////////////////////////////////////////////////////////////////////////////// + +package com.github.checkstyle.regression.internal; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +public final class FileUtils { + protected static final String LF_REGEX = "\n"; + + protected static final String CRLF_REGEX = "\\r\\n"; + + private FileUtils() { + } + + /** + * Reads the contents of a file. + * + * @param file the file whose contents are to be read + * @return contents of the file with all {@code \r\n} replaced by {@code \n} + * @throws IOException if I/O exception occurs while reading + */ + public static String readFile(File file) throws IOException { + return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).replaceAll( + CRLF_REGEX, LF_REGEX); + } +} diff --git a/src/test/resources/com/github/checkstyle/regression/configuration/expected_checker_parent_module.xml b/src/test/resources/com/github/checkstyle/regression/configuration/expected_checker_parent_module.xml index c231062..e3f8835 100644 --- a/src/test/resources/com/github/checkstyle/regression/configuration/expected_checker_parent_module.xml +++ b/src/test/resources/com/github/checkstyle/regression/configuration/expected_checker_parent_module.xml @@ -1,5 +1,6 @@ - + @@ -8,10 +9,10 @@ - + - + diff --git a/src/test/resources/com/github/checkstyle/regression/configuration/expected_empty_module_infos.xml b/src/test/resources/com/github/checkstyle/regression/configuration/expected_empty_module_infos.xml index a20f25f..387b152 100644 --- a/src/test/resources/com/github/checkstyle/regression/configuration/expected_empty_module_infos.xml +++ b/src/test/resources/com/github/checkstyle/regression/configuration/expected_empty_module_infos.xml @@ -1,5 +1,6 @@ - + @@ -8,7 +9,7 @@ - + diff --git a/src/test/resources/com/github/checkstyle/regression/configuration/expected_misc_module_infos.xml b/src/test/resources/com/github/checkstyle/regression/configuration/expected_misc_module_infos.xml index f903435..fccadf0 100644 --- a/src/test/resources/com/github/checkstyle/regression/configuration/expected_misc_module_infos.xml +++ b/src/test/resources/com/github/checkstyle/regression/configuration/expected_misc_module_infos.xml @@ -1,5 +1,6 @@ - + @@ -8,12 +9,12 @@ - + - - - + + + diff --git a/src/test/resources/com/github/checkstyle/regression/configuration/expected_tree_walker_parent_module.xml b/src/test/resources/com/github/checkstyle/regression/configuration/expected_tree_walker_parent_module.xml index 8b0ed30..c542e4e 100644 --- a/src/test/resources/com/github/checkstyle/regression/configuration/expected_tree_walker_parent_module.xml +++ b/src/test/resources/com/github/checkstyle/regression/configuration/expected_tree_walker_parent_module.xml @@ -1,5 +1,6 @@ - + @@ -8,11 +9,11 @@ - + - - + +