AcceptHeaderLocaleResolver returns default locale in case of no supported locale found
Issue: SPR-15426
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.i18n;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -24,15 +25,14 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
|
||||
import static java.util.Locale.CANADA;
|
||||
import static java.util.Locale.JAPANESE;
|
||||
import static java.util.Locale.UK;
|
||||
import static java.util.Locale.US;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static java.util.Locale.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AcceptHeaderLocaleResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AcceptHeaderLocaleResolverTests {
|
||||
|
||||
@@ -56,6 +56,17 @@ public class AcceptHeaderLocaleResolverTests {
|
||||
this.resolver.setSupportedLocales(Collections.singletonList(CANADA));
|
||||
assertEquals(US, this.resolver.resolveLocale(request(US, UK)));
|
||||
}
|
||||
@Test
|
||||
|
||||
public void resolvePreferredNotSupportedWithDefault() {
|
||||
this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
|
||||
this.resolver.setDefaultLocale(Locale.JAPAN);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Accept-Language", KOREA.toString());
|
||||
request.setPreferredLocales(Collections.singletonList(KOREA));
|
||||
assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLocale() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user