Allow tests to pass on Windows JVM (non-UTF-8 default encoding)
See gh-33071
This commit is contained in:
parent
7e7f55cb23
commit
7227c30917
|
|
@ -70,8 +70,8 @@ class WebFluxViewResolutionIntegrationTests {
|
|||
@Test
|
||||
void freemarkerWithInvalidConfig() {
|
||||
assertThatRuntimeException()
|
||||
.isThrownBy(() -> runTest(InvalidFreeMarkerWebFluxConfig.class))
|
||||
.withMessageContaining("In addition to a FreeMarker view resolver ");
|
||||
.isThrownBy(() -> runTest(InvalidFreeMarkerWebFluxConfig.class))
|
||||
.withMessageContaining("In addition to a FreeMarker view resolver ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.web.servlet.config.annotation;
|
|||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -51,11 +50,7 @@ class ViewResolutionIntegrationTests {
|
|||
|
||||
private static final String EXPECTED_BODY = "<html><body>Hello, Java Café</body></html>";
|
||||
|
||||
|
||||
@BeforeAll
|
||||
static void verifyDefaultFileEncoding() {
|
||||
assertThat(System.getProperty("file.encoding")).as("JVM default file encoding").isEqualTo("UTF-8");
|
||||
}
|
||||
private static final boolean utf8Default = StandardCharsets.UTF_8.name().equals(System.getProperty("file.encoding"));
|
||||
|
||||
|
||||
@Nested
|
||||
|
|
@ -64,15 +59,17 @@ class ViewResolutionIntegrationTests {
|
|||
@Test
|
||||
void freemarkerWithInvalidConfig() {
|
||||
assertThatRuntimeException()
|
||||
.isThrownBy(() -> runTest(InvalidFreeMarkerWebConfig.class))
|
||||
.withMessageContaining("In addition to a FreeMarker view resolver ");
|
||||
.isThrownBy(() -> runTest(InvalidFreeMarkerWebConfig.class))
|
||||
.withMessageContaining("In addition to a FreeMarker view resolver ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void freemarkerWithDefaults() throws Exception {
|
||||
MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class);
|
||||
assertThat(response.isCharset()).as("character encoding set in response").isTrue();
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
if (utf8Default) {
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
}
|
||||
// Prior to Spring Framework 6.2, the charset is not updated in the Content-Type.
|
||||
// Thus, we expect ISO-8859-1 instead of UTF-8.
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
|
||||
|
|
@ -83,7 +80,9 @@ class ViewResolutionIntegrationTests {
|
|||
void freemarkerWithExistingViewResolver() throws Exception {
|
||||
MockHttpServletResponse response = runTest(ExistingViewResolverConfig.class);
|
||||
assertThat(response.isCharset()).as("character encoding set in response").isTrue();
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
if (utf8Default) {
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
}
|
||||
// Prior to Spring Framework 6.2, the charset is not updated in the Content-Type.
|
||||
// Thus, we expect ISO-8859-1 instead of UTF-8.
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
|
||||
|
|
@ -190,20 +189,23 @@ class ViewResolutionIntegrationTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Nested
|
||||
class GroovyMarkupTests {
|
||||
|
||||
@Test
|
||||
void groovyMarkupInvalidConfig() {
|
||||
assertThatRuntimeException()
|
||||
.isThrownBy(() -> runTest(InvalidGroovyMarkupWebConfig.class))
|
||||
.withMessageContaining("In addition to a Groovy markup view resolver ");
|
||||
.isThrownBy(() -> runTest(InvalidGroovyMarkupWebConfig.class))
|
||||
.withMessageContaining("In addition to a Groovy markup view resolver ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void groovyMarkup() throws Exception {
|
||||
MockHttpServletResponse response = runTest(GroovyMarkupWebConfig.class);
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
if (utf8Default) {
|
||||
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue