|
|
|
@ -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"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with 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 |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.servlet.i18n; |
|
|
|
package org.springframework.web.servlet.i18n; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
@ -24,15 +25,14 @@ import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
|
|
|
|
|
|
|
|
import static java.util.Locale.CANADA; |
|
|
|
import static java.util.Locale.*; |
|
|
|
import static java.util.Locale.JAPANESE; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static java.util.Locale.UK; |
|
|
|
|
|
|
|
import static java.util.Locale.US; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link AcceptHeaderLocaleResolver}. |
|
|
|
* Unit tests for {@link AcceptHeaderLocaleResolver}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class AcceptHeaderLocaleResolverTests { |
|
|
|
public class AcceptHeaderLocaleResolverTests { |
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +56,17 @@ public class AcceptHeaderLocaleResolverTests { |
|
|
|
this.resolver.setSupportedLocales(Collections.singletonList(CANADA)); |
|
|
|
this.resolver.setSupportedLocales(Collections.singletonList(CANADA)); |
|
|
|
assertEquals(US, this.resolver.resolveLocale(request(US, UK))); |
|
|
|
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 |
|
|
|
@Test |
|
|
|
public void defaultLocale() throws Exception { |
|
|
|
public void defaultLocale() throws Exception { |
|
|
|
|