use of cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext in project today-infrastructure by TAKETODAY.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZoneOnly.
@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(null, TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.GERMANY);
request.setCookies(cookie);
requestContext = new MockServletRequestContext(request, response);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(requestContext);
assertThat(loc.getLocale()).isEqualTo(Locale.GERMANY);
boolean condition = loc instanceof TimeZoneAwareLocaleContext;
assertThat(condition).isTrue();
assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
use of cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext in project today-infrastructure by TAKETODAY.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZone.
@Test
public void testSetAndResolveLocaleContextWithTimeZone() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(requestContext);
assertThat(loc.getLocale().getLanguage()).isEqualTo("nl");
boolean condition = loc instanceof TimeZoneAwareLocaleContext;
assertThat(condition).isTrue();
assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
use of cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext in project today-framework by TAKETODAY.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZone.
@Test
public void testSetAndResolveLocaleContextWithTimeZone() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(requestContext);
assertThat(loc.getLocale().getLanguage()).isEqualTo("nl");
boolean condition = loc instanceof TimeZoneAwareLocaleContext;
assertThat(condition).isTrue();
assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
use of cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext in project today-framework by TAKETODAY.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZoneOnly.
@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(null, TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.GERMANY);
request.setCookies(cookie);
requestContext = new MockServletRequestContext(request, response);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(requestContext);
assertThat(loc.getLocale()).isEqualTo(Locale.GERMANY);
boolean condition = loc instanceof TimeZoneAwareLocaleContext;
assertThat(condition).isTrue();
assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
Aggregations