This commit is contained in:
Phillip Webb
2014-04-23 09:42:10 +01:00
parent 316cb87583
commit fad5ce45db
46 changed files with 276 additions and 253 deletions

View File

@@ -178,7 +178,7 @@ public class ThymeleafAutoConfiguration {
resolver.setTemplateEngine(this.templateEngine);
resolver.setCharacterEncoding(this.environment.getProperty("encoding",
"UTF-8"));
resolver.setContentType(addEncoding(
resolver.setContentType(appendCharset(
this.environment.getProperty("contentType", "text/html"),
resolver.getCharacterEncoding()));
resolver.setExcludedViewNames(this.environment.getProperty(
@@ -191,13 +191,11 @@ public class ThymeleafAutoConfiguration {
return resolver;
}
private String addEncoding(String type, String charset) {
private String appendCharset(String type, String charset) {
if (type.contains("charset=")) {
return type;
}
else {
return type + ";charset=" + charset;
}
return type + ";charset=" + charset;
}
}

View File

@@ -143,7 +143,7 @@ public class WebMvcAutoConfiguration {
@Value("${spring.resources.cachePeriod:}")
private Integer cachePeriod;
@Value("${spring.mvc.locale:}")
private String locale = "";

View File

@@ -38,6 +38,7 @@ import static org.junit.Assert.assertTrue;
public class SecurityPropertiesTests {
private SecurityProperties security = new SecurityProperties();
private RelaxedDataBinder binder = new RelaxedDataBinder(this.security, "security");
@Before

View File

@@ -149,7 +149,6 @@ public class WebMvcAutoConfigurationTests {
equalTo((Resource) new ClassPathResource("/foo/")));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void noLocaleResolver() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
this.context.register(AllResources.class, Config.class,
@@ -157,6 +156,7 @@ public class WebMvcAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(LocaleResolver.class);
}
@@ -164,8 +164,7 @@ public class WebMvcAutoConfigurationTests {
public void overrideLocale() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
// set fixed locale
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mvc.locale:en_UK");
EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.locale:en_UK");
this.context.register(AllResources.class, Config.class,
WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
@@ -176,11 +175,9 @@ public class WebMvcAutoConfigurationTests {
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
Locale locale = localeResolver.resolveLocale(request);
assertThat(localeResolver,
instanceOf(FixedLocaleResolver.class));
assertThat(localeResolver, instanceOf(FixedLocaleResolver.class));
// test locale resolver uses fixed locale and not user preferred locale
assertThat(locale.toString(),
equalTo("en_UK"));
assertThat(locale.toString(), equalTo("en_UK"));
}
@SuppressWarnings("unchecked")