diff options
author | rnveach <rveach02@gmail.com> | 2017-10-04 15:26:34 -0400 |
---|---|---|
committer | Roman Ivanov <romani@users.noreply.github.com> | 2017-12-25 14:04:06 -0800 |
commit | 0ab421d20720bde28e24d135b644ae43f98af940 (patch) | |
tree | 8c0c8880f9f311b094fa7c079e0495aceace0ffb | |
parent | f3a14ddefe32e4fd766007943237ba2a0a0933a4 (diff) | |
download | checkstyle-0ab421d20720bde28e24d135b644ae43f98af940.tar.gz |
Issue #5141: fixed broken translation check because of ordering
5 files changed, 34 insertions, 49 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java index f94a1a176..9395843bd 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java @@ -57,7 +57,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.google.common.collect.ImmutableMap; import com.google.common.io.Closeables; -import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport; +import com.puppycrawl.tools.checkstyle.AbstractXmlTestSupport; import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import com.puppycrawl.tools.checkstyle.XMLLogger; @@ -68,11 +68,12 @@ import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; import com.puppycrawl.tools.checkstyle.api.SeverityLevel; import com.puppycrawl.tools.checkstyle.api.SeverityLevelCounter; +import com.puppycrawl.tools.checkstyle.internal.utils.XmlUtil; import com.puppycrawl.tools.checkstyle.utils.CommonUtils; @RunWith(PowerMockRunner.class) @PrepareForTest(Closeables.class) -public class TranslationCheckTest extends AbstractModuleTestSupport { +public class TranslationCheckTest extends AbstractXmlTestSupport { @Captor private ArgumentCaptor<SortedSet<LocalizedMessage>> captor; @@ -144,6 +145,7 @@ public class TranslationCheckTest extends AbstractModuleTestSupport { checkConfig.addAttribute("requiredTranslations", "ja,de"); checkConfig.addAttribute("baseName", "^InputTranslation.*$"); final Checker checker = createChecker(checkConfig); + checker.setBasedir(getPath("")); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final XMLLogger logger = new XMLLogger(out, AutomaticBean.OutputStreamOptions.NONE); checker.addListener(logger); @@ -162,8 +164,21 @@ public class TranslationCheckTest extends AbstractModuleTestSupport { final String secondErrorMessage = getCheckMessage(MSG_KEY, "anotherKey"); verify(checker, propertyFiles, ImmutableMap.of( - getPath(""), Collections.singletonList(line + firstErrorMessage), - translationProps, Collections.singletonList(line + secondErrorMessage))); + ":0", Collections.singletonList(" " + firstErrorMessage), + "InputTranslationCheckFireErrors_de.properties", + Collections.singletonList(line + secondErrorMessage))); + + verifyXml(getPath("ExpectedTranslationLog.xml"), out, (expected, actual) -> { + // order is not always maintained here for an unknown reason. + // File names can appear in different orders depending on the OS and VM. + // This ensures we pick up the correct file based on its name and the + // number of children it has. + return !"file".equals(expected.getNodeName()) + || expected.getAttributes().getNamedItem("name").getNodeValue() + .equals(actual.getAttributes().getNamedItem("name").getNodeValue()) + && XmlUtil.getChildrenElements(expected).size() == XmlUtil + .getChildrenElements(actual).size(); + }, firstErrorMessage, secondErrorMessage); } @Test diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/ExpectedTranslationLog.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/ExpectedTranslationLog.xml new file mode 100644 index 000000000..7f7a77215 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/ExpectedTranslationLog.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<checkstyle version="8.3-SNAPSHOT"> +<file name="InputTranslationCheckFireErrors.properties"> +</file> +<file name="InputTranslationCheckFireErrors_de.properties"> +</file> +<file name=""> +<error line="0" severity="error" message="$0" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> +</file> +<file name="InputTranslationCheckFireErrors.properties"> +</file> +<file name="InputTranslationCheckFireErrors_de.properties"> +<error line="0" severity="error" message="$1" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> +</file> +</checkstyle> diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckLinux.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckLinux.xml deleted file mode 100644 index 34a16cbbe..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckLinux.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<checkstyle version="8.3-SNAPSHOT"> -<file name="path_to_file/InputTranslationCheckFireErrors.properties"> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors_de.properties"> -</file> -<file name="path_to_file"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors.properties"> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors_de.properties"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -</checkstyle> diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckMacOS.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckMacOS.xml deleted file mode 100644 index 865791fde..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckMacOS.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<checkstyle version="8.3-SNAPSHOT"> -<file name="path_to_file/InputTranslationCheckFireErrors.properties"> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors_de.properties"> -</file> -<file name="path_to_file"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors_de.properties"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -<file name="path_to_file/InputTranslationCheckFireErrors.properties"> -</file> -</checkstyle> diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckWindows.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckWindows.xml deleted file mode 100644 index 443bba39b..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/translation/OutputTranslationCheckWindows.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<checkstyle version="8.3-SNAPSHOT"> -<file name="path_to_file\InputTranslationCheckFireErrors.properties"> -</file> -<file name="path_to_file\InputTranslationCheckFireErrors_de.properties"> -</file> -<file name="path_to_file"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -<file name="path_to_file\InputTranslationCheckFireErrors.properties"> -</file> -<file name="path_to_file\InputTranslationCheckFireErrors_de.properties"> -<error line="0" severity="error" message="%s" source="com.puppycrawl.tools.checkstyle.checks.TranslationCheck"/> -</file> -</checkstyle> |