DDMFormRendererTag extends BaseDDMFormRendererTag { protected Locale getLocale( HttpServletRequest httpServletRequest, DDMForm ddmForm) { Locale locale = LocaleUtil.fromLanguageId( LanguageUtil.getLanguageId(httpServletRequest)); if (ddmForm == null) { return locale; } Set<Locale> availableLocales = ddmForm.getAvailableLocales(); if (availableLocales.contains(locale)) { return locale; } return ddmForm.getDefaultLocale(); }  @Override int doStartTag();  }
@Test public void testGetDDMFormDefaultLocaleWhenLocaleIsNotAvailable() { DDMForm ddmForm = new DDMForm(); ddmForm.setDefaultLocale(LocaleUtil.BRAZIL); Locale locale = _ddmFormRendererTag.getLocale( _httpServletRequest, ddmForm); Assert.assertEquals(LocaleUtil.BRAZIL, locale); }
@Test public void testGetLocaleFromRequestWhenDDMFormIsNull() { Locale locale = _ddmFormRendererTag.getLocale( _httpServletRequest, null); Assert.assertEquals(LocaleUtil.US, locale); }
@Test public void testGetLocaleWhenLocaleIsAvailable() { DDMForm ddmForm = new DDMForm(); ddmForm.setDefaultLocale(LocaleUtil.BRAZIL); ddmForm.setAvailableLocales( createAvailableLocales(LocaleUtil.BRAZIL, LocaleUtil.US)); Locale locale = _ddmFormRendererTag.getLocale( _httpServletRequest, ddmForm); Assert.assertEquals(LocaleUtil.US, locale); }