Fixed bug (594469) where unit tests would fail under different locales. Also
fixed a potential bug on how messages are located.
This commit is contained in:
parent
816c6b33c9
commit
25a13442f2
|
|
@ -205,7 +205,7 @@
|
|||
excludes="**/Generated*.java"/>
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml" toFile="target/cs_errors.xml"/>
|
||||
<classpath refid="run.classpath"/>
|
||||
<classpath refid="build.classpath"/>
|
||||
</checkstyle>
|
||||
</target>
|
||||
|
||||
|
|
|
|||
|
|
@ -107,9 +107,8 @@ public class Checker
|
|||
mCache = new PropertyCacheFile(aConfig);
|
||||
final Verifier v = new Verifier(aConfig);
|
||||
VerifierSingleton.setInstance(v);
|
||||
LocalizedMessage.init(new Locale(mConfig.getLocaleLanguage(),
|
||||
mConfig.getLocaleCountry()),
|
||||
mConfig.getClassLoader());
|
||||
LocalizedMessage.setLocale(new Locale(mConfig.getLocaleLanguage(),
|
||||
mConfig.getLocaleCountry()));
|
||||
}
|
||||
|
||||
/** Cleans up the object **/
|
||||
|
|
|
|||
|
|
@ -51,9 +51,6 @@ public class LocalizedMessage
|
|||
/** arguments for MessageFormat **/
|
||||
private final Object[] mArgs;
|
||||
|
||||
/** the class loader to locate resource bundles with **/
|
||||
private static ClassLoader sLoader;
|
||||
|
||||
/**
|
||||
* Creates a new <code>LocalizedMessage</code> instance.
|
||||
*
|
||||
|
|
@ -86,9 +83,12 @@ public class LocalizedMessage
|
|||
/** @return the translated message **/
|
||||
public String getMessage()
|
||||
{
|
||||
// Very simple approach - wait for performance problems
|
||||
// Very simple approach - wait for performance problems.
|
||||
// Important to use the default class loader, and not the one in the
|
||||
// Configuration object. This is because the class loader in the
|
||||
// Configuration is specified by the user for resolving custom classes.
|
||||
final ResourceBundle bundle =
|
||||
ResourceBundle.getBundle(MESSAGE_BUNDLE, sLocale, sLoader);
|
||||
ResourceBundle.getBundle(MESSAGE_BUNDLE, sLocale);
|
||||
final String pattern = bundle.getString(mKey);
|
||||
return MessageFormat.format(pattern, mArgs);
|
||||
}
|
||||
|
|
@ -105,16 +105,10 @@ public class LocalizedMessage
|
|||
return mColNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the localization of messages
|
||||
*
|
||||
* @param aLocale the locale to use for localization
|
||||
* @param aLoader the class loader to locate resource bundles with
|
||||
*/
|
||||
static void init(Locale aLocale, ClassLoader aLoader)
|
||||
/** @param aLocale the locale to use for localization **/
|
||||
static void setLocale(Locale aLocale)
|
||||
{
|
||||
sLocale = aLocale;
|
||||
sLoader = aLoader;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import java.io.InputStreamReader;
|
|||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.regexp.RESyntaxException;
|
||||
|
||||
|
|
@ -47,6 +49,10 @@ public class CheckerTest
|
|||
mConfig.setLeftCurlyOptionProperty(Defn.LCURLY_TYPE_PROP,
|
||||
LeftCurlyOption.NL);
|
||||
mConfig.setRCurly(RightCurlyOption.ALONE);
|
||||
mConfig.setStringProperty(Defn.LOCALE_COUNTRY_PROP,
|
||||
Locale.ENGLISH.getCountry());
|
||||
mConfig.setStringProperty(Defn.LOCALE_LANGUAGE_PROP,
|
||||
Locale.ENGLISH.getLanguage());
|
||||
}
|
||||
|
||||
static String getPath(String aFilename)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,13 @@ public class LocalizedMessageTest
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
LocalizedMessage.setLocale(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public void testMisc()
|
||||
{
|
||||
LocalizedMessage.init(Locale.getDefault(),
|
||||
Thread.currentThread().getContextClassLoader());
|
||||
LocalizedMessage lm =
|
||||
new LocalizedMessage(0, "DefaultLogger.auditFinished", null);
|
||||
assertNotNull(lm);
|
||||
|
|
|
|||
Loading…
Reference in New Issue