DataSourceMessageSource extends AbstractMessageSource implements
        InitializingBean { protected MessageFormat getMessageFormat(String code, Locale locale) { Map<Locale, MessageFormat> localeMap = this.cachedMessageFormats.get(code); if (localeMap != null) { MessageFormat result = localeMap.get(locale); if (result != null) { return result; } } String msg = getMessages(locale).getProperty(code); if (msg != null) { if (localeMap == null) { localeMap = new HashMap<Locale, MessageFormat>(); this.cachedMessageFormats.put(code, localeMap); } MessageFormat result = createMessageFormat(msg, locale); localeMap.put(locale, result); return result; } return null; }  void setDefaultLocale(Locale defaultLocale); synchronized void setDbMessageResourceDAO(
            DBMessageResourceDAO dbMessageResourceDAO); @Override void afterPropertiesSet(); synchronized void reloadDataSourceMessage();  }
@Test public void testGetMessageFormat01() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); MessageFormat mf = new MessageFormat(""); Map<Locale, MessageFormat> map = new HashMap<Locale, MessageFormat>(); map.put(locale, mf); ds.cachedMessageFormats.put(code, map); MessageFormat result = ds.getMessageFormat(code, locale); assertSame(mf, result); }
@Test public void testGetMessageFormat02() throws Exception { DataSourceMessageSource_DataSourceMessageSourceStub18 ds = new DataSourceMessageSource_DataSourceMessageSourceStub18(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); MessageFormat mf = null; Map<Locale, MessageFormat> map = new HashMap<Locale, MessageFormat>(); map.put(locale, mf); ds.cachedMessageFormats.put(code, map); MessageFormat result = ds.getMessageFormat(code, locale); assertSame(mf, result); assertTrue(ds.isRead_A1); }
@Test public void testGetMessageFormat03() throws Exception { DataSourceMessageSource_DataSourceMessageSourceStub19 ds = new DataSourceMessageSource_DataSourceMessageSourceStub19(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); MessageFormat mf = null; Map<Locale, MessageFormat> map = new HashMap<Locale, MessageFormat>(); map.put(locale, mf); ds.cachedMessageFormats.put(code, map); MessageFormat result = ds.getMessageFormat(code, locale); assertNull(result); assertTrue(ds.isRead_A1); }
@Test public void testGetMessageFormat04() throws Exception { DataSourceMessageSource_DataSourceMessageSourceStub18 ds = new DataSourceMessageSource_DataSourceMessageSourceStub18(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); ds.cachedMessageFormats.put(code, null); MessageFormat mf = new MessageFormat(""); ds.messageFormat = mf; ds.cachedMessageFormats.clear(); MessageFormat result = ds.getMessageFormat(code, locale); assertSame(locale, ds.locale); assertSame("テストメッセージ０１", ds.msg); assertSame(mf, result); assertEquals(1, ds.cachedMessageFormats.size()); Map<Locale, MessageFormat> hm = ds.cachedMessageFormats.get(code); assertSame(mf, hm.get(locale)); assertEquals(1, ds.cachedMessageFormats.size()); assertTrue(ds.isRead_A1); }