LocaleUtil { public static Locale getLocaleForMessages(Class<?> enumClazz, Locale current) { if (enumClazz != null && current != null) { AnnotationExtractorViaEnumClass annotationExtractorViaEnumClass = new AnnotationExtractorViaEnumClass(enumClazz); ch.qos.cal10n.Locale[] extractLocales = annotationExtractorViaEnumClass.extractLocales(); List<ch.qos.cal10n.Locale> list = Arrays.asList(extractLocales); for (ch.qos.cal10n.Locale cal10nLocale : list) { if (cal10nLocale.value().equals(current.getLanguage())) { return current; } } } return Locale.ENGLISH; }  static Locale getLocaleForMessages(Class<?> enumClazz, Locale current);  }
@Test public void testNullSave() { Locale localeForMessages = LocaleUtil.getLocaleForMessages(null, null); assertNotNull(localeForMessages); assertEquals(Locale.ENGLISH, localeForMessages); }
@Test public void testWithoutLocale() { Locale localeForMessages = LocaleUtil.getLocaleForMessages(Messages.class, null); assertNotNull(localeForMessages); assertEquals(Locale.ENGLISH, localeForMessages); }
@Test public void testWithMessages() { Locale localeForMessages = LocaleUtil.getLocaleForMessages(Messages.class, Locale.GERMAN); assertNotNull(localeForMessages); assertEquals(Locale.GERMAN, localeForMessages); localeForMessages = LocaleUtil.getLocaleForMessages(Messages.class, Locale.ENGLISH); assertNotNull(localeForMessages); assertEquals(Locale.ENGLISH, localeForMessages); }
@Test public void testWithDefaults() { Locale localeForMessages = LocaleUtil.getLocaleForMessages(Messages.class, Locale.FRANCE); assertNotNull(localeForMessages); assertEquals(Locale.ENGLISH, localeForMessages); }