Skip to content

Commit 7227c30

Browse files
committed
Allow tests to pass on Windows JVM (non-UTF-8 default encoding)
See gh-33071
1 parent 7e7f55c commit 7227c30

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxViewResolutionIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class FreeMarkerTests {
7070
@Test
7171
void freemarkerWithInvalidConfig() {
7272
assertThatRuntimeException()
73-
.isThrownBy(() -> runTest(InvalidFreeMarkerWebFluxConfig.class))
74-
.withMessageContaining("In addition to a FreeMarker view resolver ");
73+
.isThrownBy(() -> runTest(InvalidFreeMarkerWebFluxConfig.class))
74+
.withMessageContaining("In addition to a FreeMarker view resolver ");
7575
}
7676

7777
@Test

spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.nio.charset.StandardCharsets;
2020

21-
import org.junit.jupiter.api.BeforeAll;
2221
import org.junit.jupiter.api.Nested;
2322
import org.junit.jupiter.api.Test;
2423

@@ -51,11 +50,7 @@ class ViewResolutionIntegrationTests {
5150

5251
private static final String EXPECTED_BODY = "<html><body>Hello, Java Café</body></html>";
5352

54-
55-
@BeforeAll
56-
static void verifyDefaultFileEncoding() {
57-
assertThat(System.getProperty("file.encoding")).as("JVM default file encoding").isEqualTo("UTF-8");
58-
}
53+
private static final boolean utf8Default = StandardCharsets.UTF_8.name().equals(System.getProperty("file.encoding"));
5954

6055

6156
@Nested
@@ -64,15 +59,17 @@ class FreeMarkerTests {
6459
@Test
6560
void freemarkerWithInvalidConfig() {
6661
assertThatRuntimeException()
67-
.isThrownBy(() -> runTest(InvalidFreeMarkerWebConfig.class))
68-
.withMessageContaining("In addition to a FreeMarker view resolver ");
62+
.isThrownBy(() -> runTest(InvalidFreeMarkerWebConfig.class))
63+
.withMessageContaining("In addition to a FreeMarker view resolver ");
6964
}
7065

7166
@Test
7267
void freemarkerWithDefaults() throws Exception {
7368
MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class);
7469
assertThat(response.isCharset()).as("character encoding set in response").isTrue();
75-
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
70+
if (utf8Default) {
71+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
72+
}
7673
// Prior to Spring Framework 6.2, the charset is not updated in the Content-Type.
7774
// Thus, we expect ISO-8859-1 instead of UTF-8.
7875
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
@@ -83,7 +80,9 @@ void freemarkerWithDefaults() throws Exception {
8380
void freemarkerWithExistingViewResolver() throws Exception {
8481
MockHttpServletResponse response = runTest(ExistingViewResolverConfig.class);
8582
assertThat(response.isCharset()).as("character encoding set in response").isTrue();
86-
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
83+
if (utf8Default) {
84+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
85+
}
8786
// Prior to Spring Framework 6.2, the charset is not updated in the Content-Type.
8887
// Thus, we expect ISO-8859-1 instead of UTF-8.
8988
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
@@ -190,20 +189,23 @@ public FreeMarkerConfigurer freeMarkerConfigurer() {
190189
}
191190
}
192191

192+
193193
@Nested
194194
class GroovyMarkupTests {
195195

196196
@Test
197197
void groovyMarkupInvalidConfig() {
198198
assertThatRuntimeException()
199-
.isThrownBy(() -> runTest(InvalidGroovyMarkupWebConfig.class))
200-
.withMessageContaining("In addition to a Groovy markup view resolver ");
199+
.isThrownBy(() -> runTest(InvalidGroovyMarkupWebConfig.class))
200+
.withMessageContaining("In addition to a Groovy markup view resolver ");
201201
}
202202

203203
@Test
204204
void groovyMarkup() throws Exception {
205205
MockHttpServletResponse response = runTest(GroovyMarkupWebConfig.class);
206-
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
206+
if (utf8Default) {
207+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
208+
}
207209
}
208210

209211

0 commit comments

Comments
 (0)