use of java.util.Locale in project checkstyle by checkstyle.
the class CheckerTest method testClearNonexistentCache.
@Test
public void testClearNonexistentCache() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
treeWalkerConfig.addChild(checkConfig);
final DefaultConfiguration checkerConfig = new DefaultConfiguration("simpleConfig");
checkerConfig.addAttribute("charset", "UTF-8");
checkerConfig.addChild(treeWalkerConfig);
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
checker.clearCache();
// one more time, but cache does not exist
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}
use of java.util.Locale in project checkstyle by checkstyle.
the class CheckerTest method testCacheFile.
@Test
public void testCacheFile() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
treeWalkerConfig.addChild(checkConfig);
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyleConfig");
checkerConfig.addAttribute("charset", "UTF-8");
checkerConfig.addChild(treeWalkerConfig);
checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
// one more time to reuse cache
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}
use of java.util.Locale in project cucumber-jvm by cucumber.
the class ConvertersTest method setUp.
@Before
public void setUp() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
LocalizedXStreams transformers = new LocalizedXStreams(classLoader);
en = transformers.get(Locale.US).getConverterLookup();
no = transformers.get(new Locale("no")).getConverterLookup();
}
use of java.util.Locale in project elasticsearch by elastic.
the class DateProcessorFactoryTests method testParseLocale.
public void testParseLocale() throws Exception {
DateProcessor.Factory factory = new DateProcessor.Factory();
Map<String, Object> config = new HashMap<>();
String sourceField = randomAsciiOfLengthBetween(1, 10);
config.put("field", sourceField);
config.put("formats", Collections.singletonList("dd/MM/yyyyy"));
Locale locale = randomLocale(random());
config.put("locale", locale.toLanguageTag());
DateProcessor processor = factory.create(null, null, config);
assertThat(processor.getLocale().toLanguageTag(), equalTo(locale.toLanguageTag()));
}
use of java.util.Locale in project jetty.project by eclipse.
the class Request method getLocales.
/* ------------------------------------------------------------ */
/*
* @see javax.servlet.ServletRequest#getLocales()
*/
@Override
public Enumeration<Locale> getLocales() {
MetaData.Request metadata = _metaData;
if (metadata == null)
return Collections.enumeration(__defaultLocale);
List<String> acceptable = metadata.getFields().getQualityCSV(HttpHeader.ACCEPT_LANGUAGE);
// handle no locale
if (acceptable.isEmpty())
return Collections.enumeration(__defaultLocale);
List<Locale> locales = acceptable.stream().map(language -> {
language = HttpFields.stripParameters(language);
String country = "";
int dash = language.indexOf('-');
if (dash > -1) {
country = language.substring(dash + 1).trim();
language = language.substring(0, dash).trim();
}
return new Locale(language, country);
}).collect(Collectors.toList());
return Collections.enumeration(locales);
}
Aggregations