diff options
author | rnveach <rveach02@gmail.com> | 2016-04-15 21:02:31 -0400 |
---|---|---|
committer | Roman Ivanov <ivanov-jr@mail.ru> | 2016-04-16 05:42:20 -0700 |
commit | 3d8efeeccdc95cf5ee40e1aa08bb58173000a216 (patch) | |
tree | 3f657bcfbde7bdc2c49704f844a79fe474cd8bd2 /src/test | |
parent | dd5d6bce90eae34edd652565c2602ecbd280151e (diff) | |
download | checkstyle-3d8efeeccdc95cf5ee40e1aa08bb58173000a216.tar.gz |
Issue #3065: expanded message test to all locales
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/puppycrawl/tools/checkstyle/internal/AllChecksTest.java | 50 | ||||
-rw-r--r-- | src/test/java/com/puppycrawl/tools/checkstyle/internal/CheckUtil.java | 18 |
2 files changed, 52 insertions, 16 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllChecksTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllChecksTest.java index 65b635234..ea7eed582 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllChecksTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllChecksTest.java @@ -38,6 +38,18 @@ import com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck; import com.puppycrawl.tools.checkstyle.utils.CommonUtils; public class AllChecksTest extends BaseCheckTestSupport { + private static final Locale[] ALL_LOCALES = { + Locale.GERMAN, + new Locale("es"), + new Locale("fi"), + Locale.FRENCH, + Locale.JAPANESE, + new Locale("pt"), + new Locale("tr"), + Locale.CHINESE, + Locale.ENGLISH, + }; + @Test public void testAllChecksWithDefaultConfiguration() throws Exception { final String inputFilePath = getPath("InputDefaultConfig.java"); @@ -190,17 +202,33 @@ public class AllChecksTest extends BaseCheckTestSupport { message.setAccessible(true); } - final String result = CheckUtil.getCheckMessage(module, message.get(null) - .toString()); - - Assert.assertNotNull(module.getSimpleName() + " should have text for the message '" - + message.getName() + "'", result); - Assert.assertFalse( - module.getSimpleName() + " should have non-empty text for the message '" - + message.getName() + "'", result.trim().isEmpty()); - Assert.assertFalse(module.getSimpleName() - + " should have non-TODO text for the message '" + message.getName() + "'", - result.trim().startsWith("TODO")); + for (Locale locale : ALL_LOCALES) { + final String messageString = message.get(null).toString(); + String result = null; + + try { + result = CheckUtil.getCheckMessage(module, locale, messageString); + } + catch (IllegalArgumentException ex) { + Assert.fail(module.getSimpleName() + " with the message '" + messageString + + "' in locale '" + locale.getLanguage() + "' failed with: " + + ex.getClass().getSimpleName() + " - " + ex.getMessage()); + } + + Assert.assertNotNull( + module.getSimpleName() + " should have text for the message '" + + messageString + "' in locale " + locale.getLanguage() + "'", + result); + Assert.assertFalse( + module.getSimpleName() + " should have non-empty text for the message '" + + messageString + "' in locale '" + locale.getLanguage() + "'", + result.trim().isEmpty()); + Assert.assertFalse( + module.getSimpleName() + " should have non-TODO text for the message '" + + messageString + "' in locale " + locale.getLanguage() + "'", + !"todo.match".equals(messageString) + && result.trim().startsWith("TODO")); + } } } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/CheckUtil.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/CheckUtil.java index e0f688bc1..08a3fbb10 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/CheckUtil.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/CheckUtil.java @@ -253,19 +253,27 @@ public final class CheckUtil { * Gets the check message 'as is' from appropriate 'messages.properties' * file. * - * @param messageKey the key of message in 'messages.properties' file. - * @param arguments the arguments of message in 'messages.properties' file. + * @param locale the locale to get the message for. + * @param messageKey the key of message in 'messages*.properties' file. + * @param arguments the arguments of message in 'messages*.properties' file. * @return the check's formatted message. */ - public static String getCheckMessage(Class<?> module, String messageKey, Object... arguments) { + public static String getCheckMessage(Class<?> module, Locale locale, String messageKey, + Object... arguments) { final Properties pr = new Properties(); try { - pr.load(module.getResourceAsStream("messages.properties")); + if (locale == Locale.ENGLISH) { + pr.load(module.getResourceAsStream("messages.properties")); + } + else { + pr.load(module + .getResourceAsStream("messages_" + locale.getLanguage() + ".properties")); + } } catch (IOException ex) { return null; } - final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey), Locale.ROOT); + final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey), locale); return formatter.format(arguments); } |