### Question:
OpenSocialI18NGadgetRewriter implements GadgetRewriter { String getLocaleNameForLoadingI18NConstants(Locale locale) { String localeName = "en"; String language = locale.getLanguage(); String country = locale.getCountry(); if (!language.equalsIgnoreCase("ALL")) { try { attemptToLoadDateConstants(language); localeName = language; } catch (IOException e) { } } if (!country.equalsIgnoreCase("ALL")) { try { attemptToLoadDateConstants(localeName + '_' + country); localeName += '_' + country; } catch (IOException e) { } } return localeName; }  void rewrite(Gadget gadget, MutableContent mutableContent);  }### Answer:
@Test public void localeNameForEnglish() throws Exception { localeAtRendering = new Locale("en"); assertEquals("en", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForEnglishUS() throws Exception { localeAtRendering = new Locale("en", "US"); assertEquals("en_US", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForChinese() throws Exception { localeAtRendering = new Locale("zh"); assertEquals("zh", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForChineseCN() throws Exception { localeAtRendering = new Locale("zh", "CN"); assertEquals("zh_CN", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForChineseAll() throws Exception { localeAtRendering = new Locale("zh", "All"); assertEquals("zh", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForAllCN() throws Exception { localeAtRendering = new Locale("All", "CN"); assertEquals("en", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForDefault() throws Exception { localeAtRendering = new Locale("All", "All"); assertEquals("en", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForInvalidCountry() throws Exception { localeAtRendering = new Locale("zh", "foo"); assertEquals("zh", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForInvalidLanguage() throws Exception { localeAtRendering = new Locale("foo", "CN"); assertEquals("en", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }
@Test public void localeNameForInvalidLanguageAndCountry() throws Exception { localeAtRendering = new Locale("foo", "foo"); assertEquals("en", i18nRewriter.getLocaleNameForLoadingI18NConstants(localeAtRendering)); }