diff options
author | Ruslan Diachenko <rd.ryly@gmail.com> | 2015-10-13 23:52:19 +0100 |
---|---|---|
committer | Ruslan Diachenko <rd.ryly@gmail.com> | 2015-10-14 00:52:06 +0100 |
commit | 7d5db23ad528c95e0fbdfcd1293424c6240db07b (patch) | |
tree | 5a19361845759ed0fc748116550c5781e832bddf /src/test/java | |
parent | be3e035ce39a610881cd2c1bfdce3eef101c2e3c (diff) | |
download | checkstyle-7d5db23ad528c95e0fbdfcd1293424c6240db07b.tar.gz |
Issue #1217: goal 'testCheck' was activated in 'forbiddenapis' plugin, violations fixed
Diffstat (limited to 'src/test/java')
8 files changed, 49 insertions, 38 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java index a1d6ed62b..9b2d3affc 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksPresentOnAvailableChecksPageTest.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Locale; import org.junit.Assert; import org.junit.Test; @@ -76,7 +77,7 @@ public class AllChecksPresentOnAvailableChecksPageTest { } private static boolean isPresent(String availableChecks, String checkName) { - final String linkPattern = String.format(LINK_TEMPLATE, checkName); + final String linkPattern = String.format(Locale.ROOT, LINK_TEMPLATE, checkName); return availableChecks.matches(linkPattern); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksTest.java index cf0512535..84aa467ea 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/AllChecksTest.java @@ -28,6 +28,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import javax.xml.parsers.DocumentBuilder; @@ -100,8 +101,9 @@ public class AllChecksTest extends BaseCheckTestSupport { final int[] acceptableTokens = testedCheck.getAcceptableTokens(); if (!isSubset(defaultTokens, acceptableTokens)) { - String errorMessage = String.format("%s's default tokens must be a subset" - + " of acceptable tokens.", check.getName()); + String errorMessage = String.format(Locale.ROOT, + "%s's default tokens must be a subset" + + " of acceptable tokens.", check.getName()); Assert.fail(errorMessage); } } @@ -119,8 +121,9 @@ public class AllChecksTest extends BaseCheckTestSupport { final int[] acceptableTokens = testedCheck.getAcceptableTokens(); if (!isSubset(requiredTokens, acceptableTokens)) { - String errorMessage = String.format("%s's required tokens must be a subset" - + " of acceptable tokens.", check.getName()); + String errorMessage = String.format(Locale.ROOT, + "%s's required tokens must be a subset" + + " of acceptable tokens.", check.getName()); Assert.fail(errorMessage); } } @@ -138,8 +141,9 @@ public class AllChecksTest extends BaseCheckTestSupport { final int[] requiredTokens = testedCheck.getRequiredTokens(); if (!isSubset(requiredTokens, defaultTokens)) { - String errorMessage = String.format("%s's required tokens must be a subset" - + " of default tokens.", check.getName()); + String errorMessage = String.format(Locale.ROOT, + "%s's required tokens must be a subset" + + " of default tokens.", check.getName()); Assert.fail(errorMessage); } } @@ -155,7 +159,8 @@ public class AllChecksTest extends BaseCheckTestSupport { for (String check : checksNames) { if (!checksReferencedInConfig.contains(check)) { - String errorMessage = String.format("%s is not referenced in checkstyle_checks.xml", check); + String errorMessage = String.format(Locale.ROOT, + "%s is not referenced in checkstyle_checks.xml", check); Assert.fail(errorMessage); } } @@ -172,7 +177,7 @@ public class AllChecksTest extends BaseCheckTestSupport { for (String moduleName : checkstyleModulesNames) { if (!modulesNamesWhichHaveXdocs.contains(moduleName)) { - final String missingModuleMessage = String.format( + final String missingModuleMessage = String.format(Locale.ROOT, "Module %s does not have xdoc documentation.", moduleName); Assert.fail(missingModuleMessage); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/BaseCheckTestSupport.java b/src/test/java/com/puppycrawl/tools/checkstyle/BaseCheckTestSupport.java index d51792f9d..4ef0ea69e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/BaseCheckTestSupport.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/BaseCheckTestSupport.java @@ -1,6 +1,5 @@ package com.puppycrawl.tools.checkstyle; -import static java.text.MessageFormat.format; import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -11,6 +10,7 @@ import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.text.MessageFormat; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -172,6 +172,8 @@ public class BaseCheckTestSupport { } catch (IOException e) { return null; } - return format(pr.getProperty(messageKey), arguments); + final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey), + Locale.ROOT); + return formatter.format(arguments); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java index 46f0cc40d..2659ec8d0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java @@ -82,7 +82,7 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - String usage = String.format("Unrecognized option: -w%n" + String usage = String.format(Locale.ROOT, "Unrecognized option: -w%n" + "usage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>%n" + " file...%n" + " -c <arg> Sets the check configuration file to use.%n" @@ -135,8 +135,8 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertEquals( - String.format("Unable to find: src/main/resources/non_existing_config.xml%n" + assertEquals(String.format(Locale.ROOT, + "Unable to find: src/main/resources/non_existing_config.xml%n" + "Checkstyle ends with 1 errors.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); @@ -152,7 +152,7 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertEquals(String.format("Invalid output format. " + assertEquals(String.format(Locale.ROOT, "Invalid output format. " + "Found 'xmlp' but expected 'plain' or 'xml'.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); } @@ -187,7 +187,7 @@ public class MainTest { + " how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages." + " Please also recheck that provided ClassLoader to Checker is configured correctly."; final String expectedExceptionMessage = - String.format("cannot initialize module TreeWalker - %1$s%n" + String.format(Locale.ROOT, "cannot initialize module TreeWalker - %1$s%n" + "Cause: com.puppycrawl.tools.checkstyle.api.CheckstyleException: %1$s%n" + "Checkstyle ends with 1 errors.%n", cause); exit.checkAssertionAfterwards(new Assertion() { @@ -208,7 +208,7 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertEquals(String.format("Starting audit...%n" + assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "Audit done.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); } @@ -230,7 +230,8 @@ public class MainTest { final ResourceBundle compilationProperties = ResourceBundle.getBundle("checkstylecompilation"); String version = compilationProperties.getString("checkstyle.compile.version"); - assertEquals(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" + assertEquals(String.format(Locale.ROOT, + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" + "<checkstyle version=\"%s\">%n" + "<file name=\"%s\">%n" + "</file>%n" @@ -249,7 +250,7 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertEquals(String.format("Starting audit...%n" + assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "Audit done.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); } @@ -269,7 +270,7 @@ public class MainTest { String expectedPath = currentPath + "/src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java" .replace("/", File.separator); - assertEquals(String.format("Starting audit...%n" + assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "%1$s:3:14: " + "warning: Name 'InputMain' must match pattern '^[a-z0-9]*$'.%n" + "%1$s:5:7: " @@ -294,7 +295,7 @@ public class MainTest { String expectedPath = currentPath + "/src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java" .replace("/", File.separator); - assertEquals(String.format("Starting audit...%n" + assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "%1$s:3:14: error: " + "Name 'InputMain' must match pattern '^[a-z0-9]*$'.%n" + "%1$s:5:7: error: " @@ -396,7 +397,7 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertEquals(String.format("Starting audit...%n" + assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "Audit done.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); } @@ -432,10 +433,10 @@ public class MainTest { exit.checkAssertionAfterwards(new Assertion() { @Override public void checkAssertion() { - assertTrue(systemOut.getLog().startsWith(String.format( + assertTrue(systemOut.getLog().startsWith(String.format(Locale.ROOT, "unable to parse configuration stream - Content is not allowed in prolog.:7:1%n" + "Cause: org.xml.sax.SAXParseException; systemId: file:"))); - assertTrue(systemOut.getLog().endsWith(String.format( + assertTrue(systemOut.getLog().endsWith(String.format(Locale.ROOT, "com/puppycrawl/tools/checkstyle/config-Incorrect.xml; lineNumber: 7; columnNumber: 1; " + "Content is not allowed in prolog.%n" + "Checkstyle ends with 1 errors.%n"))); @@ -529,7 +530,7 @@ public class MainTest { sb.append("Starting audit...").append(System.getProperty("line.separator")); String format = "%s.java:%s: warning: File length is %s lines (max allowed is 80)."; for (String[] outputValue : outputValues) { - String line = String.format(format, + String line = String.format(Locale.ROOT, format, expectedPath + outputValue[0], outputValue[1], outputValue[2]); sb.append(line).append(System.getProperty("line.separator")); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java index e2be50dd8..e7fa6736e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull; import java.io.File; import java.io.FileFilter; import java.text.MessageFormat; +import java.util.Locale; import org.junit.Test; @@ -147,13 +148,13 @@ public class DetailASTTest { Object[] params = { node, parent, prev, filename, root, }; - String badParentMsg = MessageFormat.format( - "Bad parent node={0} parent={1} filename={3} root={4}", - params); + MessageFormat badParentFormatter = new MessageFormat( + "Bad parent node={0} parent={1} filename={3} root={4}", Locale.ROOT); + String badParentMsg = badParentFormatter.format(params); assertEquals(badParentMsg, parent, node.getParent()); - String badPrevMsg = MessageFormat.format( - "Bad prev node={0} prev={2} parent={1} filename={3} root={4}", - params); + MessageFormat badPrevFormatter = new MessageFormat( + "Bad prev node={0} prev={2} parent={1} filename={3} root={4}", Locale.ROOT); + String badPrevMsg = badPrevFormatter.format(params); assertEquals(badPrevMsg, prev, node.getPreviousSibling()); if (node.getFirstChild() != null) { diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheckTest.java index 3984b1c0b..726dfae24 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheckTest.java @@ -21,8 +21,6 @@ package com.puppycrawl.tools.checkstyle.checks.coding; import static com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenTextCheck.MSG_KEY; -import java.text.MessageFormat; - import org.junit.Assert; import org.junit.Test; @@ -71,7 +69,7 @@ public class IllegalTokenTextCheckTest String customMessage = "My custom message"; checkConfig.addAttribute("message", customMessage); final String[] expected = { - "24:28: " + MessageFormat.format(customMessage, "a href"), + "24:28: " + customMessage, }; verify(checkConfig, getPath("InputIllegalTokens.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java index 1e8cb0cd1..e2a0d8868 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/RegexpHeaderCheckTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.net.URI; +import java.util.Locale; import org.apache.commons.beanutils.ConversionException; import org.apache.commons.lang3.ArrayUtils; @@ -85,7 +86,8 @@ public class RegexpHeaderCheckTest extends BaseFileSetCheckTestSupport { try { String header = "^/**\\n * Licensed to the Apache Software Foundation (ASF)"; instance.setHeader(header); - fail(String.format("%s should have been thrown", ConversionException.class)); + fail(String.format(Locale.ROOT, "%s should have been thrown", + ConversionException.class)); } catch (ConversionException ex) { // expected diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java index f49bed4d0..f880d6c15 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java @@ -35,6 +35,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -86,7 +87,7 @@ public class IndentationCheckTest extends BaseCheckTestSupport { final int actualIndent = getLineStart(line, tabWidth); if (actualIndent != indentInComment) { - throw new IllegalStateException(String.format( + throw new IllegalStateException(String.format(Locale.ROOT, "File \"%1$s\" has incorrect indentation in comment." + "Line %2$d: comment:%3$d, actual:%4$d.", aFileName, @@ -100,14 +101,14 @@ public class IndentationCheckTest extends BaseCheckTestSupport { } if (!isCommentConsistent(comment)) { - throw new IllegalStateException(String.format( + throw new IllegalStateException(String.format(Locale.ROOT, "File \"%1$s\" has inconsistent comment on line %2$d", aFileName, lineNumber)); } } else if (NONEMPTY_LINE_REGEX.matcher(line).matches()) { - throw new IllegalStateException(String.format( + throw new IllegalStateException(String.format(Locale.ROOT, "File \"%1$s\" has no indentation comment or its format " + "malformed. Error on line: %2$d", aFileName, |