Remove LocaleRule / DefaultLocale

This commit is contained in:
Andreas Dangel
2022-10-13 17:24:12 +02:00
parent 88b8209958
commit 2d48dabcd0
2 changed files with 0 additions and 105 deletions

View File

@ -1,49 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.junit;
import java.util.Locale;
import java.util.Objects;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
/**
*
* Based on <a href="https://gist.github.com/digulla/5884162">digulla/DefaultLocaleRule.java</a>.
*
*/
public class LocaleRule extends TestWatcher {
private Locale localeForTest;
private Locale originalDefault;
private LocaleRule(Locale localeForTest) {
this.localeForTest = Objects.requireNonNull(localeForTest);
}
@Override
protected void starting(Description description) {
originalDefault = Locale.getDefault();
Locale.setDefault(localeForTest);
}
@Override
protected void finished(Description description) {
Locale.setDefault(originalDefault);
}
public void setDefault(Locale newLocale) {
Locale.setDefault(Objects.requireNonNull(newLocale));
}
public static LocaleRule en() {
return new LocaleRule(Locale.ENGLISH);
}
public static LocaleRule de() {
return new LocaleRule(Locale.GERMAN);
}
}

View File

@ -1,56 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.util.Locale;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* A JUnit rule to change the system locale during a test.
*/
public class DefaultLocale implements TestRule {
private boolean statementIsExecuting = false;
private Locale loc = Locale.getDefault();
/** Set the locale value (overwrites previously set value). */
public void set(Locale locale) {
if (statementIsExecuting) {
Locale.setDefault(locale);
} else {
this.loc = locale;
}
}
@Override
public Statement apply(Statement base, Description description) {
return new EnvironmentVariablesStatement(base);
}
private class EnvironmentVariablesStatement extends Statement {
final Statement baseStatement;
EnvironmentVariablesStatement(Statement baseStatement) {
this.baseStatement = baseStatement;
}
@Override
public void evaluate() throws Throwable {
Locale prev = Locale.getDefault();
statementIsExecuting = true;
try {
Locale.setDefault(loc);
baseStatement.evaluate();
} finally {
statementIsExecuting = false;
Locale.setDefault(prev);
}
}
}
}