DataSourceMessageSource extends AbstractMessageSource implements
        InitializingBean { protected Locale createLocale(DBMessage message) { if (message.getLanguage() == null) { if (defaultLocale != null) { return defaultLocale; } if (log.isErrorEnabled()) { log.error("Can't resolve Locale.Define Locale" + " in MessageSource or Defaultlocale."); } throw new IllegalArgumentException("Can't resolve Locale." + "Define Locale in MessageSource or Defaultlocale."); } if (message.getCountry() == null) { return new Locale(message.getLanguage()); } if (message.getVariant() == null) { return new Locale(message.getLanguage(), message.getCountry()); } return new Locale(message.getLanguage(), message.getCountry(), message.getVariant()); }  void setDefaultLocale(Locale defaultLocale); synchronized void setDbMessageResourceDAO(
            DBMessageResourceDAO dbMessageResourceDAO); @Override void afterPropertiesSet(); synchronized void reloadDataSourceMessage();  }
@Test public void testCreateLocale01() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); DBMessage message = new DBMessage("test01", null, null, null, "テストメッセージ０１"); ds.defaultLocale = Locale.FRENCH; Locale returnLocale = ds.createLocale(message); assertSame(ds.defaultLocale, returnLocale); }
@Test public void testCreateLocale02() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); DBMessage message = new DBMessage("test01", null, null, null, "テストメッセージ０１"); ds.defaultLocale = null; try { ds.createLocale(message); fail(); } catch (IllegalArgumentException e) { assertEquals( "Can't resolve Locale.Define Locale in MessageSource or Defaultlocale.", e.getMessage()); assertThat(logger.getLoggingEvents(), is(asList(error( "Can't resolve Locale.Define Locale in MessageSource or Defaultlocale.")))); } }
@Test public void testCreateLocale03() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); DBMessage message = new DBMessage("test01", "ja", null, null, "テストメッセージ０１"); ds.defaultLocale = null; Locale returnLocale = ds.createLocale(message); assertEquals("ja", returnLocale.getLanguage()); assertEquals("", returnLocale.getCountry()); assertEquals("", returnLocale.getVariant()); }
@Test public void testCreateLocale04() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); DBMessage message = new DBMessage("test01", "ja", "JP", null, "テストメッセージ０１"); ds.defaultLocale = null; Locale returnLocale = ds.createLocale(message); assertEquals("ja", returnLocale.getLanguage()); assertEquals("JP", returnLocale.getCountry()); assertEquals("", returnLocale.getVariant()); }
@Test public void testCreateLocale05() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); DBMessage message = new DBMessage("test01", "ja", "JP", "kansai", "テストメッセージ０１"); ds.defaultLocale = null; Locale returnLocale = ds.createLocale(message); assertEquals("ja", returnLocale.getLanguage()); assertEquals("JP", returnLocale.getCountry()); assertEquals("kansai", returnLocale.getVariant()); }