DataSourceMessageSource extends AbstractMessageSource implements
        InitializingBean { protected List<Locale> getAlternativeLocales(Locale locale) { List<Locale> locales = new ArrayList<Locale>(); if (locale.getVariant().length() > 0) { locales.add(new Locale(locale.getLanguage(), locale.getCountry())); } if (locale.getCountry().length() > 0) { locales.add(new Locale(locale.getLanguage())); } if (defaultLocale != null && !locale.equals(defaultLocale)) { if (defaultLocale.getVariant().length() > 0) { locales.add(defaultLocale); } if (defaultLocale.getCountry().length() > 0) { locales.add(new Locale(defaultLocale.getLanguage(), defaultLocale.getCountry())); } if (defaultLocale.getLanguage().length() > 0) { locales.add(new Locale(defaultLocale.getLanguage())); } } return locales; }  void setDefaultLocale(Locale defaultLocale); synchronized void setDbMessageResourceDAO(
            DBMessageResourceDAO dbMessageResourceDAO); @Override void afterPropertiesSet(); synchronized void reloadDataSourceMessage();  }
@Test public void testGetAlternativeLocales01() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); Locale locale = new Locale("ja", "", ""); Locale defaultLocale = new Locale("en", "", ""); ds.defaultLocale = defaultLocale; List<Locale> locales = ds.getAlternativeLocales(locale); assertEquals(1, locales.size()); assertEquals(defaultLocale, locales.get(0)); }
@Test public void testGetAlternativeLocales02() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); Locale locale = new Locale("ja", "JP", ""); Locale defaultLocale = new Locale("en", "US", ""); ds.defaultLocale = defaultLocale; Locale locale1 = new Locale("ja", "", ""); Locale defaultLocale2 = new Locale("en", "", ""); List<Locale> locales = ds.getAlternativeLocales(locale); assertEquals(3, locales.size()); assertEquals(locale1, locales.get(0)); assertEquals(defaultLocale, locales.get(1)); assertEquals(defaultLocale2, locales.get(2)); }
@Test public void testGetAlternativeLocales03() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); Locale locale = new Locale("ja", "JP", "kansai"); Locale defaultLocale = new Locale("en", "US", "NY"); ds.defaultLocale = defaultLocale; Locale locale1 = new Locale("ja", "JP", ""); Locale locale2 = new Locale("ja", "", ""); Locale defaultLocale2 = new Locale("en", "US", ""); Locale defaultLocale3 = new Locale("en", "", ""); List<Locale> locales = ds.getAlternativeLocales(locale); assertEquals(5, locales.size()); assertEquals(locale1, locales.get(0)); assertEquals(locale2, locales.get(1)); assertEquals(defaultLocale, locales.get(2)); assertEquals(defaultLocale2, locales.get(3)); assertEquals(defaultLocale3, locales.get(4)); }
@Test public void testGetAlternativeLocales04() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); Locale locale = new Locale("ja", "JP", "kansai"); ds.defaultLocale = locale; Locale locale1 = new Locale("ja", "JP", ""); Locale locale2 = new Locale("ja", "", ""); List<Locale> locales = ds.getAlternativeLocales(locale); assertEquals(2, locales.size()); assertEquals(locale1, locales.get(0)); assertEquals(locale2, locales.get(1)); }
@Test public void testGetAlternativeLocales05() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); Locale locale = new Locale("ja", "", ""); ds.defaultLocale = null; List<Locale> locales = ds.getAlternativeLocales(locale); assertEquals(0, locales.size()); }