Skip to content

Commit

Permalink
Allow tests to pass on Windows JVM (non-UTF-8 default encoding)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jul 8, 2024
1 parent 7e7f55c commit 7227c30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class FreeMarkerTests {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -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
Expand All @@ -64,15 +59,17 @@ class FreeMarkerTests {
@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");
Expand All @@ -83,7 +80,9 @@ void freemarkerWithDefaults() throws Exception {
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");
Expand Down Expand Up @@ -190,20 +189,23 @@ public FreeMarkerConfigurer freeMarkerConfigurer() {
}
}


@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);
}
}


Expand Down

0 comments on commit 7227c30

Please sign in to comment.