Skip to content

Commit

Permalink
infra: set english locale for all tests until checkstyle#12104
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuevKirill95 authored and romani committed Dec 11, 2023
1 parent 075c4a0 commit d5c39d4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ private static String internalGetCheckMessage(
String messageBundle, String messageKey, Object... arguments) {
final ResourceBundle resourceBundle = ResourceBundle.getBundle(
messageBundle,
Locale.getDefault(),
Locale.ROOT,
Thread.currentThread().getContextClassLoader(),
new Utf8Control());
final String pattern = resourceBundle.getString(messageKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeEach;

public abstract class AbstractPathTestSupport {

// we are using positive lookahead here, to convert \r\n to \n
Expand All @@ -42,6 +45,15 @@ public abstract class AbstractPathTestSupport {
*/
protected abstract String getPackageLocation();

/**
* Sets the English locale for all tests.
* Otherwise, some tests failed in other locales.
*/
@BeforeEach
public void setEnglishLocale() {
Locale.setDefault(Locale.ENGLISH);
}

/**
* Retrieves the name of the folder location for resources.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ public void visitToken(DetailAST ast) {
}
final int childCount = ast.getChildCount();
if (childCount != METHOD_DEF_CHILD_COUNT) {
final String msg = String.format(Locale.getDefault(),
final String msg = String.format(Locale.ENGLISH,
"AST node in no comment tree has wrong number of children. "
+ "Expected is %d but was %d",
METHOD_DEF_CHILD_COUNT, childCount);
Expand All @@ -1836,7 +1836,7 @@ public void visitToken(DetailAST ast) {
}
final int cacheChildCount = ast.getFirstChild().getChildCount();
if (cacheChildCount != actualChildCount) {
final String msg = String.format(Locale.getDefault(),
final String msg = String.format(Locale.ENGLISH,
"AST node with no comment has wrong number of children. "
+ "Expected is %d but was %d",
cacheChildCount, actualChildCount);
Expand Down Expand Up @@ -1871,6 +1871,7 @@ public int[] getRequiredTokens() {
return new int[] {TokenTypes.METHOD_DEF};
}

// Locale.ENGLISH until #12104
@Override
public void visitToken(DetailAST ast) {
if (ast.findFirstToken(TokenTypes.MODIFIERS).findFirstToken(
Expand All @@ -1879,7 +1880,7 @@ public void visitToken(DetailAST ast) {
}
final int childCount = ast.getChildCount();
if (childCount != METHOD_DEF_CHILD_COUNT) {
final String msg = String.format(Locale.getDefault(),
final String msg = String.format(Locale.ENGLISH,
"AST node in comment tree has wrong number of children. "
+ "Expected is %d but was %d",
METHOD_DEF_CHILD_COUNT, childCount);
Expand All @@ -1893,7 +1894,7 @@ public void visitToken(DetailAST ast) {
}
final int cacheChildCount = ast.getFirstChild().getChildCount();
if (cacheChildCount != actualChildCount) {
final String msg = String.format(Locale.getDefault(),
final String msg = String.format(Locale.ENGLISH,
"AST node with comment has wrong number of children. "
+ "Expected is %d but was %d",
cacheChildCount, actualChildCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

public class DefaultLoggerTest {

private static final Locale DEFAULT_LOCALE = Locale.getDefault();
private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;

@AfterEach
public void tearDown() {
Expand Down Expand Up @@ -280,11 +280,12 @@ public void testCountryIsValid() {
@Test
public void testNewCtor() throws Exception {
final ResourceBundle bundle = ResourceBundle.getBundle(
Definitions.CHECKSTYLE_BUNDLE, Locale.ROOT);
Definitions.CHECKSTYLE_BUNDLE, Locale.ENGLISH);
final String auditStartedMessage = bundle.getString(DefaultLogger.AUDIT_STARTED_MESSAGE);
final String auditFinishedMessage = bundle.getString(DefaultLogger.AUDIT_FINISHED_MESSAGE);
final String addExceptionMessage = new MessageFormat(bundle.getString(
DefaultLogger.ADD_EXCEPTION_MESSAGE), Locale.ROOT).format(new String[] {"myfile"});
DefaultLogger.ADD_EXCEPTION_MESSAGE), Locale.ENGLISH).format(new String[] {"myfile"}
);
final String infoOutput;
final String errorOutput;
try (MockByteArrayOutputStream infoStream = new MockByteArrayOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
*/
public class LocalizedMessageTest {

private static final Locale DEFAULT_LOCALE = Locale.getDefault();
private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;

@DefaultLocale("en")
@Test
public void testNullArgs() {
final LocalizedMessage messageClass = new LocalizedMessage(Definitions.CHECKSTYLE_BUNDLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void testExternalResourceIsSavedInCache() throws Exception {
@Test
public void testCacheDirectoryDoesNotExistAndShouldBeCreated() throws IOException {
final Configuration config = new DefaultConfiguration("myName");
final String filePath = String.format(Locale.getDefault(), "%s%2$stemp%2$scache.temp",
final String filePath = String.format(Locale.ENGLISH, "%s%2$stemp%2$scache.temp",
temporaryFolder, File.separator);
final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);

Expand Down

0 comments on commit d5c39d4

Please sign in to comment.